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 Closeableclose in interface AutoCloseableclose in class OutputStreamIOExceptionpublic void flush()
throws IOException
flush in interface Flushableflush in class OutputStreamIOExceptionpublic void write(byte[] b,
int off,
int len)
throws IOException
write in class OutputStreamIOExceptionpublic void write(byte[] b)
throws IOException
write in class OutputStreamIOExceptionpublic void write(int b)
throws IOException
write in class OutputStreamIOException