org.apache.pig.data
Class WritableByteArray
java.lang.Object
java.io.OutputStream
java.io.ByteArrayOutputStream
org.apache.pig.data.WritableByteArray
- All Implemented Interfaces:
- Closeable, Flushable
public class WritableByteArray
- extends ByteArrayOutputStream
A reusable byte buffer implementation
This saves memory over creating a new byte[] and
ByteArrayOutputStream each time data is written.
Typical usage is something like the following:
WritableByteArray buffer = new WritableByteArray();
while (... loop condition ...) {
buffer.reset();
... write to buffer ...
byte[] data = buffer.getData();
int dataLength = buffer.getLength();
... write data to its ultimate destination ...
}
Method Summary |
byte[] |
getData()
Returns the current contents of the buffer. |
int |
getLength()
Returns the length of the valid data currently in the buffer |
WritableByteArray
public WritableByteArray()
WritableByteArray
public WritableByteArray(int size)
WritableByteArray
public WritableByteArray(byte[] buf)
getData
public byte[] getData()
- Returns the current contents of the buffer.
Data is only valid to
getLength()
.
- Returns:
- contents of the buffer
getLength
public int getLength()
- Returns the length of the valid data currently in the buffer
- Returns:
- length of valid data
Copyright © 2007-2012 The Apache Software Foundation