org.jppf.io
Class ByteBufferInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.jppf.io.ByteBufferInputStream
All Implemented Interfaces:
Closeable

public class ByteBufferInputStream
extends InputStream

Implementation of an input stream backed by a ByteBuffer.

Author:
Laurent Cohen

Constructor Summary
ByteBufferInputStream(ByteBuffer buffer)
          Initialize this stream to read from the specified byte buffer.
ByteBufferInputStream(ByteBuffer buffer, boolean flip)
          Initialize this stream to read from the specified byte buffer.
 
Method Summary
 int available()
          Get the number of bytes that can still be read from this stream without blocking.
 void close()
          Close this input stream.
 void mark(int readlimit)
          Marks the current position in this input stream.
 boolean markSupported()
          Tests if this input stream supports the mark and reset methods.
 int read()
          Read one byte from
 int read(byte[] b)
           
 int read(byte[] b, int off, int len)
           
 void reset()
          Repositions this stream to the position at the time the mark method was last called on this input stream.
 long skip(long n)
          Skips over and discards n bytes of data from this input stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteBufferInputStream

public ByteBufferInputStream(ByteBuffer buffer)
Initialize this stream to read from the specified byte buffer.

Parameters:
buffer - the buffer to read from.

ByteBufferInputStream

public ByteBufferInputStream(ByteBuffer buffer,
                             boolean flip)
Initialize this stream to read from the specified byte buffer.

Parameters:
buffer - the buffer to read from.
flip - if true, then the buffer is flipped.
Method Detail

read

public int read()
         throws IOException
Read one byte from

Specified by:
read in class InputStream
Returns:
the next byte of data, or -1 if the end of the stream is reached.
Throws:
IOException - if an I/O error occurs.
See Also:
InputStream.read()

available

public int available()
              throws IOException
Get the number of bytes that can still be read from this stream without blocking.

Overrides:
available in class InputStream
Returns:
the number of bytes that can be read from this input stream without blocking.
Throws:
IOException - if an I/O error occurs.
See Also:
InputStream.available()

close

public void close()
           throws IOException
Close this input stream.

Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException - if an I/O error occurs.
See Also:
InputStream.close()

mark

public void mark(int readlimit)
Marks the current position in this input stream.

Overrides:
mark in class InputStream
Parameters:
readlimit - the maximum limit of bytes that can be read before the mark position becomes invalid.
See Also:
InputStream.mark(int)

markSupported

public boolean markSupported()
Tests if this input stream supports the mark and reset methods.

Overrides:
markSupported in class InputStream
Returns:
true if this stream instance supports the mark and reset methods, false otherwise.
See Also:
InputStream.markSupported()

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Overrides:
read in class InputStream
Parameters:
b - the buffer into which the data is read.
off - the start offset in array b at which the data is written.
len - the maximum number of bytes to read.
Returns:
the total number of bytes read into the buffer, or -1 if the end of the stream has been reached.
Throws:
IOException - if an I/O error occurs.
See Also:
InputStream.read(byte[], int, int)

read

public int read(byte[] b)
         throws IOException
Overrides:
read in class InputStream
Parameters:
b - the buffer into which the data is read.
Returns:
the total number of bytes read into the buffer, or -1 if the end of the stream has been reached.
Throws:
IOException - if an I/O error occurs.
See Also:
InputStream.read(byte[])

reset

public void reset()
           throws IOException
Repositions this stream to the position at the time the mark method was last called on this input stream.

Overrides:
reset in class InputStream
Throws:
IOException - if this stream has not been marked or if the mark has been invalidated.
See Also:
InputStream.reset()

skip

public long skip(long n)
          throws IOException
Skips over and discards n bytes of data from this input stream.

Overrides:
skip in class InputStream
Parameters:
n - the number of bytes to be skipped.
Returns:
the actual number of bytes skipped.
Throws:
IOException - if an I/O error occurs.
See Also:
InputStream.skip(long)


Copyright © 2005-2010 JPPF Team.