public final class MemoryEfficientByteArrayOutputStream
extends java.io.ByteArrayOutputStream
Modifier and Type | Field and Description |
---|---|
private static int |
BEST_GUESS_SIZE
byte[] payloads are not expected to be tiny.
|
private static int |
lastSize |
Constructor and Description |
---|
MemoryEfficientByteArrayOutputStream(int size)
Creates a new byte array output stream, with a buffer capacity of
the specified size, in bytes.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
getBytes()
Gets the bytes.
|
static MemoryEfficientByteArrayOutputStream |
serialize(java.io.Serializable serializable)
Factory method.
|
static MemoryEfficientByteArrayOutputStream |
serialize(java.io.Serializable serializable,
int estimatedPayloadSize)
Factory method
|
private static final int BEST_GUESS_SIZE
private static int lastSize
public MemoryEfficientByteArrayOutputStream(int size)
size
- the initial size.public byte[] getBytes()
public static MemoryEfficientByteArrayOutputStream serialize(java.io.Serializable serializable, int estimatedPayloadSize) throws java.io.IOException
serializable
- any Object that implements SerializableestimatedPayloadSize
- how many bytes is expected to be in the Serialized representationjava.io.IOException
- if something goes wrong with the Serializationpublic static MemoryEfficientByteArrayOutputStream serialize(java.io.Serializable serializable) throws java.io.IOException
serializable
- any Object that implements Serializablejava.io.IOException
- if something goes wrong with the Serialization