/** * Get this byte iterator as a UTF-8 string. * * @return the code point iterator */ public CodePointIterator asUtf8String() { if (! hasNext()) { return CodePointIterator.EMPTY; } return new Utf8DecodingIterator(this); }
/** * Convert the given OTP hash into hexadecimal format. * * @param otp the OTP hash * @return the hexadecimal value that corresponds to the given OTP hash */ public static String convertToHex(byte[] otp) { return ByteIterator.ofBytes(otp).hexEncode().drainToString(); }
private int seekPrev(int prev) throws NoSuchElementException { if (! iter.hasPrevious()) { return prev; } prev = iter.previous(); if (skip(prev)) { return seekPrev(prev); } iter.next(); return prev; }
/** * Create a DER decoder that will decode values from the given byte array. * * @param buf the byte array to decode */ public DERDecoder(byte[] buf) { this.bi = ByteIterator.ofBytes(buf); }
/** * Hex-decode the current stream. * * @return an iterator over the decoded bytes */ public ByteIterator hexDecode() { if (! hasNext()) return ByteIterator.EMPTY; return new Base16DecodingByteIterator(this); }
/** * Return a copy of this iterator which is limited to the given number of code points after the current one. Advancing * the returned iterator will also advance this one. * * @param size the number of code points * @return the limited code point iterator */ public final CodePointIterator limitedTo(final long size) { if (size <= 0 || ! hasNext()) { return EMPTY; } return new LimitedCodePointIterator(this, size); }
/** * Get a sub-iterator that removes code points based on a <code>predicate</code>. * * @param predicate a {@link IntPredicate} that evaluates the code points that should be skipper. Returning true from the predicate * indicates that the code point must be skipped. * @return the code point iterator */ public CodePointIterator skip(IntPredicate predicate) { if (!hasNext()) { return EMPTY; } return new SkippingCodePointIterator(this, predicate); }
/** * Get this byte iterator as a Latin-1 string. * * @return the code point iterator */ public CodePointIterator asLatin1String() { if (! hasNext()) { return CodePointIterator.EMPTY; } return new Latin1DecodingIterator(this, getIndex()); }
/** * Base64-decode the current stream. * * @return an iterator over the decoded bytes */ public ByteIterator base64Decode() { return base64Decode(Base64Alphabet.STANDARD, true); }
/** * 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. * * @param size the number of bytes * @return the limited byte iterator */ public final ByteIterator limitedTo(final int size) { if (size <= 0 || ! hasNext()) { return EMPTY; } return new LimitedByteIterator(this, size); }
/** * Get a code point iterator for a character array. * * @param chars the array * @return the code point iterator */ public static CodePointIterator ofChars(final char[] chars) { return ofChars(chars, 0, chars.length); }
/** * Get a code point iterator for a UTF-8 encoded byte array. * * @param bytes the array * @return the code point iterator */ public static CodePointIterator ofUtf8Bytes(final byte[] bytes) { return ofUtf8Bytes(bytes, 0, bytes.length); }
/** * Base32-encode the current stream. * * @param alphabet the alphabet to use * @return an iterator over the encoded characters */ public CodePointIterator base32Encode(final Base32Alphabet alphabet) { return base32Encode(alphabet, true); }
/** * Drain all the remaining code points in this iterator to the given string builder, * inserting the given delimiter after every {@code n} code points. * * @param b the string builder * @param delim the delimiter * @param n the number of code points between each delimiter * @return the same string builder */ public StringBuilder drainTo(StringBuilder b, final int delim, final int n) { return drainTo(b, null, delim, n); }
/** * Base32-decode the current stream. * * @return an iterator over the decoded bytes */ public ByteIterator base32Decode() { return base32Decode(Base32Alphabet.STANDARD, true); }
/** * 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. * * @param table the interleaving table * @return the interleaving byte iterator */ public ByteIterator interleavedWith(final byte[] table) { return new ByteTableTranslatingByteIterator(this, table); }
/** * Get a byte iterator over the UTF-8 encoding of this code point iterator. * * @param escapeNul {@code true} to escape NUL (0) characters as two bytes, {@code false} to encode them as one byte * @return the byte iterator */ public ByteIterator asUtf8(final boolean escapeNul) { return new Utf8EncodingByteIterator(this, escapeNul); }