Package org.epics.archiverappliance
Class ByteArray
java.lang.Object
org.epics.archiverappliance.ByteArray
A version of byte[] that is used to provide some optimization for data retrieval and the like.
This is very similar to NIO's ByteBuffer but has all its internal's exposed and is meant to pass a byte[]+offset+length around within the appliance archiver.
Many event streams reuse the same ByteArray across events in order to minimize memory allocation costs.
And as we reuse ByteArray instances so we have a reset method.
The convention for ByteArrays within Events is that they stored the escaped bytes (@see LineEscaper) and the inPlaceUnescape method is used to unescape these bytes.
For example, in summary, the PB code will
ByteArray bar = new ByteArray();
LineByteStream lbs = new LineByteStream(path...);
lbs.readLine(bar);
while(!bar.isEmpty()) {
SomeType.newBuilder().mergeFrom(bar.inPlaceUnescape().unescapedData, bar.off, bar.unescapedLen).build();
lbs.readLine(bar);
}
The readLine logic in lbs has the code necessary to increase the length of the data field as required.
Because many event streams reuse the same ByteArray across events, life becomes interesting as we need to remember to use makeClone anytime we want to span the Event across the iterator that generated it.
Spoke with Luofeng about this and we both came to the conclusion that we should try to make this work as much as possible as the GC gains itself are quite a bit.- Author:
- mshankar
-
Field Summary
FieldsModifier and TypeFieldDescriptionbyte[]intintbyte[]int -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
data
public byte[] data -
off
public int off -
len
public int len -
unescapedData
public byte[] unescapedData -
unescapedLen
public int unescapedLen
-
-
Constructor Details
-
ByteArray
public ByteArray(int size) -
ByteArray
public ByteArray(byte[] src)
-
-
Method Details
-
reset
public void reset() -
toBytes
public byte[] toBytes()Use this for unit tests and the like...- Returns:
- See Also:
-
unescapedBytes
public byte[] unescapedBytes() -
doubleBufferSize
Increases the size of the array to twice what it is currently subject to a maximum- Throws:
LineTooLongException-
-
isEmpty
public boolean isEmpty() -
inPlaceUnescape
-