|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
messif.objects.nio.BufferInputStream
public class BufferInputStream
Input stream that implements the BinaryInput
using
an internal buffer
.
If multiple threads use the same instance of this class, the access to the instance must be synchronized.
BufferOutputStream
Constructor Summary | |
---|---|
BufferInputStream(byte[] array)
Creates a new instance of BufferInputStream. |
|
BufferInputStream(java.nio.ByteBuffer buffer)
Creates a new instance of BufferInputStream. |
|
BufferInputStream(int bufferSize,
boolean bufferDirect)
Creates a new instance of BufferInputStream. |
Method Summary | |
---|---|
int |
available()
|
int |
bufferedSize()
Returns the number of bytes currently in the buffer. |
long |
getPosition()
Returns the current position in this input stream. |
int |
read()
Reads the next byte of data from the input stream. |
int |
read(byte[] buf,
int off,
int len)
Reads up to len bytes of data from the input stream into
an array of bytes. |
protected void |
read(java.nio.ByteBuffer buffer)
Reads some data into the buffer . |
int |
read(java.nio.channels.FileChannel channel,
long position)
Reads data from the specified file channel. |
int |
read(java.nio.channels.ReadableByteChannel channel)
Reads data from the specified channel. |
java.nio.ByteBuffer |
readInput(int minBytes)
Returns a buffer that contains at least minBytes bytes. |
void |
setPosition(long position)
Sets the current position in this input stream. |
long |
skip(long n)
Skips over and discards n bytes of data from this input. |
Methods inherited from class java.io.InputStream |
---|
close, mark, markSupported, read, reset |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BufferInputStream(int bufferSize, boolean bufferDirect) throws java.lang.IllegalArgumentException
bufferSize
- the size of the internal bufferbufferDirect
- allocate the internal buffer as direct
java.lang.IllegalArgumentException
- if there specified buffer size is not validpublic BufferInputStream(java.nio.ByteBuffer buffer)
buffer
- the internal buffer for this streampublic BufferInputStream(byte[] array)
wraps
the given data array.
array
- the data array for this streamMethod Detail |
---|
public long getPosition()
public void setPosition(long position) throws java.io.IOException
position
- the new position in this input stream
java.io.IOException
- if the position is invalid or there was another I/O errorpublic int bufferedSize()
public int read() throws java.io.IOException
int
in the range 0
to
255
. 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.
read
in class java.io.InputStream
-1
if the end of the stream is reached
java.io.IOException
- if there was an error using readChannelpublic int read(byte[] buf, int off, int len) throws java.io.IOException, java.lang.IndexOutOfBoundsException
len
bytes of data from the input stream into
an array of bytes. An attempt is made to read as many as
len
bytes, but a smaller number may be read.
The number of bytes actually read is returned as an integer.
read
in class java.io.InputStream
buf
- the buffer into which the data is readoff
- the start offset in array buf
at which the data is writtenlen
- the maximum number of bytes to read
-1
if there is no more data because the end of
the stream has been reached
java.io.IOException
- if there was an error reading from the input stream
java.lang.IndexOutOfBoundsException
- if the buf.length - off < len
public long skip(long n) throws java.io.IOException
BinaryInput
n
bytes of data from this input.
The skip
method may, for a variety of reasons, end
up skipping over some smaller number of bytes, possibly 0
.
This may result from any of a number of conditions; reaching end of file
before n
bytes have been skipped is only one possibility.
The actual number of bytes skipped is returned.
skip
in interface BinaryInput
skip
in class java.io.InputStream
n
- the number of bytes to be skipped
java.io.IOException
- if the input does not support seek or some other I/O error occurspublic int available()
available
in class java.io.InputStream
public java.nio.ByteBuffer readInput(int minBytes) throws java.io.IOException
BinaryInput
minBytes
bytes.
If the buffer with the required number of bytes cannot be provided, an
IOException
is thrown. Note that the returned
buffer can provide more than minBytes
.
readInput
in interface BinaryInput
minBytes
- the minimal number of bytes that must be available for reading from the buffer
java.io.IOException
- if there was an error while preparing a buffer with minBytes
bytesprotected void read(java.nio.ByteBuffer buffer) throws java.io.EOFException, java.io.IOException
buffer
.
This method blocks until at least one byte is read or,
if there are no more data, EOFException
is thrown.
buffer
- the buffer into which to read additional data
java.io.EOFException
- if there are no more data available
java.io.IOException
- if there was an error reading datapublic int read(java.nio.channels.ReadableByteChannel channel) throws java.io.IOException
read
method is called on the channel.
channel
- the readable channel from which the data is read
java.io.IOException
- if there was an I/O error reading from the channelpublic int read(java.nio.channels.FileChannel channel, long position) throws java.io.IOException
read
method is called on the channel.
channel
- the file channel from which the data is readposition
- the position in the file where to read the data
java.io.IOException
- if there was an I/O error reading from the channel
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |