pyrasun.eio
Class EIOInputBuffer

java.lang.Object
  extended bypyrasun.eio.EIOInputBuffer

public class EIOInputBuffer
extends java.lang.Object

Abstracts out NIO reading and related buffer operations to make life slightly easier for for normal folk. Normally one of these is retrieved from ReadWriteEndpoint.getInputBuffer(). Instantiting one of these on your own would be - weird. This class does simple coordination between an underlying ByteBuffer, the Endpoint it's attached to, and a ByteBufferInputStream. The ByteBuffer can expand as needed according to what you set in setLimit() and resetFor()


Constructor Summary
EIOInputBuffer(ReadWriteEndpoint endpoint)
          Create an one of these buffers against the given endpoint.
 
Method Summary
 void clear()
          Clears out any old junk and gets us ready to pull more data off the channel.
 void ensure(int size)
          Ensures that the underlying ByteBuffer has at least 'size' bytes.
 void ensure(int size, boolean saveOld)
          Ensures that the underlying ByteBuffer has at least 'size' bytes.
 void flip()
          Flips the underlying ByteBuffer for reading by your application
 java.nio.ByteBuffer getByteBuffer()
          Returns the underlying backing ByteBuffer.
 ByteBufferInputStream getInputStream()
          Returns the ByteBufferInputStream associated with this guy and backed by the ByteBuffer.
 boolean read()
          Reads data from the underlying channel into the internal ByteBufer here.
 void resetFor(int size)
          Resets a partially used buffer for a bigger size, and preserves any data that's currently already in the buffer.
 void setLimit(int size)
          Set the read limit for this buffer.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EIOInputBuffer

public EIOInputBuffer(ReadWriteEndpoint endpoint)
Create an one of these buffers against the given endpoint.

Method Detail

setLimit

public void setLimit(int size)
Set the read limit for this buffer. The buffer will never try to read more than a total of setLimit() bytes (unless of course you call resetFor()).


ensure

public void ensure(int size)
Ensures that the underlying ByteBuffer has at least 'size' bytes. This preserves any data that's already in the buffer.


ensure

public void ensure(int size,
                   boolean saveOld)
Ensures that the underlying ByteBuffer has at least 'size' bytes. If saveOld is true, it saves old data. If it s


flip

public void flip()
Flips the underlying ByteBuffer for reading by your application


resetFor

public void resetFor(int size)
Resets a partially used buffer for a bigger size, and preserves any data that's currently already in the buffer.


read

public boolean read()
             throws java.io.IOException
Reads data from the underlying channel into the internal ByteBufer here. This attempts to fill up to the limit - and returns true if it actually does go up to the limit. Returns false if it can't read all the way up to limit characters. Either way, the read status is held here internally so you can also query it later. This complete/not complete information is most useful for non-blocking readers.

Throws:
java.io.IOException

clear

public void clear()
Clears out any old junk and gets us ready to pull more data off the channel.


getByteBuffer

public java.nio.ByteBuffer getByteBuffer()
Returns the underlying backing ByteBuffer. WARNING - it's not safe to hold onto this reference past calls to resetFor() or clear().


getInputStream

public ByteBufferInputStream getInputStream()
Returns the ByteBufferInputStream associated with this guy and backed by the ByteBuffer.



Pyrasun EmberIO