java.io.Closeable, java.io.DataOutput, java.io.Flushable, java.lang.AutoCloseable@LimitedPrivate({"HDFS","MapReduce"})
@Unstable
public class DataOutputBuffer
extends java.io.DataOutputStream
DataOutput implementation that writes to an in-memory
buffer.
This saves memory over creating a new DataOutputStream and ByteArrayOutputStream each time data is written.
Typical usage is something like the following:
DataOutputBuffer buffer = new DataOutputBuffer();
while (... loop condition ...) {
buffer.reset();
... write buffer using DataOutput methods ...
byte[] data = buffer.getData();
int dataLength = buffer.getLength();
... write data to its ultimate destination ...
}
| Constructor | Description |
|---|---|
DataOutputBuffer() |
Constructs a new empty buffer.
|
DataOutputBuffer(int size) |
| 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.
|
DataOutputBuffer |
reset() |
Resets the buffer to empty.
|
void |
write(java.io.DataInput in,
int length) |
Writes bytes from a DataInput directly into the buffer.
|
void |
writeInt(int v,
int offset) |
Overwrite an integer into the internal buffer.
|
void |
writeTo(java.io.OutputStream out) |
Write to a file stream.
|
flush, size, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTFpublic DataOutputBuffer()
public DataOutputBuffer(int size)
public byte[] getData()
getLength().public int getLength()
public DataOutputBuffer reset()
public void write(java.io.DataInput in,
int length)
throws java.io.IOException
in - data input.length - length.java.io.IOException - raised on errors performing I/O.public void writeTo(java.io.OutputStream out)
throws java.io.IOException
out - OutputStream.java.io.IOException - raised on errors performing I/O.public void writeInt(int v,
int offset)
throws java.io.IOException
v - v.offset - offset.java.io.IOException - raised on errors performing I/O.Copyright © 2008–2025 Apache Software Foundation. All rights reserved.