JBoss Marshalling 1.3.0.CR9

org.jboss.marshalling
Class NioByteInput

java.lang.Object
  extended by java.io.InputStream
      extended by org.jboss.marshalling.NioByteInput
All Implemented Interfaces:
Closeable, ByteInput

public class NioByteInput
extends InputStream
implements ByteInput

A ByteInput implementation which is populated asynchronously with ByteBuffer instances.


Nested Class Summary
static interface NioByteInput.BufferReturn
          A handler for returning buffers which are have been exhausted.
static interface NioByteInput.InputHandler
          A handler for events relating to the consumption of data from a NioByteInput instance.
 
Constructor Summary
NioByteInput(NioByteInput.InputHandler inputHandler)
          Construct a new instance.
 
Method Summary
 int available()
          Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream.
 void close()
          
 void push(ByteBuffer buffer)
          Push a buffer into the queue.
 void push(ByteBuffer buffer, NioByteInput.BufferReturn bufferReturn)
          Push a buffer into the queue.
 void pushEof()
          Push the EOF condition into the queue.
 void pushException(IOException e)
          Push an exception condition into the queue.
 int read()
          Reads the next byte of data from the input stream.
 int read(byte[] b, int off, int len)
          Read some bytes from the input stream into the given array.
 long skip(long qty)
          Skips over and discards up to n bytes of data from this input stream.
 
Methods inherited from class java.io.InputStream
mark, markSupported, read, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jboss.marshalling.ByteInput
read
 

Constructor Detail

NioByteInput

public NioByteInput(NioByteInput.InputHandler inputHandler)
Construct a new instance. The given inputHandler will be invoked after each buffer is fully read and when the stream is closed.

Parameters:
inputHandler - the input events handler
Method Detail

push

public void push(ByteBuffer buffer)
Push a buffer into the queue. There is no mechanism to limit the number of pushed buffers; if such a mechanism is desired, it must be implemented externally, for example maybe using a Semaphore.

Parameters:
buffer - the buffer from which more data should be read

push

public void push(ByteBuffer buffer,
                 NioByteInput.BufferReturn bufferReturn)
Push a buffer into the queue. There is no mechanism to limit the number of pushed buffers; if such a mechanism is desired, it must be implemented externally, for example maybe using a Semaphore.

Parameters:
buffer - the buffer from which more data should be read
bufferReturn - the buffer return to send this buffer to when it is exhausted

pushEof

public void pushEof()
Push the EOF condition into the queue. After this method is called, no further buffers may be pushed into this instance.


pushException

public void pushException(IOException e)
Push an exception condition into the queue. After this method is called, no further buffers may be pushed into this instance.

Parameters:
e - the exception to push

read

public int read()
         throws IOException
Reads the next byte of data from the input stream. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Specified by:
read in interface ByteInput
Specified by:
read in class InputStream
Returns:
the next byte, or -1 if the end of stream has been reached
Throws:
IOException - if an error occurs

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Read some bytes from the input stream into the given array. Returns the number of bytes actually read (possibly zero), or -1 if the end of stream has been reached.

Specified by:
read in interface ByteInput
Overrides:
read in class InputStream
Parameters:
b - the destination array
off - the offset into the array into which data should be read
len - the number of bytes to attempt to fill in the destination array
Returns:
the number of bytes read (possibly zero), or -1 if the end of stream has been reached
Throws:
IOException - if an error occurs

available

public int available()
              throws IOException
Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream.

Specified by:
available in interface ByteInput
Overrides:
available in class InputStream
Returns:
the number of bytes
Throws:
IOException - if an error occurs

skip

public long skip(long qty)
          throws IOException
Description copied from interface: ByteInput
Skips over and discards up to n bytes of data from this input stream. If the end of stream is reached, this method returns 0 in order to be consistent with InputStream.skip(long).

Specified by:
skip in interface ByteInput
Overrides:
skip in class InputStream
Parameters:
qty - the number of bytes to attempt to skip
Returns:
the number of bytes skipped
Throws:
IOException - if an error occurs

close

public void close()
           throws IOException

Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException

JBoss Marshalling 1.3.0.CR9

Copyright © 2011 JBoss, a division of Red Hat, Inc.