Package org.springframework.core.io

# Class DescriptiveResource

java.lang.Object
org.springframework.core.io.AbstractResource
org.springframework.core.io.DescriptiveResource

All Implemented Interfaces:
  `InputStreamSource`, `Resource`

public class DescriptiveResource extends AbstractResource
Simple `Resource` implementation that holds a resource description but does not point to an actually readable resource.

To be used as placeholder if a `Resource` argument is expected by an API but not necessarily used for actual reading.

Since:
  1.2.6
Author:
  Juergen Hoeller

## Constructor Summary

Constructors
Constructor
Description
`DescriptiveResource(String description)`
Create a new DescriptiveResource.

## Method Summary

Modifier and Type
Method
Description
`boolean`
`equals(Object other)`
This implementation compares the underlying description String.
`boolean`
`exists()`
This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened.
`String`
`getDescription()`
Return a description for this resource, to be used for error output when working with the resource.
`InputStream`
`getInputStream()`
Return an `InputStream` for the content of an underlying resource.
`int`
`hashCode()`
This implementation returns the hash code of the underlying description String.
`boolean`
`isReadable()`
This implementation always returns `true` for a resource that `exists` (revised as of 5.1).

### Methods inherited from class org.springframework.core.io.AbstractResource

`contentLength, createRelative, getFile, getFileForLastModifiedCheck, getFilename, getURI, getURL, isFile, isOpen, lastModified, readableChannel, toString`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.springframework.core.io.Resource

`getContentAsByteArray, getContentAsString`

## Constructor Details

### DescriptiveResource

public DescriptiveResource(@Nullable String description)
Create a new DescriptiveResource.

Parameters:
  `description` - the resource description

## Method Details

### exists

public boolean exists()
Description copied from class: `AbstractResource`
This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened.

This will cover both directories and content resources.

Specified by:
  `exists` in interface `Resource`
Overrides:
  `exists` in class `AbstractResource`

### isReadable

public boolean isReadable()
Description copied from class: `AbstractResource`
This implementation always returns `true` for a resource that `exists` (revised as of 5.1).

Specified by:
  `isReadable` in interface `Resource`
Overrides:
  `isReadable` in class `AbstractResource`
See Also:
  - `InputStreamSource.getInputStream()`
  - `Resource.exists()`

### getInputStream

public InputStream getInputStream() throws IOException
Description copied from interface: `InputStreamSource`
Return an `InputStream` for the content of an underlying resource.

It is usually expected that every such call creates a fresh stream.

This requirement is particularly important when you consider an API such as JavaMail, which needs to be able to read the stream multiple times when creating mail attachments. For such a use case, it is required that each `getInputStream()` call returns a fresh stream.

Returns:
  the input stream for the underlying resource (must not be `null`)
Throws:
  `FileNotFoundException` - if the underlying resource does not exist
  `IOException` - if the content stream could not be opened
See Also:
  - `Resource.isReadable()`
  - `Resource.isOpen()`

### getDescription

public String getDescription()
Description copied from interface: `Resource`
Return a description for this resource, to be used for error output when working with the resource.

Implementations are also encouraged to return this value from their `toString` method.

See Also:
  - `Object.toString()`

### equals

public boolean equals(@Nullable Object other)
This implementation compares the underlying description String.

Overrides:
  `equals` in class `AbstractResource`
See Also:
  - `Resource.getDescription()`

### hashCode

public int hashCode()
This implementation returns the hash code of the underlying description String.

Overrides:
  `hashCode` in class `AbstractResource`
See Also:
  - `Resource.getDescription()`