java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable@LimitedPrivate({"HDFS","MapReduce"})
@Unstable
public class OutputBuffer
extends java.io.FilterOutputStream
OutputStream implementation that writes to an in-memory
buffer.
This saves memory over creating a new OutputStream and ByteArrayOutputStream each time data is written.
Typical usage is something like the following:
OutputBuffer buffer = new OutputBuffer();
while (... loop condition ...) {
buffer.reset();
... write buffer using OutputStream methods ...
byte[] data = buffer.getData();
int dataLength = buffer.getLength();
... write data to its ultimate destination ...
}
DataOutputBuffer,
InputBuffer| Constructor | Description |
|---|---|
OutputBuffer() |
Constructs a new empty buffer.
|
| Modifier and Type | Method | Description |
|---|---|---|
byte[] |
getData() |
Returns the current contents of the buffer.
|
int |
getLength() |
Returns the length of the valid data currently in the buffer.
|
OutputBuffer |
reset() |
|
void |
write(java.io.InputStream in,
int length) |
Writes bytes from a InputStream directly into the buffer.
|
public byte[] getData()
getLength().public int getLength()
public OutputBuffer reset()
public void write(java.io.InputStream in,
int length)
throws java.io.IOException
in - input in.length - input length.java.io.IOException - raised on errors performing I/O.Copyright © 2008–2025 Apache Software Foundation. All rights reserved.