Top Description Fields Constructors Methods
org.wildfly.common.iteration

public abstract Class ByteIterator

extends Object
implements BiDirIntIterator, IndexIterator
Class Inheritance
All Implemented Interfaces
org.wildfly.common.iteration.IndexIterator, org.wildfly.common.iteration.BiDirIntIterator, org.wildfly.common.iteration.IntIterator
Known Direct Subclasses
org.wildfly.common.iteration.ByteTableTranslatingByteIterator, org.wildfly.common.iteration.ConcatByteIterator, org.wildfly.common.iteration.DelimitedByteIterator, org.wildfly.common.iteration.InterleavedByteArrayIterator, org.wildfly.common.iteration.IntTableTranslatingByteIterator, org.wildfly.common.iteration.Latin1EncodingByteIterator, org.wildfly.common.iteration.LimitedByteIterator, org.wildfly.common.iteration.Utf8EncodingByteIterator, org.wildfly.common.iteration.Base16DecodingByteIterator, org.wildfly.common.iteration.Base32DecodingByteIterator, org.wildfly.common.iteration.Base64DecodingByteIterator, org.wildfly.common.iteration.ByteArrayIterator, org.wildfly.common.iteration.ByteBufferIterator
Imports
java.io.ByteArrayOutputStream, .InputStream, java.nio.ByteBuffer, java.nio.charset.StandardCharsets, java.security.MessageDigest, .Signature, .SignatureException, java.util.Arrays, .NoSuchElementException, javax.crypto.Mac, org.wildfly.common.Assert, org.wildfly.common.bytes.ByteStringBuilder, org.wildfly.common.codec.Base32Alphabet, .Base64Alphabet

A byte iterator.

Field Summary

Modifier and TypeField and Description
public static final ByteIterator
EMPTY

The empty byte iterator.

private static final byte[]
private static final ThreadLocal<byte[]>
private static final int

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public ByteStringBuilder
appendTo(final ByteStringBuilder builder)

public final InputStream

Returns:

the input stream (not null)
asInputStream
()

Get this iterator as an input stream.

public CodePointIterator

Returns:

the code point iterator
asLatin1String
()

Get this byte iterator as a Latin-1 string.

public CodePointIterator

Returns:

the code point iterator
asUtf8String
()

Get this byte iterator as a UTF-8 string.

public CodePointIterator

Returns:

an iterator over the encoded characters
base32Encode
(final Base32Alphabet
the alphabet to use
alphabet
,
final boolean
true to add trailing padding, false to leave it off
addPadding
)

Base32-encode the current stream.

public CodePointIterator

Returns:

an iterator over the encoded characters
base32Encode
(final Base32Alphabet
the alphabet to use
alphabet
)

Base32-encode the current stream.

public CodePointIterator

Returns:

an iterator over the encoded characters
base32Encode
()

Base32-encode the current stream.

public CodePointIterator

Returns:

an iterator over the encoded characters
base64Encode
(final Base64Alphabet
the alphabet to use
alphabet
,
final boolean
true to add trailing padding, false to leave it off
addPadding
)

Base64-encode the current stream.

public CodePointIterator

Returns:

an iterator over the encoded characters
base64Encode
(final Base64Alphabet
the alphabet to use
alphabet
)

Base64-encode the current stream.

public CodePointIterator

Returns:

an iterator over the encoded characters
base64Encode
()

Base64-encode the current stream.

public final boolean

Returns:

true if the contents are equal, false otherwise
contentEquals
(ByteIterator
the other byte iterator
other
)

Determine if the remaining contents of this iterator are identical to the remaining contents of the other iterator.

public final ByteIterator

Returns:

the sub-iterator
delimitedBy
(final int...
the byte delimiters
delims
)

Get a sub-iterator that is delimited by the given bytes.

public ByteIterator
public ByteIterator
doFinal(Mac mac)

public byte[]

Returns:

the remaining bytes as a single array
drain
()

Drain all the remaining bytes in this iterator.

public byte[]

Returns:

the array of consumed bytes (may be smaller than count)
drain
(int
the number of bytes to read
count
)

Drain up to count bytes from this iterator, returning the result.

public int

Returns:

