@InterfaceAudience.Public @InterfaceStability.Evolving public class ByteBufferOutputStream extends OutputStream
| Modifier and Type | Field and Description |
|---|---|
protected ByteBuffer |
buf |
| Constructor and Description |
|---|
ByteBufferOutputStream(ByteBuffer bb) |
ByteBufferOutputStream(int capacity) |
ByteBufferOutputStream(int capacity,
boolean useDirectByteBuffer) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
flush() |
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(OutputStream out)
Writes the complete contents of this byte buffer output stream to
the specified output stream argument.
|
protected ByteBuffer buf
public ByteBufferOutputStream(int capacity)
public ByteBufferOutputStream(int capacity,
boolean useDirectByteBuffer)
public ByteBufferOutputStream(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 ByteBuffer getByteBuffer()
public void write(int b)
throws IOException
write in class OutputStreamIOExceptionpublic void writeTo(OutputStream out) throws IOException
out - the output stream to which to write the data.IOException - if an I/O error occurs.public void write(byte[] b)
throws IOException
write in class OutputStreamIOExceptionpublic void write(byte[] b,
int off,
int len)
throws IOException
write in class OutputStreamIOExceptionpublic void flush()
throws IOException
flush in interface Flushableflush in class OutputStreamIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class OutputStreamIOExceptionpublic byte[] toByteArray(int offset,
int length)
Copyright © 2007–2016 The Apache Software Foundation. All rights reserved.