Package org.epics.archiverappliance
Class ByteArray
- java.lang.Object
-
- org.epics.archiverappliance.ByteArray
-
public class ByteArray extends Object
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 willByteArray 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
Fields Modifier and Type Field Description byte[]
data
int
len
int
off
byte[]
unescapedData
int
unescapedLen
-
Method Summary
Modifier and Type Method Description void
doubleBufferSize()
Increases the size of the array to twice what it is currently subject to a maximumByteArray
inPlaceUnescape()
boolean
isEmpty()
void
reset()
byte[]
toBytes()
Use this for unit tests and the like...byte[]
unescapedBytes()
-
-
-
Method Detail
-
reset
public void reset()
-
toBytes
public byte[] toBytes()
Use this for unit tests and the like...- Returns:
- See Also:
- System.arraycopy
-
unescapedBytes
public byte[] unescapedBytes()
-
doubleBufferSize
public void doubleBufferSize() throws LineTooLongException
Increases the size of the array to twice what it is currently subject to a maximum- Throws:
LineTooLongException
-
-
isEmpty
public boolean isEmpty()
-
inPlaceUnescape
public ByteArray inPlaceUnescape()
-
-