public abstract class AbstractByteBufferOutputStream extends OutputStream
java.io
stream based output and java.nio
based output.
Write operations are buffered in an internal java.nio.ByteBuffer
.
If this buffer gets full, or flush()
or close()
are being called,
the method write(ByteBuffer, WRITE_MODE)
, that must be implemented by derived
classes, is being called to consume pending data in the buffer.
Data not consumed by write(ByteBuffer, WRITE_MODE)
will again be passed in
subsequent write operations. So the implementor is responsible for avoiding infinite
loops.
This class is not synchronized.
Modifier and Type | Class and Description |
---|---|
static class |
AbstractByteBufferOutputStream.WRITE_MODE |
Modifier and Type | Field and Description |
---|---|
protected ByteBuffer |
m_buffer |
Constructor and Description |
---|
AbstractByteBufferOutputStream(ByteBuffer p_buffer) |
AbstractByteBufferOutputStream(int p_iCapacity) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this output stream and forces any buffered output bytes
to be written out.
|
void |
flush()
Flushes this output stream and forces any buffered output bytes
to be written out.
|
void |
write(byte[] p_buf,
int p_iOffs,
int p_iLen) |
abstract void |
write(ByteBuffer p_buffer,
AbstractByteBufferOutputStream.WRITE_MODE p_mode) |
void |
write(int p_iByte) |
write
protected ByteBuffer m_buffer
public AbstractByteBufferOutputStream(int p_iCapacity)
public AbstractByteBufferOutputStream(ByteBuffer p_buffer)
public void write(int p_iByte) throws IOException
write
in class OutputStream
IOException
public void write(byte[] p_buf, int p_iOffs, int p_iLen) throws IOException
write
in class OutputStream
IOException
public abstract void write(ByteBuffer p_buffer, AbstractByteBufferOutputStream.WRITE_MODE p_mode) throws IOException
p_buffer
- The buffer that contains the data to be written.p_mode
- AbstractByteBufferOutputStream.WRITE_MODE.WRITE
if this method was called by
write(int)
, OutputStream.write(byte[])
, or
write(byte[], int, int)
, orAbstractByteBufferOutputStream.WRITE_MODE.FLUSH
if this method was called
by flush()
, orAbstractByteBufferOutputStream.WRITE_MODE.CLOSE
if this method was called
by close()
.IOException
- If an I/O error occurs.public void flush() throws IOException
write(ByteBuffer, WRITE_MODE)
will be called with AbstractByteBufferOutputStream.WRITE_MODE.FLUSH
as second parameter.
flush
in interface Flushable
flush
in class OutputStream
IOException
- If an I/O error occurred, or if the call to
write(ByteBuffer, WRITE_MODE)
did not consume all pending data.public void close() throws IOException
write(ByteBuffer, WRITE_MODE)
will be called with AbstractByteBufferOutputStream.WRITE_MODE.CLOSE
as second parameter.
close
in interface Closeable
close
in interface AutoCloseable
close
in class OutputStream
IOException
- If an I/O error occurred, or if the call to
write(ByteBuffer, WRITE_MODE)
did not consume all pending data.Copyright © 2009-2013 Alexander Veit. All Rights Reserved.