org.cloudfoundry.client.lib.io
Class DynamicInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.cloudfoundry.client.lib.io.DynamicInputStream
All Implemented Interfaces:
Closeable
Direct Known Subclasses:
DynamicZipInputStream

public abstract class DynamicInputStream
extends InputStream

InputStream that dynamically loads data on demand as the stream is read. Subclasses must implement the writeMoreData() method.

Author:
Phillip Webb

Constructor Summary
DynamicInputStream()
           
 
Method Summary
protected  OutputStream getOutputStream()
          Returns the OutputStream that should be used when writing data.
 int read()
           
 int read(byte[] b, int off, int len)
           
protected abstract  boolean writeMoreData()
          Called when more data should be written to the output stream.
 
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DynamicInputStream

public DynamicInputStream()
Method Detail

read

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

read

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

getOutputStream

protected final OutputStream getOutputStream()
Returns the OutputStream that should be used when writing data. The output stream instance will not change during the life of the object and so can be used as the source to a a FilterInputStream. This is an in-memory stream so care should be taken to not write large amounts of data.

Returns:
the output stream
See Also:
writeMoreData()

writeMoreData

protected abstract boolean writeMoreData()
                                  throws IOException
Called when more data should be written to the output stream. This method can be called many times, implementations should write zero or more bytes to output stream on each call. Generally it is recommended that not more that 4096 bytes are written in a single call.

Returns:
false when no more data is available to write.
Throws:
IOException


Copyright © 2013. All rights reserved.