Package org.infinispan.io
Class ExpandableMarshalledValueByteStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.infinispan.io.MarshalledValueByteStream
-
- org.infinispan.io.ExpandableMarshalledValueByteStream
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,org.jboss.marshalling.ByteOutput
public final class ExpandableMarshalledValueByteStream extends MarshalledValueByteStream
A byte stream that can be written to and expanded on the fly, not dissimilar toExposedByteArrayOutputStreambut with the benefit of not having to allocate unnecessary byte arrays by not extendingByteArrayOutputStream.- Since:
- 5.1
- Author:
- Manik Surtani
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_DOUBLING_SIZEDefault buffer size after which if more buffer capacity is needed the buffer will grow by 25% rather than 100%
-
Constructor Summary
Constructors Constructor Description ExpandableMarshalledValueByteStream()ExpandableMarshalledValueByteStream(int size)ExpandableMarshalledValueByteStream(int size, int maxDoublingSize)Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object thatObject)intgetMaxDoublingSize()Gets the highest internal buffer size after which if more capacity is needed the buffer will grow in 25% increments rather than 100%.intgetNewBufferSize(int curSize, int minNewSize)Gets the number of bytes to which the internal buffer should be resized.byte[]getRaw()Gets the internal buffer array.inthashCode()intsize()Overriden only to avoid unneeded synchronizationvoidwrite(byte[] b, int off, int len)voidwrite(int b)-
Methods inherited from class java.io.OutputStream
close, flush, nullOutputStream, write
-
-
-
-
Field Detail
-
DEFAULT_DOUBLING_SIZE
public static final int DEFAULT_DOUBLING_SIZE
Default buffer size after which if more buffer capacity is needed the buffer will grow by 25% rather than 100%- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ExpandableMarshalledValueByteStream
public ExpandableMarshalledValueByteStream()
-
ExpandableMarshalledValueByteStream
public ExpandableMarshalledValueByteStream(int size)
-
ExpandableMarshalledValueByteStream
public ExpandableMarshalledValueByteStream(int size, int maxDoublingSize)Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes.- Parameters:
size- the initial size.maxDoublingSize- the buffer size, after which if more capacity is needed the buffer will grow by 25% rather than 100%- Throws:
IllegalArgumentException- if size is negative.
-
-
Method Detail
-
getRaw
public final byte[] getRaw()
Gets the internal buffer array. Note that the length of this array will almost certainly be longer than the data written to it; callsize()to get the number of bytes of actual data.- Specified by:
getRawin classMarshalledValueByteStream
-
write
public final void write(byte[] b, int off, int len)- Specified by:
writein interfaceorg.jboss.marshalling.ByteOutput- Overrides:
writein classOutputStream
-
write
public final void write(int b)
- Specified by:
writein interfaceorg.jboss.marshalling.ByteOutput- Specified by:
writein classOutputStream
-
getMaxDoublingSize
public final int getMaxDoublingSize()
Gets the highest internal buffer size after which if more capacity is needed the buffer will grow in 25% increments rather than 100%.
-
getNewBufferSize
public final int getNewBufferSize(int curSize, int minNewSize)Gets the number of bytes to which the internal buffer should be resized.- Parameters:
curSize- the current number of bytesminNewSize- the minimum number of bytes required- Returns:
- the size to which the internal buffer should be resized
-
size
public final int size()
Overriden only to avoid unneeded synchronization- Specified by:
sizein classMarshalledValueByteStream
-
-