Class BoundedSequenceDecorator

java.lang.Object
org.refcodes.serial.BoundedSequenceDecorator
All Implemented Interfaces:
Iterable<Byte>, org.refcodes.mixin.Clearable, org.refcodes.mixin.InputStreamAccessor, org.refcodes.mixin.LengthAccessor, org.refcodes.mixin.LengthAccessor.LengthMutator, org.refcodes.mixin.LengthAccessor.LengthProperty, org.refcodes.mixin.OutputStreamAccessor, Sequence

public class BoundedSequenceDecorator extends Object implements Sequence, org.refcodes.mixin.LengthAccessor.LengthProperty
The BoundedSequenceDecorator decorates a Sequence whilst bounding its size to a given maximum size (to be set via setLength(int)) . In case the underlying Sequence is smaller than the bounded size, then the BoundedSequenceDecorator will "bound" to the smaller decorated Sequence's size. If the underlying Sequence is greater than the bounded size, then the size if the underlying Sequence appears through this decorator smaller, although it by itself remains at its larger size. This functionality is useful when allocating a buffer which by usages of the decorator appears smaller without the need to copy the original sequence (thereby wasting bytes to be taken care of by the garbage collector). ATTENTION: Currently just the basic methods as well as the one required by the SequenceSection are implemented, unimplemented methods throw an UnsupportedOperationException exception. For manipulating a Sequence with more complex operations, use the underlying (decorated) Sequence.
  • Constructor Details

    • BoundedSequenceDecorator

      public BoundedSequenceDecorator(Sequence aSequence, int aLengthBounds)
      Decorates the given Sequence with a bounded maximum size.
      Parameters:
      aSequence - The Sequence to be decorated.
      aLengthBounds - The maximum size to bound this Sequence to. If the length if the provided Sequence is smaller, than the smaller size represents the bounds. A value of -1 disables any length bounds.
    • BoundedSequenceDecorator

      public BoundedSequenceDecorator(Sequence aSequence)
      Decorates the given Sequence with a bounded maximum size, as soon as a bounded size greater than -1 is provided via setLength(int).
      Parameters:
      aSequence - The Sequence to be decorated.
  • Method Details

    • getLength

      public int getLength()
      A value of -1 indicates that the length bounds are disabled.
      Specified by:
      getLength in interface org.refcodes.mixin.LengthAccessor
    • setLength

      public void setLength(int aLength)
      A value of -1 disables any length bounds.
      Specified by:
      setLength in interface org.refcodes.mixin.LengthAccessor.LengthMutator
    • iterator

      public Iterator<Byte> iterator()
      Specified by:
      iterator in interface Iterable<Byte>
    • forEach

      public void forEach(Consumer<? super Byte> aAction)
      Specified by:
      forEach in interface Iterable<Byte>
    • append

      public void append(byte... aBytes)
      Appends the given bytes to the end of this Sequence. Beware: This Sequence is modified! If you do not wish to modify this Sequence, please use Sequence.toAppend(byte...).
      Specified by:
      append in interface Sequence
      Parameters:
      aBytes - The bytes to be appended.
    • append

      public void append(byte[] aBytes, int aOffset, int aLength)
      Appends the given bytes to the end of this Sequence. Beware: This Sequence is modified! If you do not wish to modify this Sequence, please use Sequence.toAppend(byte[], int, int).
      Specified by:
      append in interface Sequence
      Parameters:
      aBytes - The bytes to be appended.
      aOffset - The offset from where to start collecting the bytes.
      aLength - The number of bytes to be appended.
    • spliterator

      public Spliterator<Byte> spliterator()
      Specified by:
      spliterator in interface Iterable<Byte>
    • append

      public void append(Sequence aSequence)
      Appends the given Sequence to the end of this Sequence. Beware: This Sequence is modified! If you do not wish to modify this Sequence, please use Sequence.toAppend(Sequence).
      Specified by:
      append in interface Sequence
      Parameters:
      aSequence - The Sequence to be appended.
    • clear

      public void clear()
      Sets all bytes in the Sequence to zero.
      Specified by:
      clear in interface org.refcodes.mixin.Clearable
      Specified by:
      clear in interface Sequence
    • clear

      public void clear(byte aValue)
      Sets all bytes in the Sequence to the provided value.
      Specified by:
      clear in interface Sequence
      Parameters:
      aValue - The value with which to zero out this Sequence.
    • concatenate

      public void concatenate(org.refcodes.mixin.ConcatenateMode aConcatenateMode, byte... aBytes)
      Concatenates the given bytes with this Sequence according to the provided ConcatenateMode . Beware: This Sequence is modified! If you do not wish to modify this Sequence, please use Sequence.toConcatenate(ConcatenateMode, byte...).
      Specified by:
      concatenate in interface Sequence
      Parameters:
      aConcatenateMode - The concatenation mode to be used.
      aBytes - The bytes to be concatenated with.
    • concatenate

      public void concatenate(org.refcodes.mixin.ConcatenateMode aConcatenateMode, byte[] aBytes, int aOffset, int aLength)
      Concatenates the given bytes with this Sequence according to the provided ConcatenateMode . Beware: This Sequence is modified! If you do not wish to modify this Sequence, please use Sequence.toConcatenate(ConcatenateMode, byte[], int, int).
      Specified by:
      concatenate in interface Sequence
      Parameters:
      aConcatenateMode - The concatenation mode to be used.
      aBytes - The bytes to be concatenated with.
      aOffset - The offset from where to start collecting the bytes.
      aLength - The number of bytes to be concatenated.
    • concatenate

      public void concatenate(Sequence aSequence, org.refcodes.mixin.ConcatenateMode aConcatenateMode)
      Concatenates the given Sequence with this Sequence according to the provided ConcatenateMode . Beware: This Sequence is modified! If you do not wish to modify this Sequence, please use Sequence.toConcatenate(Sequence, ConcatenateMode).
      Specified by:
      concatenate in interface Sequence
      Parameters:
      aSequence - The Sequence to be concatenated with.
      aConcatenateMode - The concatenation mode to be used.
    • empty

      public void empty()
      Empties the Sequence to end up being of length 0.
      Specified by:
      empty in interface Sequence
    • getByteAt

      public byte getByteAt(int aIndex) throws IndexOutOfBoundsException
      Returns the byte at the given index in the Sequence.
      Specified by:
      getByteAt in interface Sequence
      Parameters:
      aIndex - The index of the byte to retrieve.
      Returns:
      The byte being retrieved.
      Throws:
      IndexOutOfBoundsException - thrown in case the given index is out of bounds.
    • getInputStream

      public InputStream getInputStream()
      Creates an InputStream backed by this Sequence.
      Specified by:
      getInputStream in interface org.refcodes.mixin.InputStreamAccessor
      Specified by:
      getInputStream in interface Sequence
    • getOutputStream

      public OutputStream getOutputStream()
      Creates an OutputStream backed by this Sequence.
      Specified by:
      getOutputStream in interface org.refcodes.mixin.OutputStreamAccessor
      Specified by:
      getOutputStream in interface Sequence
    • overwrite

      public void overwrite(byte[] aBytes)
      Writes the given bytes into this Sequence. If the Sequence is too small for the bytes to fit into, then the Sequence is extended accordingly.
      Specified by:
      overwrite in interface Sequence
      Parameters:
      aBytes - The byte array where to copy the bytes from.
    • overwrite

      public void overwrite(byte[] aBytes, int aLength)
      Writes the given bytes into this Sequence. If the Sequence is too small for the bytes to fit into, then the Sequence is extended accordingly.
      Specified by:
      overwrite in interface Sequence
      Parameters:
      aBytes - The byte array where to copy the bytes from.
      aLength - The number of bytes to be copied starting at offset 0.
    • overwrite

      public void overwrite(int aOffset, byte[] aBytes)
      Writes the given bytes into this Sequence. If the Sequence is too small for the bytes to fit into, then the Sequence is extended accordingly.
      Specified by:
      overwrite in interface Sequence
      Parameters:
      aOffset - The offset where to start writing the bytes to.
      aBytes - The byte array where to copy the bytes from.
    • overwrite

      public void overwrite(int aOffset, byte[] aBytes, int aBytesOffset, int aLength)
      Writes the given bytes into this Sequence. If the Sequence is too small for the bytes to fit into, then the Sequence is extended accordingly.
      Specified by:
      overwrite in interface Sequence
      Parameters:
      aOffset - The offset where to start writing the bytes to.
      aBytes - The byte array where to copy the bytes from.
      aBytesOffset - The offset in the byte array where to start copying.
      aLength - The number of bytes to be copied.
    • overwrite

      public void overwrite(int aOffset, Sequence aSequence)
      Writes the given Sequence into this Sequence. If the Sequence is too small for the given Sequence's bytes to fit into, then this Sequence is extended accordingly.
      Specified by:
      overwrite in interface Sequence
      Parameters:
      aOffset - The offset where to start writing the given Sequence's bytes to.
      aSequence - The given Sequence where to copy the bytes from.
    • overwrite

      public void overwrite(int aOffset, Sequence aSequence, int aSequenceOffset, int aLength)
      Writes the given bytes into this Sequence. If the Sequence is too small for the bytes to fit into, then the Sequence is extended accordingly.
      Specified by:
      overwrite in interface Sequence
      Parameters:
      aOffset - The offset where to start writing the bytes to.
      aSequence - The given Sequence where to copy the bytes from.
      aSequenceOffset - The offset in the byte array where to start copying.
      aLength - The number of bytes to be copied.
    • overwrite

      public void overwrite(Sequence aSequence)
      Writes the given Sequence into this Sequence. If the Sequence is too small for the given Sequence's bytes to fit into, then this Sequence is extended accordingly.
      Specified by:
      overwrite in interface Sequence
      Parameters:
      aSequence - The given Sequence where to copy the bytes from.
    • overwrite

      public void overwrite(Sequence aSequence, int aLength)
      Writes the given bytes into this Sequence. If the Sequence is too small for the bytes to fit into, then the Sequence is extended accordingly.
      Specified by:
      overwrite in interface Sequence
      Parameters:
      aSequence - The Sequence where to copy the bytes from.
      aLength - The number of bytes to be copied starting at offset 0.
    • prepend

      public void prepend(byte... aBytes)
      Prepends the given bytes the beginning of this Sequence. Beware: This Sequence is modified! If you do not wish to modify this Sequence, please use Sequence.toPrepend(byte...).
      Specified by:
      prepend in interface Sequence
      Parameters:
      aBytes - The bytes to be prepended.
    • prepend

      public void prepend(byte[] aBytes, int aOffset, int aLength)
      Prepends the given bytes to the beginning of this Sequence. Beware: This Sequence is modified! If you do not wish to modify this Sequence, please use Sequence.toPrepend(byte[], int, int).
      Specified by:
      prepend in interface Sequence
      Parameters:
      aBytes - The bytes to be prepended.
      aOffset - The offset from where to start collecting the bytes.
      aLength - The number of bytes to be prepended.
    • prepend

      public void prepend(Sequence aSequence)
      Prepends the given Sequence to the beginning of this Sequence. Beware: This Sequence is modified! If you do not wish to modify this Sequence, please use Sequence.toPrepend(Sequence).
      Specified by:
      prepend in interface Sequence
      Parameters:
      aSequence - The Sequence to be prepended.
    • replace

      public void replace(byte[] aBytes)
      Replaces the given bytes with this byte array.
      Specified by:
      replace in interface Sequence
      Parameters:
      aBytes - The byte array where to copy the bytes from.
    • replace

      public void replace(byte[] aBytes, int aLength)
      Replaces the given bytes with this byte array.
      Specified by:
      replace in interface Sequence
      Parameters:
      aBytes - The byte array where to copy the bytes from.
      aLength - The number of bytes to be copied starting with offset 0.
    • replace

      public void replace(byte[] aBytes, int aOffset, int aLength)
      Replaces the given bytes with this byte array.
      Specified by:
      replace in interface Sequence
      Parameters:
      aBytes - The byte array where to copy the bytes from.
      aOffset - The offset in the byte array where to start copying.
      aLength - The number of bytes to be copied.
    • replace

      public void replace(Sequence aSequence)
      Replaces the given Sequence into this Sequence.
      Specified by:
      replace in interface Sequence
      Parameters:
      aSequence - The given Sequence where to copy the bytes from.
    • replace

      public void replace(Sequence aSequence, int aLength)
      Replaces the given bytes with this Sequence.
      Specified by:
      replace in interface Sequence
      Parameters:
      aSequence - The given Sequence where to copy the bytes from.
      aLength - The number of bytes to be copied starting with offset 0.
    • replace

      public void replace(Sequence aSequence, int aOffset, int aLength)
      Replaces the given bytes with this Sequence.
      Specified by:
      replace in interface Sequence
      Parameters:
      aSequence - The given Sequence where to copy the bytes from.
      aOffset - The offset in the byte array where to start copying.
      aLength - The number of bytes to be copied.
    • setByteAt

      public void setByteAt(int aIndex, byte aByte)
      Sets the byte at the given index in the Sequence.
      Specified by:
      setByteAt in interface Sequence
      Parameters:
      aIndex - The index of the byte to set.
      aByte - The byte to set at the given index.
    • toAppend

      public Sequence toAppend(byte... aBytes)
      Appends the given bytes to the end of this Sequence. This Sequence is not modified and a new Sequence is returned.
      Specified by:
      toAppend in interface Sequence
      Parameters:
      aBytes - The bytes to be appended.
      Returns:
      The according Sequence.
    • toAppend

      public Sequence toAppend(byte[] aBytes, int aOffset, int aLength)
      Appends the given bytes to the end of this Sequence. This Sequence is not modified and a new Sequence is returned.
      Specified by:
      toAppend in interface Sequence
      Parameters:
      aBytes - The bytes to be appended.
      aOffset - The offset from where to start collecting the bytes.
      aLength - The number of bytes to be appended.
      Returns:
      The according Sequence.
    • toAppend

      public Sequence toAppend(Sequence aSequence)
      Appends the given Sequence to the end of this Sequence. This Sequence is not modified and a new Sequence is returned.
      Specified by:
      toAppend in interface Sequence
      Parameters:
      aSequence - The Sequence to be appended.
      Returns:
      The according Sequence.
    • toBytes

      public byte[] toBytes()
      Retrieves a continuous array of bytes from the Sequence.
      Specified by:
      toBytes in interface Sequence
      Returns:
      The according byte array.
    • toBytes

      public byte[] toBytes(int aOffset, int aLength)
      Retrieves a continuous array of bytes from the Sequence, starting with the byte at the given offset and containing the given number of bytes.
      Specified by:
      toBytes in interface Sequence
      Parameters:
      aOffset - The offset from where to start collecting the bytes.
      aLength - The length of the byte array to be returned.
      Returns:
      The according bytes.
    • toBytes

      public void toBytes(int aOffset, int aLength, byte[] aBytes, int aBytesOffset)
      Retrieves a continuous array of bytes from the Sequence, starting with the byte at the given offset and containing the given number of bytes. The bytes are stored in the provided bytes starting at the given bytes' offset.
      Specified by:
      toBytes in interface Sequence
      Parameters:
      aOffset - The offset from where to start collecting the bytes.
      aLength - The number of bytes to be copied.
      aBytes - The byte array where to copy the bytes to.
      aBytesOffset - The offset in the byte array where to start copying.
    • toClone

      public Sequence toClone()
      Creates a deep clone of this Sequence.
      Specified by:
      toClone in interface Sequence
      Returns:
      The deep clone.
    • toConcatenate

      public Sequence toConcatenate(org.refcodes.mixin.ConcatenateMode aConcatenateMode, byte... aBytes)
      Concatenates the given bytes with this Sequence according to the provided ConcatenateMode. This Sequence is not modified and a new Sequence is returned.
      Specified by:
      toConcatenate in interface Sequence
      Parameters:
      aConcatenateMode - The concatenation mode to be used.
      aBytes - The bytes to be concatenated with.
      Returns:
      The according Sequence.
    • toConcatenate

      public Sequence toConcatenate(org.refcodes.mixin.ConcatenateMode aConcatenateMode, byte[] aBytes, int aOffset, int aLength)
      Concatenates the given bytes with this Sequence according to the provided ConcatenateMode. This Sequence is not modified and a new Sequence is returned.
      Specified by:
      toConcatenate in interface Sequence
      Parameters:
      aConcatenateMode - The concatenation mode to be used.
      aBytes - The bytes to be concatenated.
      aOffset - The offset from where to start collecting the bytes.
      aLength - The number of bytes to be concatenated with.
      Returns:
      The according Sequence.
    • toConcatenate

      public Sequence toConcatenate(Sequence aSequence, org.refcodes.mixin.ConcatenateMode aConcatenateMode)
      Concatenates the given Sequence with this Sequence according to the provided ConcatenateMode. This Sequence is not modified and a new Sequence is returned.
      Specified by:
      toConcatenate in interface Sequence
      Parameters:
      aSequence - The Sequence to be concatenated with.
      aConcatenateMode - The concatenation mode to be used.
      Returns:
      The according Sequence.
    • toCrcBytes

      public byte[] toCrcBytes(org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm, org.refcodes.numerical.Endianess aEndianess)
      Calculates the CRC checksum as byte array for this Sequence.
      Specified by:
      toCrcBytes in interface Sequence
      Parameters:
      aCrcAlgorithm - The CrcAlgorithm to be used when calculating the CRC checksum.
      aEndianess - The Endianess (little endian or big endian) to be used for the byte array representation of the CRC checksum.
      Returns:
      The CRC checksum of the Sequence.
    • toCrcBytes

      public byte[] toCrcBytes(long aCrcChecksum, org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm, org.refcodes.numerical.Endianess aEndianess)
      Calculates the CRC checksum as byte array for this Sequence.
      Specified by:
      toCrcBytes in interface Sequence
      Parameters:
      aCrcChecksum - The CRC checksum from which to continue calculating the checksum,
      aCrcAlgorithm - The CrcAlgorithm to be used when calculating the CRC checksum.
      aEndianess - The Endianess (little endian or big endian) to be used for the byte array representation of the CRC checksum.
      Returns:
      The CRC checksum of the Sequence.
    • toCrcChecksum

      public long toCrcChecksum(org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm)
      Calculates the CRC checksum for this Sequence.
      Specified by:
      toCrcChecksum in interface Sequence
      Parameters:
      aCrcAlgorithm - The CrcAlgorithm to be used when calculating the CRC checksum.
      Returns:
      The CRC checksum of the Sequence.
    • toCrcChecksum

      public long toCrcChecksum(long aCrcChecksum, org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm)
      Calculates the CRC checksum for this Sequence.
      Specified by:
      toCrcChecksum in interface Sequence
      Parameters:
      aCrcChecksum - The CRC checksum from which to continue calculating the checksum,
      aCrcAlgorithm - The CrcAlgorithm to be used when calculating the CRC checksum.
      Returns:
      The CRC checksum of the Sequence.
    • toInputStream

      public InputStream toInputStream()
      Creates an InputStream form this Sequence without being backed by this Sequence, e.g. reading from the returned InputStream does not affect this Sequence (in contrast to the InputStream returned by the method Sequence.getInputStream()).
      Specified by:
      toInputStream in interface Sequence
      Returns:
      The according InputStream not affecting this Sequence.
    • toOverwrite

      public Sequence toOverwrite(byte[] aBytes)
      Writes the given bytes into a copy of this Sequence. If the Sequence is too small for the bytes to fit into, then the Sequence is extended accordingly.
      Specified by:
      toOverwrite in interface Sequence
      Parameters:
      aBytes - The byte array where to copy the bytes from.
      Returns:
      The according Sequence.
    • toOverwrite

      public Sequence toOverwrite(byte[] aBytes, int aLength)
      Writes the given bytes into a copy of this Sequence. If the Sequence is too small for the bytes to fit into, then the Sequence is extended accordingly.
      Specified by:
      toOverwrite in interface Sequence
      Parameters:
      aBytes - The byte array where to copy the bytes from.
      aLength - The number of bytes to be copied starting with offset 0.
      Returns:
      The according Sequence.
    • toOverwrite

      public Sequence toOverwrite(int aOffset, byte[] aBytes)
      Writes the given bytes into a copy of this Sequence. If the Sequence is too small for the bytes to fit into, then the Sequence is extended accordingly.
      Specified by:
      toOverwrite in interface Sequence
      Parameters:
      aOffset - The offset where to start writing the bytes to.
      aBytes - The byte array where to copy the bytes from.
      Returns:
      The according Sequence.
    • toOverwrite

      public Sequence toOverwrite(int aOffset, byte[] aBytes, int aBytesOffset, int aLength)
      Writes the given bytes into a copy of this Sequence. If the Sequence is too small for the bytes to fit into, then the Sequence is extended accordingly.
      Specified by:
      toOverwrite in interface Sequence
      Parameters:
      aOffset - The offset where to start writing the bytes to.
      aBytes - The byte array where to copy the bytes from.
      aBytesOffset - The offset in the byte array where to start copying.
      aLength - The number of bytes to be copied.
      Returns:
      The according Sequence.
    • toOverwrite

      public Sequence toOverwrite(int aOffset, Sequence aSequence)
      Writes the given bytes into a copy of this Sequence. If the Sequence is too small for the bytes to fit into, then the Sequence is extended accordingly.
      Specified by:
      toOverwrite in interface Sequence
      Parameters:
      aOffset - The offset where to start writing the bytes to.
      aSequence - The Sequence where to copy the bytes from.
      Returns:
      The according Sequence.
    • toOverwrite

      public Sequence toOverwrite(int aOffset, Sequence aSequence, int aBytesOffset, int aLength)
      Writes the given Sequence into a copy of this Sequence. If the Sequence is too small for the bytes to fit into, then the Sequence is extended accordingly.
      Specified by:
      toOverwrite in interface Sequence
      Parameters:
      aOffset - The offset where to start writing the bytes to.
      aSequence - The Sequence where to copy the bytes from.
      aBytesOffset - The offset in the Sequence where to start copying.
      aLength - The number of bytes to be copied.
      Returns:
      The according Sequence.
    • toOverwrite

      public Sequence toOverwrite(Sequence aSequence)
      Writes the given bytes into a copy of this Sequence. If the Sequence is too small for the bytes to fit into, then the Sequence is extended accordingly.
      Specified by:
      toOverwrite in interface Sequence
      Parameters:
      aSequence - The Sequence where to copy the bytes from.
      Returns:
      The according Sequence.
    • toOverwrite

      public Sequence toOverwrite(Sequence aSequence, int aLength)
      Writes the given bytes into a copy of this Sequence. If the Sequence is too small for the bytes to fit into, then the Sequence is extended accordingly.
      Specified by:
      toOverwrite in interface Sequence
      Parameters:
      aSequence - The Sequence where to copy the bytes from.
      aLength - The number of bytes to be copied starting with offset 0.
      Returns:
      The according Sequence.
    • toPrepend

      public Sequence toPrepend(byte... aBytes)
      Prepends the given bytes to the beginning of this Sequence. This Sequence is not modified and a new Sequence is returned.
      Specified by:
      toPrepend in interface Sequence
      Parameters:
      aBytes - The bytes to be prepended.
      Returns:
      The according Sequence.
    • toPrepend

      public Sequence toPrepend(byte[] aBytes, int aOffset, int aLength)
      Prepends the given bytes to the beginning of this Sequence. This Sequence is not modified and a new Sequence is returned.
      Specified by:
      toPrepend in interface Sequence
      Parameters:
      aBytes - The bytes to be prepended.
      aOffset - The offset from where to start collecting the bytes.
      aLength - The number of bytes to be prepended.
      Returns:
      The according Sequence.
    • toPrepend

      public Sequence toPrepend(Sequence aSequence)
      Prepends the given Sequence to the beginning of this Sequence. This Sequence is not modified and a new Sequence is returned.
      Specified by:
      toPrepend in interface Sequence
      Parameters:
      aSequence - The Sequence to be prepended.
      Returns:
      The according Sequence.
    • toSequence

      public Sequence toSequence(int aOffset, int aLength)
      Retrieves a new Sequence from this Sequence, starting with the byte at the given offset and containing the given number of bytes.
      Specified by:
      toSequence in interface Sequence
      Parameters:
      aOffset - The offset from where to start collecting the bytes.
      aLength - The length of the byte array to be returned.
      Returns:
      The according TransmissionSequenceException.
    • toTruncate

      public Sequence toTruncate(int aLength, org.refcodes.mixin.TruncateMode aTruncateMode)
      Returns a new Sequence truncated by the given number of bytes from the right or from the left of both, according to the given TruncateMode. If the number of bytes exceeds the actual length of the Sequence, then the Sequence will end up being empty.
      Specified by:
      toTruncate in interface Sequence
      Parameters:
      aLength - The number of bytes to truncate according to the TruncateMode.
      aTruncateMode - The TruncateMode to use for truncating the Sequence.
      Returns:
      The newly created truncated Sequence.
    • toTruncateHead

      public Sequence toTruncateHead(int aLength)
      Returns a new Sequence truncated by the given number of bytes from the left. If the number of bytes exceeds the actual length of the Sequence, then the new Sequence will end up being empty.
      Specified by:
      toTruncateHead in interface Sequence
      Parameters:
      aLength - The number of bytes to truncate from the left.
      Returns:
      The newly created truncated Sequence.
    • toTruncateTail

      public Sequence toTruncateTail(int aLength)
      Returns a new Sequence truncated by the given number of bytes from the right. If the number of bytes exceeds the actual length of the Sequence, then the new Sequence will end up being empty.
      Specified by:
      toTruncateTail in interface Sequence
      Parameters:
      aLength - The number of bytes to truncate from the right.
      Returns:
      The newly created truncated Sequence.
    • truncate

      public void truncate(int aLength, org.refcodes.mixin.TruncateMode aTruncateMode)
      Truncates the Sequence by the given number of bytes from the right or from the left of both, according to the given TruncateMode. If the number of bytes exceeds the actual length of the Sequence, then the Sequence will end up being empty.
      Specified by:
      truncate in interface Sequence
      Parameters:
      aLength - The number of bytes to truncate according to the TruncateMode.
      aTruncateMode - The TruncateMode to use for truncating the Sequence.
    • truncateHead

      public void truncateHead(int aLength)
      Truncates the Sequence by the given number of bytes from the left. If the number of bytes exceeds the actual length of the Sequence, then the Sequence will end up being empty.
      Specified by:
      truncateHead in interface Sequence
      Parameters:
      aLength - The number of bytes to truncate from the left.
    • truncateTail

      public void truncateTail(int aLength)
      Truncates the Sequence by the given number of bytes from the right. If the number of bytes exceeds the actual length of the Sequence, then the Sequence will end up being empty.
      Specified by:
      truncateTail in interface Sequence
      Parameters:
      aLength - The number of bytes to truncate from the right.
    • withAppend

      public Sequence withAppend(byte... aBytes)
      Builder method for the Sequence.append(byte...) method.
      Specified by:
      withAppend in interface Sequence
      Parameters:
      aBytes - The bytes to be appended.
      Returns:
      This instance as of the builder pattern.
    • withAppend

      public Sequence withAppend(byte[] aBytes, int aOffset, int aLength)
      Builder method for the Sequence.append(byte...) method.
      Specified by:
      withAppend in interface Sequence
      Parameters:
      aBytes - The bytes to be appended.
      aOffset - The offset from where to start collecting the bytes.
      aLength - The number of bytes to be appended.
      Returns:
      This instance as of the builder pattern.
    • withAppend

      public Sequence withAppend(Sequence aSequence)
      Builder method for the Sequence.append(Sequence) method.
      Specified by:
      withAppend in interface Sequence
      Parameters:
      aSequence - The Sequence to be appended.
      Returns:
      This instance as of the builder pattern.
    • withConcatenate

      public Sequence withConcatenate(org.refcodes.mixin.ConcatenateMode aConcatenateMode, byte... aBytes)
      Builder method for the Sequence.concatenate(ConcatenateMode, byte...) method.
      Specified by:
      withConcatenate in interface Sequence
      Parameters:
      aConcatenateMode - The concatenation mode to be used.
      aBytes - The bytes to be concatenated with.
      Returns:
      This instance as of the builder pattern.
    • withConcatenate

      public Sequence withConcatenate(Sequence aSequence, org.refcodes.mixin.ConcatenateMode aConcatenateMode)
      Specified by:
      withConcatenate in interface Sequence
      Parameters:
      aSequence - The Sequence to be concatenated with
      aConcatenateMode - The concatenation mode to be used.
      Returns:
      This instance as of the builder pattern.
    • withOverwrite

      public Sequence withOverwrite(byte[] aBytes)
      Builder method for the Sequence.overwrite(byte[]) method.
      Specified by:
      withOverwrite in interface Sequence
      Parameters:
      aBytes - The byte array where to copy the bytes from.
      Returns:
      This instance as of the builder pattern.
    • withOverwrite

      public Sequence withOverwrite(byte[] aBytes, int aLength)
      Builder method for the Sequence.overwrite(Sequence, int) method.
      Specified by:
      withOverwrite in interface Sequence
      Parameters:
      aBytes - The bytes where to copy the bytes from.
      aLength - The number of bytes to be copied starting at offset 0.
      Returns:
      This instance as of the builder pattern.
    • withOverwrite

      public Sequence withOverwrite(int aOffset, byte[] aBytes)
      Builder method for the Sequence.overwrite(int, byte[]) method.
      Specified by:
      withOverwrite in interface Sequence
      Parameters:
      aOffset - The offset where to start writing the bytes to.
      aBytes - The byte array where to copy the bytes from.
      Returns:
      This instance as of the builder pattern.
    • withOverwrite

      public Sequence withOverwrite(int aOffset, byte[] aBytes, int aBytesOffset, int aLength)
      Builder method for the Sequence.overwrite(int, byte[], int, int) method.
      Specified by:
      withOverwrite in interface Sequence
      Parameters:
      aOffset - The offset where to start writing the bytes to.
      aBytes - The byte array where to copy the bytes from.
      aBytesOffset - The offset in the byte array where to start copying.
      aLength - The number of bytes to be copied.
      Returns:
      This instance as of the builder pattern.
    • withOverwrite

      public Sequence withOverwrite(int aOffset, Sequence aSequence)
      Builder method for the Sequence.overwrite(int, Sequence) method.
      Specified by:
      withOverwrite in interface Sequence
      Parameters:
      aOffset - The offset where to start writing the bytes to.
      aSequence - The Sequence where to copy the bytes from.
      Returns:
      This instance as of the builder pattern.
    • withOverwrite

      public Sequence withOverwrite(int aOffset, Sequence aSequence, int aSequenceOffset, int aLength)
      Builder method for the Sequence.overwrite(int, Sequence, int, int) method.
      Specified by:
      withOverwrite in interface Sequence
      Parameters:
      aOffset - The offset where to start writing the bytes to.
      aSequence - The Sequence where to copy the bytes from.
      aSequenceOffset - The offset in the byte array where to start copying.
      aLength - The number of bytes to be copied.
      Returns:
      This instance as of the builder pattern.
    • withOverwrite

      public Sequence withOverwrite(Sequence aSequence)
      Builder method for the Sequence.overwrite(Sequence) method.
      Specified by:
      withOverwrite in interface Sequence
      Parameters:
      aSequence - The Sequence where to copy the bytes from.
      Returns:
      This instance as of the builder pattern.
    • withOverwrite

      public Sequence withOverwrite(Sequence aSequence, int aLength)
      Builder method for the Sequence.overwrite(Sequence, int) method.
      Specified by:
      withOverwrite in interface Sequence
      Parameters:
      aSequence - The Sequence where to copy the bytes from.
      aLength - The number of bytes to be copied starting at offset 0.
      Returns:
      This instance as of the builder pattern.
    • withPrepend

      public Sequence withPrepend(byte... aBytes)
      Builder method for the Sequence.prepend(byte...) method.
      Specified by:
      withPrepend in interface Sequence
      Parameters:
      aBytes - The bytes to be prepended.
      Returns:
      This instance as of the builder pattern.
    • withPrepend

      public Sequence withPrepend(byte[] aBytes, int aOffset, int aLength)
      Builder method for the Sequence.prepend(byte...) method.
      Specified by:
      withPrepend in interface Sequence
      Parameters:
      aBytes - The bytes to be prepended.
      aOffset - The offset from where to start collecting the bytes.
      aLength - The number of bytes to be prepended.
      Returns:
      This instance as of the builder pattern.
    • withPrepend

      public Sequence withPrepend(Sequence aSequence)
      Builder method for the Sequence.prepend(Sequence) method.
      Specified by:
      withPrepend in interface Sequence
      Parameters:
      aSequence - The Sequence to be prepended.
      Returns:
      This instance as of the builder pattern.
    • withReplace

      public Sequence withReplace(byte[] aBytes)
      Builder method for the Sequence.replace(byte[]) method.
      Specified by:
      withReplace in interface Sequence
      Parameters:
      aBytes - The byte array where to copy the bytes from.
      Returns:
      This instance as of the builder pattern.
    • withReplace

      public Sequence withReplace(byte[] aBytes, int aLength)
      Builder method for the Sequence.replace(byte[], int, int) method.
      Specified by:
      withReplace in interface Sequence
      Parameters:
      aBytes - The byte array where to copy the bytes from.
      aLength - The number of bytes to be copied starting at offset 0.
      Returns:
      This instance as of the builder pattern.
    • withReplace

      public Sequence withReplace(Sequence aSequence, int aLength)
      Builder method for the Sequence.replace(Sequence, int, int) method.
      Specified by:
      withReplace in interface Sequence
      Parameters:
      aSequence - The byte Sequence where to copy the bytes from.
      aLength - The number of bytes to be copied starting at offset 0.
      Returns:
      This instance as of the builder pattern.
    • withReplace

      public Sequence withReplace(byte[] aBytes, int aOffset, int aLength)
      Builder method for the Sequence.replace(byte[], int, int) method.
      Specified by:
      withReplace in interface Sequence
      Parameters:
      aBytes - The byte array where to copy the bytes from.
      aOffset - The offset in the byte array where to start copying.
      aLength - The number of bytes to be copied.
      Returns:
      This instance as of the builder pattern.
    • withReplace

      public Sequence withReplace(Sequence aSequence)
      Builder method for the Sequence.replace(Sequence) method.
      Specified by:
      withReplace in interface Sequence
      Parameters:
      aSequence - The Sequence where to copy the bytes from.
      Returns:
      This instance as of the builder pattern.
    • withReplace

      public Sequence withReplace(Sequence aSequence, int aOffset, int aLength)
      Builder method for the Sequence.replace(Sequence, int, int) method.
      Specified by:
      withReplace in interface Sequence
      Parameters:
      aSequence - The Sequence where to copy the bytes from.
      aOffset - The offset in the byte array where to start copying.
      aLength - The number of bytes to be copied.
      Returns:
      This instance as of the builder pattern.
    • withTruncate

      public Sequence withTruncate(int aLength, org.refcodes.mixin.TruncateMode aTruncateMode)
      Builder method for the Sequence.truncate(int, TruncateMode) method.
      Specified by:
      withTruncate in interface Sequence
      Parameters:
      aLength - The number of bytes to truncate according to the TruncateMode.
      aTruncateMode - The TruncateMode to use for truncating the Sequence.
      Returns:
      This instance as of the builder pattern.
    • withTruncateHead

      public Sequence withTruncateHead(int aLength)
      Builder method for the Sequence.truncateHead(int) method.
      Specified by:
      withTruncateHead in interface Sequence
      Parameters:
      aLength - The number of bytes to truncate.
      Returns:
      This instance as of the builder pattern.
    • withTruncateTail

      public Sequence withTruncateTail(int aLength)
      Builder method for the Sequence.truncateTail(int) method.
      Specified by:
      withTruncateTail in interface Sequence
      Parameters:
      aLength - The number of bytes to truncate.
      Returns:
      This instance as of the builder pattern.
    • writeTo

      public void writeTo(OutputStream aOutputStream) throws IOException
      Writes the content of the Sequence to the provided OutputStream.
      Specified by:
      writeTo in interface Sequence
      Parameters:
      aOutputStream - The OutputStream where to write to.
      Throws:
      IOException - thrown in case of I/O problems.