net.sf.ehcache.util
Class MemoryEfficientByteArrayOutputStream
java.lang.Object
java.io.OutputStream
java.io.ByteArrayOutputStream
net.sf.ehcache.util.MemoryEfficientByteArrayOutputStream
- All Implemented Interfaces:
- Closeable, Flushable
public final class MemoryEfficientByteArrayOutputStream
- extends ByteArrayOutputStream
This class is designed to minimise the number of System.arraycopy(); methods
required to complete.
ByteArrayOutputStream in the JDK is tuned for a wide variety of purposes. This sub-class
starts with an initial size which is a closer match for ehcache usage.
- Version:
- $Id$
- Author:
- Greg Luck
MemoryEfficientByteArrayOutputStream
public MemoryEfficientByteArrayOutputStream(int size)
- Creates a new byte array output stream, with a buffer capacity of
the specified size, in bytes.
- Parameters:
size
- the initial size.
getBytes
public byte[] getBytes()
- Gets the bytes.
- Returns:
- the underlying byte[], or a copy if the byte[] is oversized
serialize
public static MemoryEfficientByteArrayOutputStream serialize(Serializable serializable,
int estimatedPayloadSize)
throws IOException
- Factory method
- Parameters:
serializable
- any Object that implements SerializableestimatedPayloadSize
- how many bytes is expected to be in the Serialized representation
- Returns:
- a ByteArrayOutputStream with a Serialized object in it
- Throws:
IOException
- if something goes wrong with the Serialization
serialize
public static MemoryEfficientByteArrayOutputStream serialize(Serializable serializable)
throws IOException
- Factory method. This method optimises memory by trying to make a better guess than the Java default
of 32 bytes by assuming the starting point for the serialized size will be what it was last time
this method was called.
- Parameters:
serializable
- any Object that implements Serializable
- Returns:
- a ByteArrayOutputStream with a Serialized object in it
- Throws:
IOException
- if something goes wrong with the Serialization
Copyright 2001-2015, Terracotta, Inc.