/** * Decodes data from Base64 notation, automatically detecting gzip-compressed data and decompressing it. * * @param s the string to decode * @return the decoded data */ public static byte[] decode( String s ) { return decode(s, NO_OPTIONS); }
/** * Encodes content of the supplied InputStream into Base64 notation. Does not GZip-compress data. * * @param source The data to convert * @return the encoded bytes */ public static String encode( java.io.InputStream source ) { return encode(source, NO_OPTIONS); }
/** * Encodes up to the first three bytes of array <var>threeBytes</var> and returns a four-byte array in Base64 notation. The * actual number of significant bytes in your array is given by <var>numSigBytes</var>. The array <var>threeBytes</var> needs * only be as big as <var>numSigBytes</var>. Code can reuse a byte array by passing a four-byte array as <var>b4</var>. * * @param b4 A reusable byte array to reduce array instantiation * @param threeBytes the array to convert * @param numSigBytes the number of significant bytes in your array * @param options The options to use in this operation * @return four byte array in Base64 notation. */ protected static byte[] encode3to4( byte[] b4, byte[] threeBytes, int numSigBytes, int options ) { encode3to4(threeBytes, 0, numSigBytes, b4, 0, options); return b4; }
if (position >= bufferLength) // Enough to encode. out.write(encode3to4(b4, buffer, bufferLength, options)); buffer[position++] = (byte)theByte; if (position >= bufferLength) { // Enough to output. int len = Base64.decode4to3(buffer, 0, b4, 0, options); out.write(b4, 0, len);
int len, int options ) { byte[] DECODABET = getDecodabet(options); if (b4Posn > 3) { outBuffPosn += decode4to3(b4, 0, outBuff, outBuffPosn, options); b4Posn = 0;
/** * 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); }
this.lineLength = 0; this.options = options; // Record for later, mostly to determine which alphabet to use this.decodabet = getDecodabet(options);
/** * Serializes an object and returns the Base64-encoded version of that serialized object. If the object cannot be serialized * or there is another error, the method will return <tt>null</tt>. The object is not GZip-compressed before being encoded. * * @param serializableObject The object to encode * @return The Base64-encoded object * @throws IOException if there is an IOException while serializing */ public static String encodeObject( java.io.Serializable serializableObject ) throws IOException { return encodeObject(serializableObject, NO_OPTIONS); }
int destOffset, int options ) { byte[] ALPHABET = getAlphabet(options);
encode3to4(b3, 0, numBinaryBytes, buffer, 0, options); position = 0; numSigBytes = 4; numSigBytes = decode4to3(b4, 0, buffer, 0, options); position = 0; } else if (i == 0) {
/** * 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); }
this.b4 = new byte[4]; this.options = options; this.decodabet = getDecodabet(options);
byte[] objBytes = decode(encodedObject);
/** * Return the JSON-compatible string representation of the given property value. If the value is a {@link PropertyType#BINARY * binary} value, then this method returns the Base-64 encoding of that value. Otherwise, it just returns the string * representation of the value. * * @param value the property value; may not be null * @return the string representation of the value * @throws RepositoryException if there is a problem accessing the value */ private String jsonEncodedStringFor( Value value ) throws RepositoryException { // Encode the binary value in Base64 ... InputStream stream = value.getStream(); try { return Base64.encode(stream); } finally { if (stream != null) { try { stream.close(); } catch (IOException e) { // Error accessing the value, so throw this ... throw new RepositoryException(e); } } } }
/** * 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); }
/** * Method added by PHIL. [Thanks, PHIL. -Rob] This pads the buffer without closing the stream. * * @throws IOException */ public void flushBase64() throws IOException { if (position > 0) { if (encode) { out.write(encode3to4(b4, buffer, position, options)); position = 0; } else { throw new IOException("Base64 input not properly padded."); } } }
int destOffset, int options ) { byte[] DECODABET = getDecodabet(options);
private Value decodeValue( String encodedValue, ValueFactory valueFactory ) throws RepositoryException { byte[] binaryValue = Base64.decode(encodedValue); InputStream stream = new ByteArrayInputStream(binaryValue); try { return valueFactory.createValue(stream); } finally { try { stream.close(); } catch (IOException e) { // Error accessing the value, so throw this ... throw new RepositoryException(e); } } }
/** * {@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; } }
int lineLength = 0; for (; d < len2; d += 3, e += 4) { encode3to4(source, d + off, 3, outBuff, e, options); encode3to4(source, d + off, len - d, outBuff, e, options); e += 4;