Class 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 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 Detail

      • data

        public byte[] data
      • off

        public int off
      • len

        public int len
      • unescapedData

        public byte[] unescapedData
      • unescapedLen

        public int unescapedLen
    • Constructor Detail

      • ByteArray

        public ByteArray​(int size)
      • ByteArray

        public ByteArray​(byte[] src)
    • 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()
      • isEmpty

        public boolean isEmpty()
      • inPlaceUnescape

        public ByteArray inPlaceUnescape()