@InterfaceAudience.Public @InterfaceStability.Evolving public class ByteBufferOutputStream extends java.io.OutputStream
| Modifier and Type | Field and Description |
|---|---|
protected java.nio.ByteBuffer |
buf |
| Constructor and Description |
|---|
ByteBufferOutputStream(java.nio.ByteBuffer bb) |
ByteBufferOutputStream(int capacity) |
ByteBufferOutputStream(int capacity,
boolean useDirectByteBuffer) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
flush() |
java.nio.ByteBuffer |
getByteBuffer()
This flips the underlying BB so be sure to use it _last_!
|
int |
size() |
byte[] |
toByteArray(int offset,
int length) |
void |
write(byte[] b) |
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
void |
writeTo(java.io.OutputStream out)
Writes the complete contents of this byte buffer output stream to
the specified output stream argument.
|
public ByteBufferOutputStream(int capacity)
public ByteBufferOutputStream(int capacity,
boolean useDirectByteBuffer)
public ByteBufferOutputStream(java.nio.ByteBuffer bb)
bb - ByteBuffer to use. If too small, will be discarded and a new one allocated in its
place; i.e. the passed in BB may NOT BE RETURNED!! Minimally it will be altered. SIDE EFFECT!!
If you want to get the newly allocated ByteBuffer, you'll need to pick it up when
done with this instance by calling getByteBuffer(). All this encapsulation violation
is so we can recycle buffers rather than allocate each time; it can get expensive especially
if the buffers are big doing allocations each time or having them undergo resizing because
initial allocation was small.getByteBuffer()public int size()
public java.nio.ByteBuffer getByteBuffer()
public void write(int b)
throws java.io.IOException
write in class java.io.OutputStreamjava.io.IOExceptionpublic void writeTo(java.io.OutputStream out)
throws java.io.IOException
out - the output stream to which to write the data.java.io.IOException - if an I/O error occurs.public void write(byte[] b)
throws java.io.IOException
write in class java.io.OutputStreamjava.io.IOExceptionpublic void write(byte[] b,
int off,
int len)
throws java.io.IOException
write in class java.io.OutputStreamjava.io.IOExceptionpublic void flush()
throws java.io.IOException
flush in interface java.io.Flushableflush in class java.io.OutputStreamjava.io.IOExceptionpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.OutputStreamjava.io.IOExceptionpublic byte[] toByteArray(int offset,
int length)