Top Description Fields Constructors Methods
org.springframework.core.io

public Class InputStreamResource

extends AbstractResource
Class Inheritance
Imports
java.io.IOException, .InputStream, org.springframework.lang.Nullable, org.springframework.util.Assert

Resource implementation for a given InputStream.

Should only be used if no other 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 an InputStreamResource if you need to keep the resource descriptor somewhere, or if you need to read from a stream multiple times.

Authors
Juergen Hoeller, Sam Brannen
Since
28.12.2003
See Also
ByteArrayResource, ClassPathResource, FileSystemResource, UrlResource

Field Summary

Modifier and TypeField and Description
private final String
private final InputStream
private boolean

Constructor Summary

AccessConstructor and Description
public
InputStreamResource(InputStream
the InputStream to use
inputStream
)

Create a new InputStreamResource.

public
InputStreamResource(InputStream
the InputStream to use
inputStream
,
String
where the InputStream comes from
description
)

Create a new InputStreamResource.

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides org.springframework.core.io.AbstractResource.equals.

This implementation compares the underlying InputStream.

public boolean
exists()

Overrides org.springframework.core.io.AbstractResource.exists.

Implements org.springframework.core.io.Resource.exists.

This implementation always returns true.

public String
getDescription()

Implements org.springframework.core.io.Resource.getDescription.

This implementation returns a description that includes the passed-in description, if any.

public InputStream
getInputStream()

Implements org.springframework.core.io.InputStreamSource.getInputStream.

This implementation throws IllegalStateException if attempting to read the underlying stream multiple times.

public int
hashCode()

Overrides org.springframework.core.io.AbstractResource.hashCode.

This implementation returns the hash code of the underlying InputStream.

public boolean
isOpen()

Overrides org.springframework.core.io.AbstractResource.isOpen.

Overrides default org.springframework.core.io.Resource.isOpen.

This implementation always returns true.

Inherited from org.springframework.core.io.AbstractResource:
contentLengthcreateRelativegetFilegetFileForLastModifiedCheckgetFilenamegetURIgetURLisFileisReadablelastModifiedreadableChanneltoString

Field Detail

descriptionback to summary
private final String description
inputStreamback to summary
private final InputStream inputStream
readback to summary
private boolean read

Constructor Detail

InputStreamResourceback to summary
public InputStreamResource(InputStream inputStream)

Create a new InputStreamResource.

Parameters
inputStream:InputStream

the InputStream to use

InputStreamResourceback to summary
public InputStreamResource(InputStream inputStream, String description)

Create a new InputStreamResource.

Parameters
inputStream:InputStream

the InputStream to use

description:String

where the InputStream comes from

Method Detail

equalsback to summary
public boolean equals(Object other)

Overrides org.springframework.core.io.AbstractResource.equals.

This implementation compares the underlying InputStream.

Parameters
other:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
existsback to summary
public boolean exists()

Overrides org.springframework.core.io.AbstractResource.exists.

Implements org.springframework.core.io.Resource.exists.

This implementation always returns true.

Annotations
@Override
getDescriptionback to summary
public String getDescription()

Implements org.springframework.core.io.Resource.getDescription.

This implementation returns a description that includes the passed-in description, if any.

Annotations
@Override
getInputStreamback to summary
public InputStream getInputStream() throws IOException, IllegalStateException

Implements org.springframework.core.io.InputStreamSource.getInputStream.

This implementation throws IllegalStateException if attempting to read the underlying stream multiple times.

Returns:InputStream

Doc from org.springframework.core.io.InputStreamSource.getInputStream.

the input stream for the underlying resource (must not be null)

Annotations
@Override
Exceptions
IOException:

Doc from org.springframework.core.io.InputStreamSource.getInputStream.

if the content stream could not be opened

hashCodeback to summary
public int hashCode()

Overrides org.springframework.core.io.AbstractResource.hashCode.

This implementation returns the hash code of the underlying InputStream.

Returns:int

Doc from java.lang.Object.hashCode.

a hash code value for this object

Annotations
@Override
isOpenback to summary
public boolean isOpen()

Overrides org.springframework.core.io.AbstractResource.isOpen.

Overrides default org.springframework.core.io.Resource.isOpen.

This implementation always returns true.

Annotations
@Override