org.springframework.core.io
Class InputStreamResource

java.lang.Object
  extended by org.springframework.core.io.AbstractResource
      extended by org.springframework.core.io.InputStreamResource
All Implemented Interfaces:
InputStreamSource, Resource

public class InputStreamResource
extends AbstractResource

Resource implementation for a given InputStream. Should only be used if no specific Resource implementation is applicable.

In contrast to other Resource implementations, this is a descriptor for an already opened resource - therefore returning true on isOpen(). Do not use it if you need to keep the resource descriptor somewhere, or if you need to read a stream multiple times.

Since:
28.12.2003
Author:
Juergen Hoeller

Constructor Summary
InputStreamResource(InputStream inputStream)
          Create a new InputStreamResource.
InputStreamResource(InputStream inputStream, String description)
          Create a new InputStreamResource.
 
Method Summary
 boolean exists()
          This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened.
 String getDescription()
          This abstract method declaration shadows the method in the Resource interface.
 InputStream getInputStream()
          This implementation throws IllegalStateException if attempting to read the underlying stream multiple times.
 boolean isOpen()
          This implementations always returns false.
 
Methods inherited from class org.springframework.core.io.AbstractResource
createRelative, equals, getFile, getFilename, getURL, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InputStreamResource

public InputStreamResource(InputStream inputStream)
Create a new InputStreamResource.

Parameters:
inputStream - the InputStream to use

InputStreamResource

public InputStreamResource(InputStream inputStream,
                           String description)
Create a new InputStreamResource.

Parameters:
inputStream - the InputStream to use
description - where the InputStream comes from
Method Detail

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

isOpen

public boolean isOpen()
Description copied from class: AbstractResource
This implementations always returns false.

Specified by:
isOpen in interface Resource
Overrides:
isOpen in class AbstractResource

getInputStream

public InputStream getInputStream()
                           throws IOException,
                                  IllegalStateException
This implementation throws IllegalStateException if attempting to read the underlying stream multiple times.

Throws:
IOException - if the stream could not be opened
IllegalStateException

getDescription

public String getDescription()
Description copied from class: AbstractResource
This abstract method declaration shadows the method in the Resource interface. This is necessary to make the toString implementation in this class work on Sun's JDK 1.3 classic VM, which can't find the getDescription method when executing toString else.

Specified by:
getDescription in interface Resource
Specified by:
getDescription in class AbstractResource
See Also:
Resource.getDescription()


Copyright (c) 2002-2005 The Spring Framework Project.