Class ByteIterator

    • Field Detail

      • EMPTY

        public static final ByteIterator EMPTY
        The empty byte iterator.
    • Method Detail

      • hasNext

        public abstract boolean hasNext()
        Determine if there are more bytes after the current byte.
        Specified by:
        hasNext in interface BiDirIntIterator
        Specified by:
        hasNext in interface IntIterator
        Returns:
        true if there are more bytes, false otherwise
      • hasPrevious

        public abstract boolean hasPrevious()
        Determine if there are more bytes before the current byte.
        Specified by:
        hasPrevious in interface BiDirIntIterator
        Returns:
        true if there are more bytes, false otherwise
      • next

        public abstract int next()
                          throws java.util.NoSuchElementException
        Get the next byte.
        Specified by:
        next in interface BiDirIntIterator
        Specified by:
        next in interface IntIterator
        Returns:
        the next byte
        Throws:
        java.util.NoSuchElementException - if hasNext() returns false
      • peekNext

        public abstract int peekNext()
                              throws java.util.NoSuchElementException
        Peek at the next byte without advancing.
        Specified by:
        peekNext in interface BiDirIntIterator
        Specified by:
        peekNext in interface IntIterator
        Returns:
        the next byte
        Throws:
        java.util.NoSuchElementException - if hasNext() returns false
      • previous

        public abstract int previous()
                              throws java.util.NoSuchElementException
        Get the previous byte.
        Specified by:
        previous in interface BiDirIntIterator
        Returns:
        the previous byte
        Throws:
        java.util.NoSuchElementException - if hasPrevious() returns false
      • peekPrevious

        public abstract int peekPrevious()
                                  throws java.util.NoSuchElementException
        Peek at the previous byte without moving backwards.
        Specified by:
        peekPrevious in interface BiDirIntIterator
        Returns:
        the previous byte
        Throws:
        java.util.NoSuchElementException - if hasPrevious() returns false
      • getIndex

        public abstract long getIndex()
        Get the current offset, in bytes.
        Specified by:
        getIndex in interface IndexIterator
        Returns:
        the byte offset
      • getBE16

        public int getBE16()
                    throws java.util.NoSuchElementException
        Throws:
        java.util.NoSuchElementException
      • getBE32

        public int getBE32()
                    throws java.util.NoSuchElementException
        Throws:
        java.util.NoSuchElementException
      • getBE64

        public long getBE64()
                     throws java.util.NoSuchElementException
        Throws:
        java.util.NoSuchElementException
      • getLE16

        public int getLE16()
                    throws java.util.NoSuchElementException
        Throws:
        java.util.NoSuchElementException
      • getLE32

        public int getLE32()
                    throws java.util.NoSuchElementException
        Throws:
        java.util.NoSuchElementException
      • getLE64

        public long getLE64()
                     throws java.util.NoSuchElementException
        Throws:
        java.util.NoSuchElementException
      • getPackedBE32

        public int getPackedBE32()
                          throws java.util.NoSuchElementException
        Throws:
        java.util.NoSuchElementException
      • getPackedBE64

        public long getPackedBE64()
                           throws java.util.NoSuchElementException
        Throws:
        java.util.NoSuchElementException
      • update

        public void update​(java.security.MessageDigest digest)
      • doFinal

        public ByteIterator doFinal​(java.security.MessageDigest digest)
      • update

        public void update​(javax.crypto.Mac mac)
      • doFinal

        public ByteIterator doFinal​(javax.crypto.Mac mac)
      • update

        public void update​(java.security.Signature signature)
                    throws java.security.SignatureException
        Throws:
        java.security.SignatureException
      • sign

        public ByteIterator sign​(java.security.Signature signature)
                          throws java.security.SignatureException
        Throws:
        java.security.SignatureException
      • verify

        public boolean verify​(java.security.Signature signature)
                       throws java.security.SignatureException
        Throws:
        java.security.SignatureException
      • base64Encode

        public CodePointIterator base64Encode​(Base64Alphabet alphabet,
                                              boolean addPadding)
        Base64-encode the current stream.
        Parameters:
        alphabet - the alphabet to use
        addPadding - true to add trailing padding, false to leave it off
        Returns:
        an iterator over the encoded characters
      • base64Encode

        public CodePointIterator base64Encode​(Base64Alphabet alphabet)
        Base64-encode the current stream.
        Parameters:
        alphabet - the alphabet to use
        Returns:
        an iterator over the encoded characters
      • base64Encode

        public CodePointIterator base64Encode()
        Base64-encode the current stream.
        Returns:
        an iterator over the encoded characters
      • base32Encode

        public CodePointIterator base32Encode​(Base32Alphabet alphabet,
                                              boolean addPadding)
        Base32-encode the current stream.
        Parameters:
        alphabet - the alphabet to use
        addPadding - true to add trailing padding, false to leave it off
        Returns:
        an iterator over the encoded characters
      • base32Encode

        public CodePointIterator base32Encode​(Base32Alphabet alphabet)
        Base32-encode the current stream.
        Parameters:
        alphabet - the alphabet to use
        Returns:
        an iterator over the encoded characters
      • base32Encode

        public CodePointIterator base32Encode()
        Base32-encode the current stream.
        Returns:
        an iterator over the encoded characters
      • hexEncode

        public CodePointIterator hexEncode​(boolean toUpperCase)
        Hex-encode the current stream.
        Parameters:
        toUpperCase - true to use upper case characters when encoding, false to use lower case characters
        Returns:
        an iterator over the encoded characters
      • hexEncode

        public CodePointIterator hexEncode()
        Hex-encode the current stream.
        Returns:
        an iterator over the encoded characters
      • asUtf8String

        public CodePointIterator asUtf8String()
        Get this byte iterator as a UTF-8 string.
        Returns:
        the code point iterator
      • asLatin1String

        public CodePointIterator asLatin1String()
        Get this byte iterator as a Latin-1 string.
        Returns:
        the code point iterator
      • contentEquals

        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 - the other byte iterator
        Returns:
        true if the contents are equal, false otherwise
      • limitedTo

        public final ByteIterator limitedTo​(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 - the number of bytes
        Returns:
        the limited byte iterator
      • delimitedBy

        public final ByteIterator delimitedBy​(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 - the byte delimiters
        Returns:
        the sub-iterator
      • interleavedWith

        public ByteIterator interleavedWith​(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 - the interleaving table
        Returns:
        the interleaving byte iterator
      • interleavedWith

        public ByteIterator interleavedWith​(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 - the interleaving table
        Returns:
        the interleaving byte iterator
      • drainTo

        public java.io.ByteArrayOutputStream drainTo​(java.io.ByteArrayOutputStream stream)
        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 to count bytes 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

        public byte[] drainAll​(int count)
                        throws java.util.NoSuchElementException
        Drain exactly count bytes from this iterator, returning the result.
        Parameters:
        count - the number of bytes to read
        Returns:
        the array of consumed bytes
        Throws:
        java.util.NoSuchElementException - if there are not enough bytes to fill the array
      • drain

        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 - the buffer into which the data is drained
        Returns:
        the total number of bytes drained into dst, always greater or equal to 0
      • drain

        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 - the buffer into which the data is drained
        offs - the start offset in array dst at 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 to 0
      • drainToUtf8

        public java.lang.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 - the maximum number of bytes to consume
        Returns:
        the UTF-8 string
      • drainToLatin1

        public java.lang.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 - the maximum number of bytes to consume
        Returns:
        the Latin-1 string
      • ofBytes

        public static ByteIterator ofBytes​(byte... bytes)
        Get a byte iterator for a byte array.
        Parameters:
        bytes - the array
        Returns:
        the byte iterator
      • ofBytes

        public static ByteIterator ofBytes​(byte[] bytes,
                                           int offs,
                                           int len)
        Get a byte iterator for a byte array.
        Parameters:
        bytes - the array
        offs - the array offset
        len - the number of bytes to include
        Returns:
        the byte iterator
      • ofBytes

        public static ByteIterator ofBytes​(byte[] bytes,
                                           int offs,
                                           int len,
                                           int[] interleave)
        Get a byte iterator for a byte array with interleave.
        Parameters:
        bytes - the array
        offs - the array offset
        len - the number of bytes to include
        interleave - the interleave table to use
        Returns:
        the byte iterator
      • ofBytes

        public static ByteIterator ofBytes​(byte[] bytes,
                                           int[] interleave)
        Get a byte iterator for a byte array with interleave.
        Parameters:
        bytes - the array
        interleave - the interleave table to use
        Returns:
        the byte iterator
      • ofByteBuffer

        public static ByteIterator ofByteBuffer​(java.nio.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 - the byte buffer (must not be null)
        Returns:
        the byte iterator (not null)
      • ofIterators

        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 - the iterators array (must not be null or contain null elements)
        Returns:
        a concatenated iterator
      • asInputStream

        public final java.io.InputStream asInputStream()
        Get this iterator as an input stream.
        Returns:
        the input stream (not null)