com.healthmarketscience.rmiio.util
Class InputStreamAdapter

java.lang.Object
  extended by com.healthmarketscience.rmiio.util.InputStreamAdapter

public abstract class InputStreamAdapter
extends Object

Utility class for optimizing different read strategies based on the type of the underlying InputStream.

Author:
James Ahlborn

Method Summary
static InputStreamAdapter create(InputStream istream, int packetSize)
           
abstract  InputStream getInputStream()
           
abstract  byte[] getTempBuffer()
           
abstract  byte[] readPacket()
          Gets the next "packet" from the internal buffer and returns it (if any).
abstract  int readTemp()
          Reads some number of bytes from the underlying stream and puts them in a buffer available from the getTempBuffer() call.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInputStream

public abstract InputStream getInputStream()
Returns:
the underlying InputStream

readPacket

public abstract byte[] readPacket()
                           throws IOException
Gets the next "packet" from the internal buffer and returns it (if any). This method will probably block until a fully filled packet is created (equivalent to calling readPacket(false)).

Note, this method is slightly optimized for current usage, so an implementation caveat is that the returned packet must be "consumed" before another call to readPacket is made.

Returns:
a fully filled array of byte's or null if the end of stream has been reached
Throws:
IOException

getTempBuffer

public abstract byte[] getTempBuffer()
Returns:
a buffer containing the bytes read by the last successful readTemp() call

readTemp

public abstract int readTemp()
                      throws IOException
Reads some number of bytes from the underlying stream and puts them in a buffer available from the getTempBuffer() call.

Returns:
the number of bytes read, or -1 if end of stream was reached
Throws:
IOException

create

public static InputStreamAdapter create(InputStream istream,
                                        int packetSize)
Parameters:
istream - stream to wrap and for which the implementation is optimized
packetSize - recommended packet size for any created packets
Returns:
a new InputStreamAdapter optimized for the stream type


Copyright © 2006–2016 Health Market Science. All rights reserved.