Class LazilyConcatenatedByteArray


  • public class LazilyConcatenatedByteArray
    extends 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.
    • 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:
        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.