the total number of bytes drained into dst, always greater or equal to 0
drain
(byte[]
the buffer into which the data is drained
dst
)

Drains up to dst.length bytes from this iterator into the given dst array.

public int

Returns:

the total number of bytes drained into dst, always greater or equal to 0
drain
(byte[]
the buffer into which the data is drained
dst
,
int
the start offset in array dst at which the data is written.
offs
,
int
the maximum number of bytes to drain
len
)

Drains up to len bytes from this iterator into the given dst array.

public byte[]

Returns:

the array of consumed bytes
drainAll
(int
the number of bytes to read
count
)

Drain exactly count bytes from this iterator, returning the result.

public ByteArrayOutputStream

Returns:

the same stream
drainTo
(ByteArrayOutputStream
the stream
stream
)

Drain all the remaining bytes in this iterator to the given stream.

public String

Returns:

the Latin-1 string
drainToLatin1
(int
the maximum number of bytes to consume
count
)

Convenience method to directly drain a certain number of bytes to a Latin-1 string.

public String

Returns:

the UTF-8 string
drainToUtf8
(int
the maximum number of bytes to consume
count
)

Convenience method to directly drain a certain number of bytes to a UTF-8 string.

public int
public int
public long
public abstract long

Returns:

the byte offset
getIndex
()

Redeclares org.wildfly.common.iteration.IndexIterator.getIndex.

Get the current offset, in bytes.
public int
public int
public long
public int
public long
public abstract boolean

Returns:

true if there are more bytes, false otherwise
hasNext
()

Redeclares org.wildfly.common.iteration.BiDirIntIterator.hasNext.

Determine if there are more bytes after the current byte.
public abstract boolean

Returns:

true if there are more bytes, false otherwise
hasPrevious
()

Redeclares org.wildfly.common.iteration.BiDirIntIterator.hasPrevious.

Determine if there are more bytes before the current byte.
public CodePointIterator

Returns:

an iterator over the encoded characters
hexEncode
(boolean
true to use upper case characters when encoding, false to use lower case characters
toUpperCase
)

Hex-encode the current stream.

public CodePointIterator

Returns:

an iterator over the encoded characters
hexEncode
()

Hex-encode the current stream.

public ByteIterator

Returns:

the interleaving byte iterator
interleavedWith
(final byte[]
the interleaving table
table
)

Get a byte iterator which translates this byte iterator through an interleaving table.

public ByteIterator

Returns:

the interleaving byte iterator
interleavedWith
(final int[]
the interleaving table
table
)

Get a byte iterator which translates this byte iterator through an interleaving table.

public final ByteIterator

Returns:

the limited byte iterator
limitedTo
(final int
the number of bytes
size
)

Return a copy of this iterator which is limited to the given number of bytes after the current one.

public abstract int

Returns:

the next byte
next
()

Redeclares org.wildfly.common.iteration.BiDirIntIterator.next.

Get the next byte.
public static ByteIterator

Returns:

the byte iterator (not null)
ofByteBuffer
(ByteBuffer
the byte buffer (must not be null)
buffer
)

Get a byte iterator for a byte buffer.

public static ByteIterator

Returns:

the byte iterator
ofBytes
(final byte...
the array
bytes
)

Get a byte iterator for a byte array.

public static ByteIterator

Returns:

the byte iterator
ofBytes
(final byte[]
the array
bytes
,
final int
the array offset
offs
,
final int
the number of bytes to include
len
)

Get a byte iterator for a byte array.

public static ByteIterator

Returns:

the byte iterator
ofBytes
(final byte[]
the array
bytes
,
final int
the array offset
offs
,
final int
the number of bytes to include
len
,
final int[]
the interleave table to use
interleave
)

Get a byte iterator for a byte array with interleave.

public static ByteIterator

Returns:

the byte iterator
ofBytes
(final byte[]
the array
bytes
,
final int[]
the interleave table to use
interleave
)

Get a byte iterator for a byte array with interleave.

public static ByteIterator

Returns:

a concatenated iterator
ofIterators
(ByteIterator...
the iterators array (must not be null or contain null elements)
iterators
)

Get a concatenated byte iterator.

public abstract int

Returns:

the next byte
peekNext
()

