/** * Encodes a byte array into Base64 notation. Does not GZip-compress data. * * @param source The data to convert * @return the encoded bytes */ public static String encodeBytes( byte[] source ) { return encodeBytes(source, 0, source.length, NO_OPTIONS); }
/** * Encodes a byte array into Base64 notation. Does not GZip-compress data. * * @param source The data to convert * @param off Offset in array where conversion should begin * @param len Length of data * @return the encoded bytes */ public static String encodeBytes( byte[] source, int off, int len ) { return encodeBytes(source, off, len, NO_OPTIONS); }
/** * Encodes a byte array into Base64 notation. * <p> * Valid options: * * <pre> * GZIP: gzip-compresses object before encoding it. * DONT_BREAK_LINES: don't break lines at 76 characters * <i>Note: Technically, this makes your encoding non-compliant.</i> * </pre> * <p> * Example: <code>encodeBytes( myData, Base64.GZIP )</code> or * <p> * Example: <code>encodeBytes( myData, Base64.GZIP | Base64.DONT_BREAK_LINES )</code> * * @param source The data to convert * @param options Specified options * @return the encoded bytes * @see Base64#GZIP * @see Base64#DONT_BREAK_LINES */ public static String encodeBytes( byte[] source, int options ) { return encodeBytes(source, 0, source.length, options); }
/** * {@inheritDoc} * * @see org.jboss.dna.common.text.TextEncoder#encode(java.lang.String) */ public String encode( String text ) { try { byte[] hash = SecureHash.getHash(algorithm, text.getBytes()); String result = Base64.encodeBytes(hash); return result.length() < maxLength ? result : result.substring(0, maxLength); } catch (NoSuchAlgorithmException e) { return text; } }