/** * Get a code point iterator for a UTF-8 encoded array. * * @param bytes the array * @param offs the array offset * @param len the number of characters to include * @return the code point iterator */ public static CodePointIterator ofUtf8Bytes(final byte[] bytes, final int offs, final int len) { if (len <= 0) { return EMPTY; } return ByteIterator.ofBytes(bytes, offs, len).asUtf8String(); }
public int read(final byte[] b) throws IOException { final int result = drain(b); /* As drain(byte[] dst) never returns a negative result, * we need to perform some additional checks to honor * the contract of InputStream.read(byte[]). Citing from its JavaDoc: * * If the length of <code>b</code> is zero, then no bytes are read and * <code>0</code> is returned; otherwise, there is an attempt to read at * least one byte. If no byte is available because the stream is at the * end of the file, the value <code>-1</code> is returned; otherwise, at * least one byte is read and stored into <code>b</code>. */ return result == 0 ? (b.length == 0 ? 0 : -1) : result; }
public ByteStringBuilder append(ByteIterator iterator) { return iterator.appendTo(this); }
/** * Get a code point iterator for a ISO-8859-1 (Latin-1) encoded array. * * @param bytes the array * @param offs the array offset * @param len the number of characters to include * @return the code point iterator */ public static CodePointIterator ofLatin1Bytes(final byte[] bytes, final int offs, final int len) { if (len <= 0) { return EMPTY; } return ByteIterator.ofBytes(bytes, offs, len).asLatin1String(); }
/** * Get a byte iterator for a byte array. * * @param bytes the array * @return the byte iterator */ public static ByteIterator ofBytes(final byte... bytes) { return ofBytes(bytes, 0, bytes.length); }
final String b64Password = getProperty(properties, prefix + PROPERTY_KEY_PASSWORD_BASE64, null, expandPasswords); if (b64Password != null) { setPassword(CodePointIterator.ofString(b64Password).base64Decode().asUtf8String().drainToString()); } else { final String password = getProperty(properties, prefix + PROPERTY_KEY_PASSWORD, null, expandPasswords);
public boolean hasPrev() { return offset > 0 && ByteIterator.this.hasPrev(); }
public boolean hasNext() { return ByteIterator.this.hasNext(); }
@Override public boolean verifyCertificate(X509Certificate certificate, Attributes attributes) throws NamingException, RealmUnavailableException { Attribute attribute = attributes.get(ldapAttribute); if (attribute == null) return false; final int size = attribute.size(); try { MessageDigest md = MessageDigest.getInstance(algorithm); String digest = ByteIterator.ofBytes(md.digest(certificate.getEncoded())).hexEncode(true).drainToString(); for (int i = 0; i < size; i++) { Object attrDigest = attribute.get(i); if (attrDigest != null){ if (digest.equalsIgnoreCase((String) attrDigest)) { return true; } } } } catch (NoSuchAlgorithmException | CertificateEncodingException e) { throw new RealmUnavailableException(e); } return false; } }
/** * 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); }
/** * Base64-encode the current stream. * * @param alphabet the alphabet to use * @return an iterator over the encoded characters */ public CodePointIterator base64Encode(final Base64Alphabet alphabet) { return base64Encode(alphabet, true); }
/** * Drain all the remaining bytes in this iterator. * * @return the remaining bytes as a single array */ public byte[] drain() { return drainTo(new ByteArrayOutputStream()).toByteArray(); }
/** * Get a byte iterator for a byte array with interleave. * * @param bytes the array * @param interleave the interleave table to use * @return the byte iterator */ public static ByteIterator ofBytes(final byte[] bytes, final int[] interleave) { return ofBytes(bytes, 0, bytes.length, interleave); }