- 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
TheBoundedSequenceDecorator
decorates aSequence
whilst bounding its size to a given maximum size (to be set viasetLength(int)
) . In case the underlyingSequence
is smaller than the bounded size, then theBoundedSequenceDecorator
will "bound" to the smaller decoratedSequence
's size. If the underlying Sequence is greater than the bounded size, then the size if the underlyingSequence
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 theSequenceSection
are implemented, unimplemented methods throw anUnsupportedOperationException
exception. For manipulating aSequence
with more complex operations, use the underlying (decorated)Sequence
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.InputStreamAccessor
org.refcodes.mixin.InputStreamAccessor.InputStreamBuilder<B extends org.refcodes.mixin.InputStreamAccessor.InputStreamBuilder<?>>, org.refcodes.mixin.InputStreamAccessor.InputStreamMutator, org.refcodes.mixin.InputStreamAccessor.InputStreamProperty
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.LengthAccessor
org.refcodes.mixin.LengthAccessor.LengthBuilder<B extends org.refcodes.mixin.LengthAccessor.LengthBuilder<B>>, org.refcodes.mixin.LengthAccessor.LengthMutator, org.refcodes.mixin.LengthAccessor.LengthProperty
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.OutputStreamAccessor
org.refcodes.mixin.OutputStreamAccessor.OutputStreamBuilder<B extends org.refcodes.mixin.OutputStreamAccessor.OutputStreamBuilder<?>>, org.refcodes.mixin.OutputStreamAccessor.OutputStreamMutator, org.refcodes.mixin.OutputStreamAccessor.OutputStreamProperty
-
-
Constructor Summary
Constructors Constructor Description BoundedSequenceDecorator(Sequence aSequence)
Decorates the givenSequence
with a bounded maximum size, as soon as a bounded size greater than -1 is provided viasetLength(int)
.BoundedSequenceDecorator(Sequence aSequence, int aLengthBounds)
Decorates the givenSequence
with a bounded maximum size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
append(byte... aBytes)
Appends the given bytes to the end of thisSequence
.void
append(byte[] aBytes, int aOffset, int aLength)
Appends the given bytes to the end of thisSequence
.void
append(Sequence aSequence)
void
clear()
Sets all bytes in theSequence
to zero.void
clear(byte aValue)
Sets all bytes in theSequence
to the provided value.void
concatenate(org.refcodes.mixin.ConcatenateMode aConcatenateMode, byte... aBytes)
Concatenates the given bytes with thisSequence
according to the providedConcatenateMode
.void
concatenate(org.refcodes.mixin.ConcatenateMode aConcatenateMode, byte[] aBytes, int aOffset, int aLength)
Concatenates the given bytes with thisSequence
according to the providedConcatenateMode
.void
concatenate(Sequence aSequence, org.refcodes.mixin.ConcatenateMode aConcatenateMode)
void
empty()
Empties theSequence
to end up being of length 0.void
forEach(Consumer<? super Byte> aAction)
byte
getByteAt(int aIndex)
Returns the byte at the given index in theSequence
.InputStream
getInputStream()
Creates anInputStream
backed by thisSequence
.int
getLength()
A value of -1 indicates that the length bounds are disabled.OutputStream
getOutputStream()
Creates anOutputStream
backed by thisSequence
.Iterator<Byte>
iterator()
void
overwrite(byte[] aBytes)
Writes the given bytes into thisSequence
.void
overwrite(byte[] aBytes, int aLength)
Writes the given bytes into thisSequence
.void
overwrite(int aOffset, byte[] aBytes)
Writes the given bytes into thisSequence
.void
overwrite(int aOffset, byte[] aBytes, int aBytesOffset, int aLength)
Writes the given bytes into thisSequence
.void
overwrite(int aOffset, Sequence aSequence)
void
overwrite(int aOffset, Sequence aSequence, int aSequenceOffset, int aLength)
Writes the given bytes into thisSequence
.void
overwrite(Sequence aSequence)
void
overwrite(Sequence aSequence, int aLength)
Writes the given bytes into thisSequence
.void
prepend(byte... aBytes)
Prepends the given bytes the beginning of thisSequence
.void
prepend(byte[] aBytes, int aOffset, int aLength)
Prepends the given bytes to the beginning of thisSequence
.void
prepend(Sequence aSequence)
void
replace(byte[] aBytes)
Replaces the given bytes with this byte array.void
replace(byte[] aBytes, int aLength)
Replaces the given bytes with this byte array.void
replace(byte[] aBytes, int aOffset, int aLength)
Replaces the given bytes with this byte array.void
replace(Sequence aSequence)
void
replace(Sequence aSequence, int aLength)
Replaces the given bytes with thisSequence
.void
replace(Sequence aSequence, int aOffset, int aLength)
Replaces the given bytes with thisSequence
.void
setByteAt(int aIndex, byte aByte)
Sets the byte at the given index in theSequence
.void
setLength(int aLength)
A value of -1 disables any length bounds.Spliterator<Byte>
spliterator()
Sequence
toAppend(byte... aBytes)
Appends the given bytes to the end of thisSequence
.Sequence
toAppend(byte[] aBytes, int aOffset, int aLength)
Appends the given bytes to the end of thisSequence
.Sequence
toAppend(Sequence aSequence)
byte[]
toBytes()
Retrieves a continuous array of bytes from theSequence
.byte[]
toBytes(int aOffset, int aLength)
Retrieves a continuous array of bytes from theSequence
, starting with the byte at the given offset and containing the given number of bytes.void
toBytes(int aOffset, int aLength, byte[] aBytes, int aBytesOffset)
Retrieves a continuous array of bytes from theSequence
, starting with the byte at the given offset and containing the given number of bytes.Sequence
toClone()
Creates a deep clone of thisSequence
.Sequence
toConcatenate(org.refcodes.mixin.ConcatenateMode aConcatenateMode, byte... aBytes)
Concatenates the given bytes with thisSequence
according to the providedConcatenateMode
.Sequence
toConcatenate(org.refcodes.mixin.ConcatenateMode aConcatenateMode, byte[] aBytes, int aOffset, int aLength)
Concatenates the given bytes with thisSequence
according to the providedConcatenateMode
.Sequence
toConcatenate(Sequence aSequence, org.refcodes.mixin.ConcatenateMode aConcatenateMode)
byte[]
toCrcBytes(long aCrcChecksum, org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm, org.refcodes.numerical.Endianess aEndianess)
Calculates the CRC checksum as byte array for thisSequence
.byte[]
toCrcBytes(org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm, org.refcodes.numerical.Endianess aEndianess)
Calculates the CRC checksum as byte array for thisSequence
.long
toCrcChecksum(long aCrcChecksum, org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm)
Calculates the CRC checksum for thisSequence
.long
toCrcChecksum(org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm)
Calculates the CRC checksum for thisSequence
.InputStream
toInputStream()
Creates anInputStream
form thisSequence
without being backed by thisSequence
, e.g. reading from the returnedInputStream
does not affect thisSequence
(in contrast to theInputStream
returned by the methodSequence.getInputStream()
).Sequence
toOverwrite(byte[] aBytes)
Writes the given bytes into a copy of thisSequence
.Sequence
toOverwrite(byte[] aBytes, int aLength)
Writes the given bytes into a copy of thisSequence
.Sequence
toOverwrite(int aOffset, byte[] aBytes)
Writes the given bytes into a copy of thisSequence
.Sequence
toOverwrite(int aOffset, byte[] aBytes, int aBytesOffset, int aLength)
Writes the given bytes into a copy of thisSequence
.Sequence
toOverwrite(int aOffset, Sequence aSequence)
Writes the given bytes into a copy of thisSequence
.Sequence
toOverwrite(int aOffset, Sequence aSequence, int aBytesOffset, int aLength)
Sequence
toOverwrite(Sequence aSequence)
Writes the given bytes into a copy of thisSequence
.Sequence
toOverwrite(Sequence aSequence, int aLength)
Writes the given bytes into a copy of thisSequence
.Sequence
toPrepend(byte... aBytes)
Prepends the given bytes to the beginning of thisSequence
.Sequence
toPrepend(byte[] aBytes, int aOffset, int aLength)
Prepends the given bytes to the beginning of thisSequence
.Sequence
toPrepend(Sequence aSequence)
Sequence
toSequence(int aOffset, int aLength)
Sequence
toTruncate(int aLength, org.refcodes.mixin.TruncateMode aTruncateMode)
Returns a newSequence
truncated by the given number of bytes from the right or from the left of both, according to the givenTruncateMode
.Sequence
toTruncateHead(int aLength)
Returns a newSequence
truncated by the given number of bytes from the left.Sequence
toTruncateTail(int aLength)
Returns a newSequence
truncated by the given number of bytes from the right.void
truncate(int aLength, org.refcodes.mixin.TruncateMode aTruncateMode)
Truncates theSequence
by the given number of bytes from the right or from the left of both, according to the givenTruncateMode
.void
truncateHead(int aLength)
Truncates theSequence
by the given number of bytes from the left.void
truncateTail(int aLength)
Truncates theSequence
by the given number of bytes from the right.Sequence
withAppend(byte... aBytes)
Builder method for theSequence.append(byte...)
method.Sequence
withAppend(byte[] aBytes, int aOffset, int aLength)
Builder method for theSequence.append(byte...)
method.Sequence
withAppend(Sequence aSequence)
Builder method for theSequence.append(Sequence)
method.Sequence
withConcatenate(org.refcodes.mixin.ConcatenateMode aConcatenateMode, byte... aBytes)
Builder method for theSequence.concatenate(ConcatenateMode, byte...)
method.Sequence
withConcatenate(Sequence aSequence, org.refcodes.mixin.ConcatenateMode aConcatenateMode)
Builder method for theSequence.concatenate(Sequence, ConcatenateMode)
method.Sequence
withOverwrite(byte[] aBytes)
Builder method for theSequence.overwrite(byte[])
method.Sequence
withOverwrite(byte[] aBytes, int aLength)
Builder method for theSequence.overwrite(Sequence, int)
method.Sequence
withOverwrite(int aOffset, byte[] aBytes)
Builder method for theSequence.overwrite(int, byte[])
method.Sequence
withOverwrite(int aOffset, byte[] aBytes, int aBytesOffset, int aLength)
Builder method for theSequence.overwrite(int, byte[], int, int)
method.Sequence
withOverwrite(int aOffset, Sequence aSequence)
Builder method for theSequence.overwrite(int, Sequence)
method.Sequence
withOverwrite(int aOffset, Sequence aSequence, int aSequenceOffset, int aLength)
Builder method for theSequence.overwrite(int, Sequence, int, int)
method.Sequence
withOverwrite(Sequence aSequence)
Builder method for theSequence.overwrite(Sequence)
method.Sequence
withOverwrite(Sequence aSequence, int aLength)
Builder method for theSequence.overwrite(Sequence, int)
method.Sequence
withPrepend(byte... aBytes)
Builder method for theSequence.prepend(byte...)
method.Sequence
withPrepend(byte[] aBytes, int aOffset, int aLength)
Builder method for theSequence.prepend(byte...)
method.Sequence
withPrepend(Sequence aSequence)
Builder method for theSequence.prepend(Sequence)
method.Sequence
withReplace(byte[] aBytes)
Builder method for theSequence.replace(byte[])
method.Sequence
withReplace(byte[] aBytes, int aLength)
Builder method for theSequence.replace(byte[], int, int)
method.Sequence
withReplace(byte[] aBytes, int aOffset, int aLength)
Builder method for theSequence.replace(byte[], int, int)
method.Sequence
withReplace(Sequence aSequence)
Builder method for theSequence.replace(Sequence)
method.Sequence
withReplace(Sequence aSequence, int aLength)
Builder method for theSequence.replace(Sequence, int, int)
method.Sequence
withReplace(Sequence aSequence, int aOffset, int aLength)
Builder method for theSequence.replace(Sequence, int, int)
method.Sequence
withTruncate(int aLength, org.refcodes.mixin.TruncateMode aTruncateMode)
Builder method for theSequence.truncate(int, TruncateMode)
method.Sequence
withTruncateHead(int aLength)
Builder method for theSequence.truncateHead(int)
method.Sequence
withTruncateTail(int aLength)
Builder method for theSequence.truncateTail(int)
method.void
writeTo(OutputStream aOutputStream)
Writes the content of the Sequence to the providedOutputStream
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.refcodes.serial.Sequence
toHexString, toHexString
-
-
-
-
Constructor Detail
-
BoundedSequenceDecorator
public BoundedSequenceDecorator(Sequence aSequence, int aLengthBounds)
Decorates the givenSequence
with a bounded maximum size.
-
BoundedSequenceDecorator
public BoundedSequenceDecorator(Sequence aSequence)
Decorates the givenSequence
with a bounded maximum size, as soon as a bounded size greater than -1 is provided viasetLength(int)
.- Parameters:
aSequence
- TheSequence
to be decorated.
-
-
Method Detail
-
getLength
public int getLength()
A value of -1 indicates that the length bounds are disabled.- Specified by:
getLength
in interfaceorg.refcodes.mixin.LengthAccessor
-
setLength
public void setLength(int aLength)
A value of -1 disables any length bounds.- Specified by:
setLength
in interfaceorg.refcodes.mixin.LengthAccessor.LengthMutator
-
append
public void append(byte... aBytes)
Appends the given bytes to the end of thisSequence
. Beware: ThisSequence
is modified! If you do not wish to modify thisSequence
, please useSequence.toAppend(byte...)
.
-
append
public void append(byte[] aBytes, int aOffset, int aLength)
Appends the given bytes to the end of thisSequence
. Beware: ThisSequence
is modified! If you do not wish to modify thisSequence
, please useSequence.toAppend(byte[], int, int)
.
-
spliterator
public Spliterator<Byte> spliterator()
- Specified by:
spliterator
in interfaceIterable<Byte>
-
append
public void append(Sequence aSequence)
Appends the givenSequence
to the end of thisSequence
. Beware: ThisSequence
is modified! If you do not wish to modify thisSequence
, please useSequence.toAppend(Sequence)
.
-
clear
public void clear()
Sets all bytes in theSequence
to zero.
-
clear
public void clear(byte aValue)
Sets all bytes in theSequence
to the provided value.
-
concatenate
public void concatenate(org.refcodes.mixin.ConcatenateMode aConcatenateMode, byte... aBytes)
Concatenates the given bytes with thisSequence
according to the providedConcatenateMode
. Beware: ThisSequence
is modified! If you do not wish to modify thisSequence
, please useSequence.toConcatenate(ConcatenateMode, byte...)
.- Specified by:
concatenate
in interfaceSequence
- 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 thisSequence
according to the providedConcatenateMode
. Beware: ThisSequence
is modified! If you do not wish to modify thisSequence
, please useSequence.toConcatenate(ConcatenateMode, byte[], int, int)
.- Specified by:
concatenate
in interfaceSequence
- 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 givenSequence
with thisSequence
according to the providedConcatenateMode
. Beware: ThisSequence
is modified! If you do not wish to modify thisSequence
, please useSequence.toConcatenate(Sequence, ConcatenateMode)
.- Specified by:
concatenate
in interfaceSequence
- Parameters:
aSequence
- TheSequence
to be concatenated with.aConcatenateMode
- The concatenation mode to be used.
-
empty
public void empty()
Empties theSequence
to end up being of length 0.
-
getByteAt
public byte getByteAt(int aIndex) throws IndexOutOfBoundsException
Returns the byte at the given index in theSequence
.- Specified by:
getByteAt
in interfaceSequence
- 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 anInputStream
backed by thisSequence
.- Specified by:
getInputStream
in interfaceorg.refcodes.mixin.InputStreamAccessor
- Specified by:
getInputStream
in interfaceSequence
-
getOutputStream
public OutputStream getOutputStream()
Creates anOutputStream
backed by thisSequence
.- Specified by:
getOutputStream
in interfaceorg.refcodes.mixin.OutputStreamAccessor
- Specified by:
getOutputStream
in interfaceSequence
-
overwrite
public void overwrite(byte[] aBytes)
-
overwrite
public void overwrite(byte[] aBytes, int aLength)
-
overwrite
public void overwrite(int aOffset, byte[] aBytes)
-
overwrite
public void overwrite(int aOffset, byte[] aBytes, int aBytesOffset, int aLength)
-
overwrite
public void overwrite(int aOffset, Sequence aSequence)
-
overwrite
public void overwrite(int aOffset, Sequence aSequence, int aSequenceOffset, int aLength)
-
overwrite
public void overwrite(Sequence aSequence)
-
overwrite
public void overwrite(Sequence aSequence, int aLength)
-
prepend
public void prepend(byte... aBytes)
Prepends the given bytes the beginning of thisSequence
. Beware: ThisSequence
is modified! If you do not wish to modify thisSequence
, please useSequence.toPrepend(byte...)
.
-
prepend
public void prepend(byte[] aBytes, int aOffset, int aLength)
Prepends the given bytes to the beginning of thisSequence
. Beware: ThisSequence
is modified! If you do not wish to modify thisSequence
, please useSequence.toPrepend(byte[], int, int)
.
-
prepend
public void prepend(Sequence aSequence)
Prepends the givenSequence
to the beginning of thisSequence
. Beware: ThisSequence
is modified! If you do not wish to modify thisSequence
, please useSequence.toPrepend(Sequence)
.
-
replace
public void replace(byte[] aBytes)
Replaces the given bytes with this byte array.
-
replace
public void replace(byte[] aBytes, int aLength)
Replaces the given bytes with this byte array.
-
replace
public void replace(byte[] aBytes, int aOffset, int aLength)
Replaces the given bytes with this byte array.
-
replace
public void replace(Sequence aSequence)
-
replace
public void replace(Sequence aSequence, int aLength)
Replaces the given bytes with thisSequence
.
-
replace
public void replace(Sequence aSequence, int aOffset, int aLength)
Replaces the given bytes with thisSequence
.
-
setByteAt
public void setByteAt(int aIndex, byte aByte)
Sets the byte at the given index in theSequence
.
-
toAppend
public Sequence toAppend(byte... aBytes)
-
toAppend
public Sequence toAppend(byte[] aBytes, int aOffset, int aLength)
-
toBytes
public byte[] toBytes()
Retrieves a continuous array of bytes from theSequence
.
-
toBytes
public byte[] toBytes(int aOffset, int aLength)
Retrieves a continuous array of bytes from theSequence
, starting with the byte at the given offset and containing the given number of bytes.
-
toBytes
public void toBytes(int aOffset, int aLength, byte[] aBytes, int aBytesOffset)
Retrieves a continuous array of bytes from theSequence
, 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.
-
toConcatenate
public Sequence toConcatenate(org.refcodes.mixin.ConcatenateMode aConcatenateMode, byte... aBytes)
Concatenates the given bytes with thisSequence
according to the providedConcatenateMode
. ThisSequence
is not modified and a newSequence
is returned.- Specified by:
toConcatenate
in interfaceSequence
- 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 thisSequence
according to the providedConcatenateMode
. ThisSequence
is not modified and a newSequence
is returned.- Specified by:
toConcatenate
in interfaceSequence
- 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 givenSequence
with thisSequence
according to the providedConcatenateMode
. ThisSequence
is not modified and a newSequence
is returned.- Specified by:
toConcatenate
in interfaceSequence
- Parameters:
aSequence
- TheSequence
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 thisSequence
.- Specified by:
toCrcBytes
in interfaceSequence
- Parameters:
aCrcAlgorithm
- TheCrcAlgorithm
to be used when calculating the CRC checksum.aEndianess
- TheEndianess
(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 thisSequence
.- Specified by:
toCrcBytes
in interfaceSequence
- Parameters:
aCrcChecksum
- The CRC checksum from which to continue calculating the checksum,aCrcAlgorithm
- TheCrcAlgorithm
to be used when calculating the CRC checksum.aEndianess
- TheEndianess
(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 thisSequence
.- Specified by:
toCrcChecksum
in interfaceSequence
- Parameters:
aCrcAlgorithm
- TheCrcAlgorithm
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 thisSequence
.- Specified by:
toCrcChecksum
in interfaceSequence
- Parameters:
aCrcChecksum
- The CRC checksum from which to continue calculating the checksum,aCrcAlgorithm
- TheCrcAlgorithm
to be used when calculating the CRC checksum.- Returns:
- The CRC checksum of the
Sequence
.
-
toInputStream
public InputStream toInputStream()
Creates anInputStream
form thisSequence
without being backed by thisSequence
, e.g. reading from the returnedInputStream
does not affect thisSequence
(in contrast to theInputStream
returned by the methodSequence.getInputStream()
).- Specified by:
toInputStream
in interfaceSequence
- Returns:
- The according
InputStream
not affecting thisSequence
.
-
toOverwrite
public Sequence toOverwrite(byte[] aBytes)
Writes the given bytes into a copy of thisSequence
. If theSequence
is too small for the bytes to fit into, then theSequence
is extended accordingly.- Specified by:
toOverwrite
in interfaceSequence
- 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 thisSequence
. If theSequence
is too small for the bytes to fit into, then theSequence
is extended accordingly.- Specified by:
toOverwrite
in interfaceSequence
- 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 thisSequence
. If theSequence
is too small for the bytes to fit into, then theSequence
is extended accordingly.- Specified by:
toOverwrite
in interfaceSequence
- 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 thisSequence
. If theSequence
is too small for the bytes to fit into, then theSequence
is extended accordingly.- Specified by:
toOverwrite
in interfaceSequence
- 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 thisSequence
. If theSequence
is too small for the bytes to fit into, then theSequence
is extended accordingly.- Specified by:
toOverwrite
in interfaceSequence
- Parameters:
aOffset
- The offset where to start writing the bytes to.aSequence
- TheSequence
where to copy the bytes from.- Returns:
- The according
Sequence
.
-
toOverwrite
public Sequence toOverwrite(int aOffset, Sequence aSequence, int aBytesOffset, int aLength)
Writes the givenSequence
into a copy of thisSequence
. If theSequence
is too small for the bytes to fit into, then theSequence
is extended accordingly.- Specified by:
toOverwrite
in interfaceSequence
- Parameters:
aOffset
- The offset where to start writing the bytes to.aSequence
- TheSequence
where to copy the bytes from.aBytesOffset
- The offset in theSequence
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 thisSequence
. If theSequence
is too small for the bytes to fit into, then theSequence
is extended accordingly.- Specified by:
toOverwrite
in interfaceSequence
- Parameters:
aSequence
- TheSequence
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 thisSequence
. If theSequence
is too small for the bytes to fit into, then theSequence
is extended accordingly.- Specified by:
toOverwrite
in interfaceSequence
- Parameters:
aSequence
- TheSequence
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)
-
toPrepend
public Sequence toPrepend(byte[] aBytes, int aOffset, int aLength)
-
toSequence
public Sequence toSequence(int aOffset, int aLength)
Retrieves a newSequence
from thisSequence
, starting with the byte at the given offset and containing the given number of bytes.- Specified by:
toSequence
in interfaceSequence
- 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 newSequence
truncated by the given number of bytes from the right or from the left of both, according to the givenTruncateMode
. If the number of bytes exceeds the actual length of theSequence
, then the Sequence will end up being empty.- Specified by:
toTruncate
in interfaceSequence
- Parameters:
aLength
- The number of bytes to truncate according to theTruncateMode
.aTruncateMode
- TheTruncateMode
to use for truncating theSequence
.- Returns:
- The newly created truncated
Sequence
.
-
toTruncateHead
public Sequence toTruncateHead(int aLength)
Returns a newSequence
truncated by the given number of bytes from the left. If the number of bytes exceeds the actual length of theSequence
, then the newSequence
will end up being empty.- Specified by:
toTruncateHead
in interfaceSequence
- 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 newSequence
truncated by the given number of bytes from the right. If the number of bytes exceeds the actual length of theSequence
, then the newSequence
will end up being empty.- Specified by:
toTruncateTail
in interfaceSequence
- 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)
-
truncateHead
public void truncateHead(int aLength)
Truncates theSequence
by the given number of bytes from the left. If the number of bytes exceeds the actual length of theSequence
, then theSequence
will end up being empty.- Specified by:
truncateHead
in interfaceSequence
- Parameters:
aLength
- The number of bytes to truncate from the left.
-
truncateTail
public void truncateTail(int aLength)
Truncates theSequence
by the given number of bytes from the right. If the number of bytes exceeds the actual length of theSequence
, then theSequence
will end up being empty.- Specified by:
truncateTail
in interfaceSequence
- Parameters:
aLength
- The number of bytes to truncate from the right.
-
withAppend
public Sequence withAppend(byte... aBytes)
Builder method for theSequence.append(byte...)
method.- Specified by:
withAppend
in interfaceSequence
- 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 theSequence.append(byte...)
method.- Specified by:
withAppend
in interfaceSequence
- 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 theSequence.append(Sequence)
method.- Specified by:
withAppend
in interfaceSequence
- Parameters:
aSequence
- TheSequence
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 theSequence.concatenate(ConcatenateMode, byte...)
method.- Specified by:
withConcatenate
in interfaceSequence
- 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)
Builder method for theSequence.concatenate(Sequence, ConcatenateMode)
method.- Specified by:
withConcatenate
in interfaceSequence
- Parameters:
aSequence
- TheSequence
to be concatenated withaConcatenateMode
- The concatenation mode to be used.- Returns:
- This instance as of the builder pattern.
-
withOverwrite
public Sequence withOverwrite(byte[] aBytes)
Builder method for theSequence.overwrite(byte[])
method.- Specified by:
withOverwrite
in interfaceSequence
- 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 theSequence.overwrite(Sequence, int)
method.- Specified by:
withOverwrite
in interfaceSequence
- 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 theSequence.overwrite(int, byte[])
method.- Specified by:
withOverwrite
in interfaceSequence
- 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 theSequence.overwrite(int, byte[], int, int)
method.- Specified by:
withOverwrite
in interfaceSequence
- 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 theSequence.overwrite(int, Sequence)
method.- Specified by:
withOverwrite
in interfaceSequence
- Parameters:
aOffset
- The offset where to start writing the bytes to.aSequence
- TheSequence
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 theSequence.overwrite(int, Sequence, int, int)
method.- Specified by:
withOverwrite
in interfaceSequence
- Parameters:
aOffset
- The offset where to start writing the bytes to.aSequence
- TheSequence
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 theSequence.overwrite(Sequence)
method.- Specified by:
withOverwrite
in interfaceSequence
- Parameters:
aSequence
- TheSequence
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 theSequence.overwrite(Sequence, int)
method.- Specified by:
withOverwrite
in interfaceSequence
- Parameters:
aSequence
- TheSequence
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 theSequence.prepend(byte...)
method.- Specified by:
withPrepend
in interfaceSequence
- 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 theSequence.prepend(byte...)
method.- Specified by:
withPrepend
in interfaceSequence
- 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 theSequence.prepend(Sequence)
method.- Specified by:
withPrepend
in interfaceSequence
- Parameters:
aSequence
- TheSequence
to be prepended.- Returns:
- This instance as of the builder pattern.
-
withReplace
public Sequence withReplace(byte[] aBytes)
Builder method for theSequence.replace(byte[])
method.- Specified by:
withReplace
in interfaceSequence
- 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 theSequence.replace(byte[], int, int)
method.- Specified by:
withReplace
in interfaceSequence
- 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 theSequence.replace(Sequence, int, int)
method.- Specified by:
withReplace
in interfaceSequence
- Parameters:
aSequence
- The byteSequence
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 theSequence.replace(byte[], int, int)
method.- Specified by:
withReplace
in interfaceSequence
- 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 theSequence.replace(Sequence)
method.- Specified by:
withReplace
in interfaceSequence
- Parameters:
aSequence
- TheSequence
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 theSequence.replace(Sequence, int, int)
method.- Specified by:
withReplace
in interfaceSequence
- Parameters:
aSequence
- TheSequence
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 theSequence.truncate(int, TruncateMode)
method.- Specified by:
withTruncate
in interfaceSequence
- Parameters:
aLength
- The number of bytes to truncate according to theTruncateMode
.aTruncateMode
- TheTruncateMode
to use for truncating theSequence
.- Returns:
- This instance as of the builder pattern.
-
withTruncateHead
public Sequence withTruncateHead(int aLength)
Builder method for theSequence.truncateHead(int)
method.- Specified by:
withTruncateHead
in interfaceSequence
- 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 theSequence.truncateTail(int)
method.- Specified by:
withTruncateTail
in interfaceSequence
- 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 providedOutputStream
.- Specified by:
writeTo
in interfaceSequence
- Parameters:
aOutputStream
- TheOutputStream
where to write to.- Throws:
IOException
- thrown in case of I/O problems.
-
-