/** * Same as encodeBytes, except uses a filesystem / URL friendly set of characters, * replacing / with ~, and + with - */ private static String safeEncode(byte[] source, int off, int len, boolean useStandardAlphabet) { if (len + off > source.length) throw new ArrayIndexOutOfBoundsException("Trying to encode too much! source.len=" + source.length + " off=" + off + " len=" + len); StringBuilder buf = new StringBuilder(len * 4 / 3); if (useStandardAlphabet) encodeBytes(source, off, len, false, buf, ALPHABET); else encodeBytes(source, off, len, false, buf, ALPHABET_ALT); return buf.toString(); }