Redeclares org.wildfly.common.iteration.BiDirIntIterator.peekNext.

Peek at the next byte without advancing.
public abstract int

Returns:

the previous byte
peekPrevious
()

Redeclares org.wildfly.common.iteration.BiDirIntIterator.peekPrevious.

Peek at the previous byte without moving backwards.
public abstract int

Returns:

the previous byte
previous
()

Redeclares org.wildfly.common.iteration.BiDirIntIterator.previous.

Get the previous byte.
public ByteIterator
sign(Signature signature)

public void
public void
update(Mac mac)

public void
update(Signature signature)

public boolean
verify(Signature signature)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EMPTYback to summary
public static final ByteIterator EMPTY

The empty byte iterator.

NO_BYTESback to summary
private static final byte[] NO_BYTES
OP_BUFFERback to summary
private static final ThreadLocal<byte[]> OP_BUFFER
OP_BUFFER_SIZEback to summary
private static final int OP_BUFFER_SIZE

Constructor Detail

ByteIteratorback to summary
pack-priv ByteIterator()

Method Detail

appendToback to summary
public ByteStringBuilder appendTo(final ByteStringBuilder builder)
asInputStreamback to summary
public final InputStream asInputStream()

Get this iterator as an input stream.

Returns:InputStream

the input stream (not null)

asLatin1Stringback to summary
public CodePointIterator asLatin1String()

Get this byte iterator as a Latin-1 string.

Returns:CodePointIterator

the code point iterator

asUtf8Stringback to summary
public CodePointIterator asUtf8String()

Get this byte iterator as a UTF-8 string.

Returns:CodePointIterator

the code point iterator

base32Encodeback to summary
public CodePointIterator base32Encode(final Base32Alphabet alphabet, final boolean addPadding)

Base32-encode the current stream.

Parameters
alphabet:Base32Alphabet

the alphabet to use

addPadding:boolean

true to add trailing padding, false to leave it off

Returns:CodePointIterator

an iterator over the encoded characters

base32Encodeback to summary
public CodePointIterator base32Encode(final Base32Alphabet alphabet)

Base32-encode the current stream.

Parameters
alphabet:Base32Alphabet

the alphabet to use

Returns:CodePointIterator

an iterator over the encoded characters

base32Encodeback to summary
public CodePointIterator base32Encode()

Base32-encode the current stream.

Returns:CodePointIterator

an iterator over the encoded characters

base64Encodeback to summary
public CodePointIterator base64Encode(final Base64Alphabet alphabet, final boolean addPadding)

Base64-encode the current stream.

Parameters
alphabet:Base64Alphabet

the alphabet to use

addPadding:boolean

true to add trailing padding, false to leave it off

Returns:CodePointIterator

an iterator over the encoded characters

base64Encodeback to summary
public CodePointIterator base64Encode(final Base64Alphabet alphabet)

Base64-encode the current stream.

Parameters
alphabet:Base64Alphabet

the alphabet to use

Returns:CodePointIterator

an iterator over the encoded characters

base64Encodeback to summary
public CodePointIterator base64Encode()

Base64-encode the current stream.

Returns:CodePointIterator

an iterator over the encoded characters

contentEqualsback to summary
public final boolean contentEquals(ByteIterator other)

Determine if the remaining contents of this iterator are identical to the remaining contents of the other iterator. If the contents are not equal, the iterators will be positioned at the location of the first difference. If the contents are equal, the iterators will both be positioned at the end of their contents.

Parameters
other:ByteIterator

the other byte iterator

Returns:boolean

true if the contents are equal, false otherwise

delimitedByback to summary
public final ByteIterator delimitedBy(final int... delims)

Get a sub-iterator that is delimited by the given bytes. The returned iterator offset starts at 0 and cannot be backed up before that point. The returned iterator will return false for hasNext() if the next character in the encapsulated iterator is a delimiter or if the underlying iterator returns false for hasNext().

Parameters
delims:int[]

the byte delimiters

Returns:ByteIterator

the sub-iterator

doFinalback to summary
public ByteIterator doFinal(MessageDigest digest)
doFinalback to summary
public ByteIterator doFinal(Mac mac)
drainback to summary
public byte[] drain()

Drain all the remaining bytes in this iterator.

Returns:byte[]

the remaining bytes as a single array

drainback to summary
public byte[] drain(int count)

Drain up to count bytes from this iterator, returning the result.

Parameters
count:int

the number of bytes to read

Returns:byte[]

the array of consumed bytes (may be smaller than count)

drainback to summary
public int drain(byte[] dst)

Drains up to dst.length bytes from this iterator into the given dst array. An attempt is made to drain as many as dst.length bytes, but a smaller number may be drained.

The number of bytes actually drained is returned as an integer. Unlike InputStream#read(byte[], int, int), this method never returns a negative result.

Parameters
dst:byte[]

the buffer into which the data is drained

Returns:int

the total number of bytes drained into dst, always greater or equal to 0

drainback to summary
public int drain(byte[] dst, int offs, int len)

Drains up to len bytes from this iterator into the given dst array. An attempt is made to drain as many as len bytes, but a smaller number may be drained.

The number of bytes actually drained is returned as an integer. Unlike InputStream#read(byte[], int, int), this method never returns a negative result.

Parameters
dst:byte[]

the buffer into which the data is drained

offs:int

the start offset in array dst at which the data is written.

len:int

the maximum number of bytes to drain

Returns:int

the total number of bytes drained into dst, always greater or equal to 0

drainAllback to summary
public byte[] drainAll(int count) throws NoSuchElementException

Drain exactly count bytes from this iterator, returning the result.

Parameters
count:int

the number of bytes to read

Returns:byte[]

the array of consumed bytes

Exceptions
NoSuchElementException:
if there are not enough bytes to fill the array
drainToback to summary
public ByteArrayOutputStream drainTo(ByteArrayOutputStream stream)

Drain all the remaining bytes in this iterator to the given stream.

Parameters
stream:ByteArrayOutputStream

the stream

Returns:ByteArrayOutputStream

the same stream

drainToLatin1back to summary
public String drainToLatin1(int count)

Convenience method to directly drain a certain number of bytes to a Latin-1 string. If fewer than count bytes are available, only the available bytes will be used to construct the string.

Parameters
count:int

the maximum number of bytes to consume

Returns:String

the Latin-1 string

drainToUtf8back to summary
public String drainToUtf8(int count)

Convenience method to directly drain a certain number of bytes to a UTF-8 string. If fewer than count bytes are available, only the available bytes will be used to construct the string.

Parameters
count:int

the maximum number of bytes to consume

Returns:String

the UTF-8 string

getBE16back to summary
public int getBE16() throws NoSuchElementException
getBE32back to summary
public int getBE32() throws NoSuchElementException
getBE64back to summary
public long getBE64() throws NoSuchElementException
getIndexback to summary
public abstract long getIndex()

Redeclares org.wildfly.common.iteration.IndexIterator.getIndex.

Get the current offset, in bytes.

Returns:long

the byte offset

getLE16back to summary
public int getLE16() throws NoSuchElementException
getLE32back to summary
public int getLE32() throws NoSuchElementException
getLE64back to summary
public long getLE64() throws NoSuchElementException
getPackedBE32back to summary
public int getPackedBE32() throws NoSuchElementException
getPackedBE64back to summary
public long getPackedBE64() throws NoSuchElementException
hasNextback to summary
public abstract boolean hasNext()

Redeclares org.wildfly.common.iteration.BiDirIntIterator.hasNext.

Determine if there are more bytes after the current byte.

Returns:boolean

true if there are more bytes, false otherwise

hasPreviousback to summary
public abstract boolean hasPrevious()

Redeclares org.wildfly.common.iteration.BiDirIntIterator.hasPrevious.

Determine if there are more bytes before the current byte.

Returns:boolean

true if there are more bytes, false otherwise

hexEncodeback to summary
public CodePointIterator hexEncode(boolean toUpperCase)

Hex-encode the current stream.

Parameters
toUpperCase:boolean

true to use upper case characters when encoding, false to use lower case characters

Returns:CodePointIterator

an iterator over the encoded characters

hexEncodeback to summary
public CodePointIterator hexEncode()

Hex-encode the current stream.

Returns:CodePointIterator

an iterator over the encoded characters

interleavedWithback to summary
public ByteIterator interleavedWith(final byte[] table)

Get a byte iterator which translates this byte iterator through an interleaving table. The table should be 256 entries in size or exceptions may result.

Parameters
table:byte[]

the interleaving table

Returns:ByteIterator

the interleaving byte iterator

interleavedWithback to summary
public ByteIterator interleavedWith(final int[] table)

Get a byte iterator which translates this byte iterator through an interleaving table. The table should be 256 entries in size or exceptions may result.

Parameters
table:int[]

the interleaving table

Returns:ByteIterator

the interleaving byte iterator

limitedToback to summary
public final ByteIterator limitedTo(final int size)

Return a copy of this iterator which is limited to the given number of bytes after the current one. Advancing the returned iterator will also advance this one.

Parameters
size:int

the number of bytes

Returns:ByteIterator

the limited byte iterator

nextback to summary
public abstract int next() throws NoSuchElementException

Redeclares org.wildfly.common.iteration.BiDirIntIterator.next.

Get the next byte.

Returns:int

the next byte

Exceptions
NoSuchElementException:
if hasNext() returns false
ofByteBufferback to summary
public static ByteIterator ofByteBuffer(ByteBuffer buffer)

Get a byte iterator for a byte buffer. The buffer's position is kept up to date with the number of bytes consumed by the iterator. The iterator cannot be moved before the position that the buffer had when the iterator was constructed (this position is considered the zero offset).

Parameters
buffer:ByteBuffer

the byte buffer (must not be null)

Returns:ByteIterator

the byte iterator (not null)

ofBytesback to summary
public static ByteIterator ofBytes(final byte... bytes)

Get a byte iterator for a byte array.

Parameters
bytes:byte[]

the array

Returns:ByteIterator

the byte iterator

ofBytesback to summary
public static ByteIterator ofBytes(final byte[] bytes, final int offs, final int len)

Get a byte iterator for a byte array.

Parameters
bytes:byte[]

the array

offs:int

the array offset

len:int

the number of bytes to include

Returns:ByteIterator

the byte iterator

ofBytesback to summary
public static ByteIterator ofBytes(final byte[] bytes, final int offs, final int len, final int[] interleave)

Get a byte iterator for a byte array with interleave.

Parameters
bytes:byte[]

the array

offs:int

the array offset

len:int

the number of bytes to include

interleave:int[]

the interleave table to use

Returns:ByteIterator

the byte iterator

ofBytesback to summary
public static ByteIterator ofBytes(final byte[] bytes, final int[] interleave)

Get a byte iterator for a byte array with interleave.

Parameters
bytes:byte[]

the array

interleave:int[]

the interleave table to use

Returns:ByteIterator

the byte iterator

ofIteratorsback to summary
public static ByteIterator ofIterators(ByteIterator... iterators)

Get a concatenated byte iterator. The array and the byte iterators in the array must not be modified or inconsistent behavior will result.

Parameters
iterators:ByteIterator[]

the iterators array (must not be null or contain null elements)

Returns:ByteIterator

a concatenated iterator

peekNextback to summary
public abstract int peekNext() throws NoSuchElementException

Redeclares org.wildfly.common.iteration.BiDirIntIterator.peekNext.

Peek at the next byte without advancing.

Returns:int

the next byte

Exceptions
NoSuchElementException:
if hasNext() returns false
peekPreviousback to summary
public abstract int peekPrevious() throws NoSuchElementException

Redeclares org.wildfly.common.iteration.BiDirIntIterator.peekPrevious.

Peek at the previous byte without moving backwards.

Returns:int

the previous byte

Exceptions
NoSuchElementException:
if hasPrevious() returns false
previousback to summary
public abstract int previous() throws NoSuchElementException

Redeclares org.wildfly.common.iteration.BiDirIntIterator.previous.

Get the previous byte.

Returns:int

the previous byte

Exceptions
NoSuchElementException:
if hasPrevious() returns false
signback to summary
public ByteIterator sign(Signature signature) throws SignatureException
updateback to summary
public void update(MessageDigest digest)
updateback to summary
public void update(Mac mac)
updateback to summary
public void update(Signature signature) throws SignatureException
verifyback to summary
public boolean verify(Signature signature) throws SignatureException