Class LazilyConcatenatedByteArray


  • public class LazilyConcatenatedByteArray
    extends java.lang.Object
    Utility for delaying the concatenation of multiple byte arrays. Doing this up-front causes significantly more copying, which for a large number of byte arrays can cost a large amount of time.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clears the array (sets the concatenated length back to zero.
      void concatenate​(byte[] array)
      Concatenates an array onto the end of our array.
      byte[] toArray()
      Gets the concatenated contents as a single byte array.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LazilyConcatenatedByteArray

        public LazilyConcatenatedByteArray()
    • Method Detail

      • clear

        public void clear()
        Clears the array (sets the concatenated length back to zero.
      • concatenate

        public void concatenate​(byte[] array)
        Concatenates an array onto the end of our array. This is a relatively fast operation.
        Parameters:
        array - the array to concatenate.
        Throws:
        java.lang.IllegalArgumentException - if array is null.
      • toArray

        public byte[] toArray()
        Gets the concatenated contents as a single byte array. This is a slower operation, but the concatenated array is stored off as a single array again so that subsequent calls will not perform additional copying.
        Returns:
        the byte array. Returns null if no data has been placed into it.