/** * Drain all the remaining code points in this iterator to the given string builder, * inserting the given prefix before every {@code n} code points. * * @param b the string builder * @param prefix the prefix * @param n the number of code points between each prefix * @return the same string builder */ public StringBuilder drainTo(StringBuilder b, final String prefix, final int n) { return drainTo(b, prefix, -1, n); }
/** * 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); }
/** * Drain all the remaining code points in this iterator to a new string, * inserting the given prefix before every {@code n} code points. * * @param prefix the prefix * @param n the number of code points between each prefix * @return the string */ public String drainToString(final String prefix, final int n) { return hasNext() ? drainTo(new StringBuilder(), prefix, -1, n).toString() : ""; }
/** * Drain all the remaining code points in this iterator to a new string. * * @return the string */ public String drainToString() { return hasNext() ? drainTo(new StringBuilder()).toString() : ""; }
/** * Drain all the remaining code points in this iterator to a new string, * inserting the given delimiter after every {@code n} code points. * * @param delim the delimiter * @param n the number of code points between each delimiter * @return the string */ public String drainToString(final int delim, final int n) { return hasNext() ? drainTo(new StringBuilder(), null, delim, n).toString() : ""; }
/** * Drain all the remaining code points in this iterator to a new string, * inserting the given prefix and delimiter before and after every {@code n} * code points, respectively. * * @param prefix the prefix * @param delim the delimiter * @param n the number of code points between each prefix and delimiter * @return the string */ public String drainToString(final String prefix, final int delim, final int n) { return hasNext() ? drainTo(new StringBuilder(), prefix, delim, n).toString() : ""; }
private String calculateNewAlias(String alias, Class<? extends Credential> credentialType, String algorithm, AlgorithmParameterSpec parameterSpec) throws CredentialStoreException { final StringBuilder b = new StringBuilder(64 + alias.length()); b.append(alias.toLowerCase(Locale.ROOT)); b.append('/'); b.append(credentialType.getSimpleName().toLowerCase(Locale.ROOT)); b.append('/'); if (algorithm != null) { b.append(algorithm.toLowerCase(Locale.ROOT)); b.append('/'); if (parameterSpec != null) try { final AlgorithmParameters algorithmParameters = AlgorithmParameters.getInstance(algorithm); algorithmParameters.init(parameterSpec); ByteIterator.ofBytes(algorithmParameters.getEncoded()).base32Encode(Base32Alphabet.LOWERCASE, false).drainTo(b); } catch (NoSuchAlgorithmException | InvalidParameterSpecException | IOException e) { throw log.cannotWriteCredentialToStore(e); } } else { b.append('/'); } return b.toString(); }
static String[] realmListPropertyToArray(String realmList, int escapeCharacter, int... delims) { if (realmList == null) { return null; } final int[] escapeCharacterAndDelims = Arrays.copyOf(delims, delims.length + 1); escapeCharacterAndDelims[escapeCharacterAndDelims.length - 1] = escapeCharacter; final CodePointIterator cpi = CodePointIterator.ofString(realmList); final CodePointIterator di = cpi.delimitedBy(escapeCharacterAndDelims); final ArrayList<String> realms = new ArrayList<>(); StringBuilder realm = new StringBuilder(); while (cpi.hasNext()) { if (di.hasNext()) { di.drainTo(realm); } else { if (cpi.peekNext() == escapeCharacter) { cpi.next(); // skip the escape character if (cpi.hasNext()) { realm.append((char) cpi.next()); } } else { // reached the end of a realm name realms.add(realm.toString()); skipDelims(di, cpi, delims); realm = new StringBuilder(); } } } realms.add(realm.toString()); return realms.toArray(new String[realms.size()]); }
static String arrayToRealmListProperty(String[] realms, int escapeCharacter, int... delims) { if (realms == null) { return null; } final int[] escapeCharacterAndDelims = Arrays.copyOf(delims, delims.length + 1); escapeCharacterAndDelims[escapeCharacterAndDelims.length - 1] = escapeCharacter; StringBuilder realmList = new StringBuilder(); for (int i = 0; i < realms.length; i++) { if (i != 0) { addDelims(realmList, delims); } CodePointIterator cpi = CodePointIterator.ofString(realms[i]); CodePointIterator di = cpi.delimitedBy(escapeCharacterAndDelims); while (cpi.hasNext()) { if (di.hasNext()) { di.drainTo(realmList); } else { realmList.append((char) escapeCharacter); // escape the delimiter or escape character realmList.append((char) cpi.next()); } } } return realmList.toString(); }
/** * Convert the given hexadecimal OTP value into a hash. * * @param otp the OTP in hexadecimal format * @return the OTP hash that corresponds to the given hexadecimal value * @throws SaslException if an error occurs while parsing the hexadecimal value */ public static byte[] convertFromHex(String otp) throws SaslException { final CodePointIterator cpi = CodePointIterator.ofString(otp); final CodePointIterator di = cpi.delimitedBy(DELIMS); // Remove any white space final StringBuilder sb = new StringBuilder(); while (di.hasNext()) { di.drainTo(sb); skipDelims(di, cpi); } return CodePointIterator.ofString(sb.toString()).hexDecode().drain(); }
/** * Drain all the remaining code points in this iterator to the given string builder, * inserting the given prefix before every {@code n} code points. * * @param b the string builder * @param prefix the prefix * @param n the number of code points between each prefix * @return the same string builder */ public StringBuilder drainTo(StringBuilder b, final String prefix, final int n) { return drainTo(b, prefix, -1, n); }
/** * 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); }
/** * 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); }
/** * Drain all the remaining code points in this iterator to the given string builder, * inserting the given prefix before every {@code n} code points. * * @param b the string builder * @param prefix the prefix * @param n the number of code points between each prefix * @return the same string builder */ public StringBuilder drainTo(StringBuilder b, final String prefix, final int n) { return drainTo(b, prefix, -1, n); }
/** * Drain all the remaining code points in this iterator to a new string, * inserting the given prefix before every {@code n} code points. * * @param prefix the prefix * @param n the number of code points between each prefix * @return the string */ public String drainToString(final String prefix, final int n) { return hasNext() ? drainTo(new StringBuilder(), prefix, -1, n).toString() : ""; }
/** * Drain all the remaining code points in this iterator to a new string, * inserting the given delimiter after every {@code n} code points. * * @param delim the delimiter * @param n the number of code points between each delimiter * @return the string */ public String drainToString(final int delim, final int n) { return hasNext() ? drainTo(new StringBuilder(), null, delim, n).toString() : ""; }
/** * Drain all the remaining code points in this iterator to a new string. * * @return the string */ public String drainToString() { return hasNext() ? drainTo(new StringBuilder()).toString() : ""; }
/** * Drain all the remaining code points in this iterator to a new string, * inserting the given prefix before every {@code n} code points. * * @param prefix the prefix * @param n the number of code points between each prefix * @return the string */ public String drainToString(final String prefix, final int n) { return hasNext() ? drainTo(new StringBuilder(), prefix, -1, n).toString() : ""; }
/** * Drain all the remaining code points in this iterator to a new string. * * @return the string */ public String drainToString() { return hasNext() ? drainTo(new StringBuilder()).toString() : ""; }
/** * Drain all the remaining code points in this iterator to a new string, * inserting the given delimiter after every {@code n} code points. * * @param delim the delimiter * @param n the number of code points between each delimiter * @return the string */ public String drainToString(final int delim, final int n) { return hasNext() ? drainTo(new StringBuilder(), null, delim, n).toString() : ""; }