org.eclipse.webdav.http.client
Class RequestInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.eclipse.webdav.http.client.RequestInputStream
All Implemented Interfaces:
Closeable

public class RequestInputStream
extends InputStream

A resettable InputStream.

Note: This class/interface is part of an interim API that is still under development and expected to change significantly before reaching stability. It is being made available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.


Constructor Summary
RequestInputStream(byte[] b)
          Creates a RequestInputStream on the given byte array.
RequestInputStream(ByteArrayInputStream bais)
          Creates a RequestInputStream on the given ByteArrayInputStream.
RequestInputStream(File file)
          Creates a RequestInputStream on the given file.
RequestInputStream(InputStream is, long length)
          Creates a RequestInputStream on the given InputStream.
 
Method Summary
 void close()
           
 long length()
          Returns the length of the stream, or -1 if the length of the stream is unknown.
 int read()
           
 int read(byte[] b, int off, int len)
           
 void reset()
          Resets the stream to its beginning so it can be read again.
 
Methods inherited from class java.io.InputStream
available, mark, markSupported, read, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestInputStream

public RequestInputStream(byte[] b)
Creates a RequestInputStream on the given byte array.

Parameters:
b - the underlying byte array

RequestInputStream

public RequestInputStream(ByteArrayInputStream bais)
Creates a RequestInputStream on the given ByteArrayInputStream.

Parameters:
bais - the underlying input stream

RequestInputStream

public RequestInputStream(File file)
                   throws IOException
Creates a RequestInputStream on the given file.

Parameters:
file - the underlying file
Throws:
IOException - if there is a problem opening the file

RequestInputStream

public RequestInputStream(InputStream is,
                          long length)
                   throws IOException
Creates a RequestInputStream on the given InputStream. The length of the stream is set to be the given length. If the length of the stream is unknown, the given length must be -1.

Note that to enable reset on streams created using this constructor, the streams content is written to a temporary file while the stream is read. This results in a loss of performance, so use this constructor as a last resort.

Parameters:
is - the underlying input stream
length - the length of the stream, or -1 if the length is unknown
Throws:
IOException - if there is a problem creating or opening the temporary file
Method Detail

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException
See Also:
InputStream.close()

length

public long length()
Returns the length of the stream, or -1 if the length of the stream is unknown. Note the length of the stream is always known once the stream has been reset.

Returns:
the length of the stream

read

public int read()
         throws IOException
Specified by:
read in class InputStream
Throws:
IOException
See Also:
InputStream.read()

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException
See Also:
InputStream.read(byte[], int, int)

reset

public void reset()
           throws IOException
Resets the stream to its beginning so it can be read again.

Overrides:
reset in class InputStream
Throws:
IOException - if there is an I/O error


Copyright © 2001-2014 JBoss by Red Hat. All Rights Reserved.