public class ByteBufferOutputStream extends OutputStream
OutputStream
that writes to an existing ByteBuffer
.
The buffer is repositioned at construction, and written sequentially. Attempts
to write past the capacity of the buffer will result in IOException
.
Warnings:
Because this class explicitly repositions the buffer, you should not create
two instances around the same buffer; slice()
the buffer
instead. Instances of this class are only as thread-safe as the underlying
buffer (and the JavaDocs don't have much to say about that).
Constructor and Description |
---|
ByteBufferOutputStream(ByteBuffer buf)
Creates an instance that repositions the passed buffer to its start.
|
ByteBufferOutputStream(ByteBuffer buf,
int index)
Creates an instance that repositions the passed buffer to the specified
index.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
flush() |
void |
write(byte[] b) |
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
public ByteBufferOutputStream(ByteBuffer buf)
public ByteBufferOutputStream(ByteBuffer buf, int index)
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class OutputStream
IOException
public void flush() throws IOException
flush
in interface Flushable
flush
in class OutputStream
IOException
public void write(byte[] b, int off, int len) throws IOException
write
in class OutputStream
IOException
public void write(byte[] b) throws IOException
write
in class OutputStream
IOException
public void write(int b) throws IOException
write
in class OutputStream
IOException