|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.OutputStream
messif.objects.nio.BufferOutputStream
public class BufferOutputStream
Output stream that implements the BinaryOutput
using
an internal buffer
.
If multiple threads use the same instance of this class, the access to the instance must be synchronized.
BufferInputStream
Field Summary | |
---|---|
static int |
MINIMAL_BUFFER_SIZE
Minimal buffer size in bytes |
Constructor Summary | |
---|---|
BufferOutputStream(java.nio.ByteBuffer buffer)
Creates a new instance of BufferOutputStream. |
|
BufferOutputStream(int bufferSize,
boolean bufferDirect)
Creates a new instance of BufferOutputStream. |
Method Summary | |
---|---|
int |
bufferedSize()
Returns the number of bytes currently in the buffer. |
void |
close()
|
void |
flush()
Flushes this output stream and forces any buffered output bytes to be written out. |
boolean |
isDirty()
Returns true if there are some bytes pending in the buffer. |
java.nio.ByteBuffer |
prepareOutput(int minBytes)
Returns a buffer that allows to write at least minBytes . |
byte[] |
write()
Writes the buffered data to a byte array. |
void |
write(byte[] bytes,
int off,
int len)
Writes len bytes from the specified byte array
starting at offset off to this output stream. |
protected void |
write(java.nio.ByteBuffer buffer)
Writes the buffered data out. |
int |
write(java.nio.channels.FileChannel channel,
long position)
Writes the buffered data to the specified file channel. |
void |
write(int b)
Writes the specified byte to this output stream. |
int |
write(java.nio.channels.WritableByteChannel channel)
Writes the buffered data to the specified channel. |
Methods inherited from class java.io.OutputStream |
---|
write |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int MINIMAL_BUFFER_SIZE
Constructor Detail |
---|
public BufferOutputStream(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 BufferOutputStream(java.nio.ByteBuffer buffer)
buffer
- the internal buffer this streamMethod Detail |
---|
public boolean isDirty()
flush()
public int bufferedSize()
public void write(int b) throws java.io.IOException
write
in class java.io.OutputStream
b
- the byte to be written
java.io.IOException
- if there was an error using writeChannelpublic void write(byte[] bytes, int off, int len) throws java.io.IOException
len
bytes from the specified byte array
starting at offset off
to this output stream.
write
in class java.io.OutputStream
bytes
- the dataoff
- the start offset in the datalen
- the number of bytes to write
java.io.IOException
- if there was an error using writeChannelpublic void flush() throws java.io.IOException
flush
in interface java.io.Flushable
flush
in interface BinaryOutput
flush
in class java.io.OutputStream
java.io.IOException
- if there was an error using writeChannelpublic void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in class java.io.OutputStream
java.io.IOException
public java.nio.ByteBuffer prepareOutput(int minBytes) throws java.io.IOException
BinaryOutput
minBytes
.
If the buffer with the required space cannot be provided, an
IOException
is thrown. Note that the returned
buffer can provide more than minBytes
.
prepareOutput
in interface BinaryOutput
minBytes
- the minimal number of bytes that must be available for writing into the buffer
java.io.IOException
- if there was an error while preparing a buffer for minBytes
bytesprotected void write(java.nio.ByteBuffer buffer) throws java.io.IOException
buffer
- the buffer from which to write data
java.io.IOException
- if there was an error writing the datapublic int write(java.nio.channels.WritableByteChannel channel) throws java.io.IOException
write
method is called on the channel.
channel
- the writable channel that the buffered data is written to
java.io.IOException
- if there was an I/O error writing to the channelpublic byte[] write()
public int write(java.nio.channels.FileChannel channel, long position) throws java.io.IOException
write
method is called on the channel.
channel
- the file channel that the buffered data is written toposition
- the position in the file where to write the data
java.io.IOException
- if there was an I/O error writing to the channel
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |