Package org.wildfly.common.iteration
Class ByteIterator
java.lang.Object
org.wildfly.common.iteration.ByteIterator
- All Implemented Interfaces:
BiDirIntIterator,IndexIterator,IntIterator
A byte iterator.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionappendTo(ByteStringBuilder builder) final InputStreamGet this iterator as an input stream.Get this byte iterator as a Latin-1 string.Get this byte iterator as a UTF-8 string.Base32-encode the current stream.base32Encode(Base32Alphabet alphabet) Base32-encode the current stream.base32Encode(Base32Alphabet alphabet, boolean addPadding) Base32-encode the current stream.Base64-encode the current stream.base64Encode(Base64Alphabet alphabet) Base64-encode the current stream.base64Encode(Base64Alphabet alphabet, boolean addPadding) Base64-encode the current stream.final booleancontentEquals(ByteIterator other) Determine if the remaining contents of this iterator are identical to the remaining contents of the other iterator.final ByteIteratordelimitedBy(int... delims) Get a sub-iterator that is delimited by the given bytes.doFinal(MessageDigest digest) byte[]drain()Drain all the remaining bytes in this iterator.intdrain(byte[] dst) Drains up todst.lengthbytes from this iterator into the givendstarray.intdrain(byte[] dst, int offs, int len) Drains up tolenbytes from this iterator into the givendstarray.byte[]drain(int count) Drain up tocountbytes from this iterator, returning the result.byte[]drainAll(int count) Drain exactlycountbytes from this iterator, returning the result.drainTo(ByteArrayOutputStream stream) Drain all the remaining bytes in this iterator to the given stream.drainToLatin1(int count) Convenience method to directly drain a certain number of bytes to a Latin-1 string.drainToUtf8(int count) Convenience method to directly drain a certain number of bytes to a UTF-8 string.intgetBE16()intgetBE32()longgetBE64()abstract longgetIndex()Get the current offset, in bytes.intgetLE16()intgetLE32()longgetLE64()intlongabstract booleanhasNext()Determine if there are more bytes after the current byte.abstract booleanDetermine if there are more bytes before the current byte.Hex-encode the current stream.hexEncode(boolean toUpperCase) Hex-encode the current stream.interleavedWith(byte[] table) Get a byte iterator which translates this byte iterator through an interleaving table.interleavedWith(int[] table) Get a byte iterator which translates this byte iterator through an interleaving table.final ByteIteratorlimitedTo(int size) Return a copy of this iterator which is limited to the given number of bytes after the current one.abstract intnext()Get the next byte.static ByteIteratorofByteBuffer(ByteBuffer buffer) Get a byte iterator for a byte buffer.static ByteIteratorofBytes(byte... bytes) Get a byte iterator for a byte array.static ByteIteratorofBytes(byte[] bytes, int[] interleave) Get a byte iterator for a byte array with interleave.static ByteIteratorofBytes(byte[] bytes, int offs, int len) Get a byte iterator for a byte array.static ByteIteratorofBytes(byte[] bytes, int offs, int len, int[] interleave) Get a byte iterator for a byte array with interleave.static ByteIteratorofIterators(ByteIterator... iterators) Get a concatenated byte iterator.abstract intpeekNext()Peek at the next byte without advancing.abstract intPeek at the previous byte without moving backwards.abstract intprevious()Get the previous byte.voidupdate(MessageDigest digest) voidvoidboolean
-
Field Details
-
EMPTY
The empty byte iterator.
-
-
Method Details
-
hasNext
public abstract boolean hasNext()Determine if there are more bytes after the current byte.- Specified by:
hasNextin interfaceBiDirIntIterator- Specified by:
hasNextin interfaceIntIterator- Returns:
trueif there are more bytes,falseotherwise
-
hasPrevious
public abstract boolean hasPrevious()Determine if there are more bytes before the current byte.- Specified by:
hasPreviousin interfaceBiDirIntIterator- Returns:
trueif there are more bytes,falseotherwise
-
next
Get the next byte.- Specified by:
nextin interfaceBiDirIntIterator- Specified by:
nextin interfaceIntIterator- Returns:
- the next byte
- Throws:
NoSuchElementException- ifhasNext()returnsfalse
-
peekNext
Peek at the next byte without advancing.- Specified by:
peekNextin interfaceBiDirIntIterator- Specified by:
peekNextin interfaceIntIterator- Returns:
- the next byte
- Throws:
NoSuchElementException- ifhasNext()returnsfalse
-
previous
Get the previous byte.- Specified by:
previousin interfaceBiDirIntIterator- Returns:
- the previous byte
- Throws:
NoSuchElementException- ifhasPrevious()returnsfalse
-
peekPrevious
Peek at the previous byte without moving backwards.- Specified by:
peekPreviousin interfaceBiDirIntIterator- Returns:
- the previous byte
- Throws:
NoSuchElementException- ifhasPrevious()returnsfalse
-
getIndex
public abstract long getIndex()Get the current offset, in bytes.- Specified by:
getIndexin interfaceIndexIterator- Returns:
- the byte offset
-
getBE16
- Throws:
NoSuchElementException
-
getBE32
- Throws:
NoSuchElementException
-
getBE64
- Throws:
NoSuchElementException
-
getLE16
- Throws:
NoSuchElementException
-
getLE32
- Throws:
NoSuchElementException
-
getLE64
- Throws:
NoSuchElementException
-
getPackedBE32
- Throws:
NoSuchElementException
-
getPackedBE64
- Throws:
NoSuchElementException
-
appendTo
-
update
-
doFinal
-
update
-
doFinal
-
update
- Throws:
SignatureException
-
sign
- Throws:
SignatureException
-
verify
- Throws:
SignatureException
-
base64Encode
Base64-encode the current stream.- Parameters:
alphabet- the alphabet to useaddPadding-trueto add trailing padding,falseto leave it off- Returns:
- an iterator over the encoded characters
-
base64Encode
Base64-encode the current stream.- Parameters:
alphabet- the alphabet to use- Returns:
- an iterator over the encoded characters
-
base64Encode
Base64-encode the current stream.- Returns:
- an iterator over the encoded characters
-
base32Encode
Base32-encode the current stream.- Parameters:
alphabet- the alphabet to useaddPadding-trueto add trailing padding,falseto leave it off- Returns:
- an iterator over the encoded characters
-
base32Encode
Base32-encode the current stream.- Parameters:
alphabet- the alphabet to use- Returns:
- an iterator over the encoded characters
-
base32Encode
Base32-encode the current stream.- Returns:
- an iterator over the encoded characters
-
hexEncode
Hex-encode the current stream.- Parameters:
toUpperCase-trueto use upper case characters when encoding,falseto use lower case characters- Returns:
- an iterator over the encoded characters
-
hexEncode
Hex-encode the current stream.- Returns:
- an iterator over the encoded characters
-
asUtf8String
Get this byte iterator as a UTF-8 string.- Returns:
- the code point iterator
-
asLatin1String
Get this byte iterator as a Latin-1 string.- Returns:
- the code point iterator
-
contentEquals
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- the other byte iterator- Returns:
trueif the contents are equal,falseotherwise
-
limitedTo
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- the number of bytes- Returns:
- the limited byte iterator
-
delimitedBy
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 returnfalseforhasNext()if the next character in the encapsulated iterator is a delimiter or if the underlying iterator returnsfalseforhasNext().- Parameters:
delims- the byte delimiters- Returns:
- the sub-iterator
-
interleavedWith
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- the interleaving table- Returns:
- the interleaving byte iterator
-
interleavedWith
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- the interleaving table- Returns:
- the interleaving byte iterator
-
drainTo
Drain all the remaining bytes in this iterator to the given stream.- Parameters:
stream- the stream- Returns:
- the same stream
-
drain
public byte[] drain()Drain all the remaining bytes in this iterator.- Returns:
- the remaining bytes as a single array
-
drain
public byte[] drain(int count) Drain up tocountbytes from this iterator, returning the result.- Parameters:
count- the number of bytes to read- Returns:
- the array of consumed bytes (may be smaller than
count)
-
drainAll
Drain exactlycountbytes from this iterator, returning the result.- Parameters:
count- the number of bytes to read- Returns:
- the array of consumed bytes
- Throws:
NoSuchElementException- if there are not enough bytes to fill the array
-
drain
public int drain(byte[] dst) Drains up todst.lengthbytes from this iterator into the givendstarray. An attempt is made to drain as many asdst.lengthbytes, 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- the buffer into which the data is drained- Returns:
- the total number of bytes drained into
dst, always greater or equal to0
-
drain
public int drain(byte[] dst, int offs, int len) Drains up tolenbytes from this iterator into the givendstarray. An attempt is made to drain as many aslenbytes, 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- the buffer into which the data is drainedoffs- the start offset in arraydstat which the data is written.len- the maximum number of bytes to drain- Returns:
- the total number of bytes drained into
dst, always greater or equal to0
-
drainToUtf8
Convenience method to directly drain a certain number of bytes to a UTF-8 string. If fewer thancountbytes are available, only the available bytes will be used to construct the string.- Parameters:
count- the maximum number of bytes to consume- Returns:
- the UTF-8 string
-
drainToLatin1
Convenience method to directly drain a certain number of bytes to a Latin-1 string. If fewer thancountbytes are available, only the available bytes will be used to construct the string.- Parameters:
count- the maximum number of bytes to consume- Returns:
- the Latin-1 string
-
ofBytes
Get a byte iterator for a byte array.- Parameters:
bytes- the array- Returns:
- the byte iterator
-
ofBytes
Get a byte iterator for a byte array.- Parameters:
bytes- the arrayoffs- the array offsetlen- the number of bytes to include- Returns:
- the byte iterator
-
ofBytes
Get a byte iterator for a byte array with interleave.- Parameters:
bytes- the arrayoffs- the array offsetlen- the number of bytes to includeinterleave- the interleave table to use- Returns:
- the byte iterator
-
ofBytes
Get a byte iterator for a byte array with interleave.- Parameters:
bytes- the arrayinterleave- the interleave table to use- Returns:
- the byte iterator
-
ofByteBuffer
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- the byte buffer (must not benull)- Returns:
- the byte iterator (not
null)
-
ofIterators
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- the iterators array (must not benullor containnullelements)- Returns:
- a concatenated iterator
-
asInputStream
Get this iterator as an input stream.- Returns:
- the input stream (not
null)
-