org.springframework.core.io
public class: InputStreamResource [javadoc |
source]
java.lang.Object
org.springframework.core.io.AbstractResource
org.springframework.core.io.InputStreamResource
All Implemented Interfaces:
Resource
Resource implementation for a given InputStream. Should only
be used if no specific Resource implementation is applicable.
In particular, prefer
ByteArrayResource or any of the
file-based Resource implementations where possible.
In contrast to other Resource implementations, this is a descriptor
for an already opened resource - therefore returning "true" from
isOpen(). Do not use it if you need to keep the resource
descriptor somewhere, or if you need to read a stream multiple times.
| Constructor: |
public InputStreamResource(InputStream inputStream) {
this(inputStream, "resource loaded through InputStream");
}
Create a new InputStreamResource. Parameters:
inputStream - the InputStream to use
|
public InputStreamResource(InputStream inputStream,
String description) {
if (inputStream == null) {
throw new IllegalArgumentException("InputStream must not be null");
}
this.inputStream = inputStream;
this.description = (description != null ? description : "");
}
Create a new InputStreamResource. Parameters:
inputStream - the InputStream to use
description - where the InputStream comes from
|
| Methods from org.springframework.core.io.AbstractResource: |
|---|
|
createRelative, equals, exists, getFile, getFileForLastModifiedCheck, getFilename, getURI, getURL, hashCode, isOpen, isReadable, lastModified, toString |
| Method from org.springframework.core.io.InputStreamResource Detail: |
public boolean equals(Object obj) {
return (obj == this ||
(obj instanceof InputStreamResource && ((InputStreamResource) obj).inputStream.equals(this.inputStream)));
}
This implementation compares the underlying InputStream. |
public boolean exists() {
return true;
}
This implementation always returns true. |
public String getDescription() {
return this.description;
}
This implementation returns the passed-in description, if any. |
public InputStream getInputStream() throws IOException, IllegalStateException {
if (this.read) {
throw new IllegalStateException("InputStream has already been read - " +
"do not use InputStreamResource if a stream needs to be read multiple times");
}
this.read = true;
return this.inputStream;
}
This implementation throws IllegalStateException if attempting to
read the underlying stream multiple times. |
public int hashCode() {
return this.inputStream.hashCode();
}
This implementation returns the hash code of the underlying InputStream. |
public boolean isOpen() {
return true;
}
This implementation always returns true. |