/** * Decodes data from Base64 notation, automatically detecting gzip-compressed data and decompressing it. * * @param s * the string to decode * @return the decoded data * @since 1.4 */ public static byte[] decode(final String s) { return decode(s, NO_OPTIONS); }
/** * Encodes or decodes two files from the command line; <strong>feel free to delete this method (in fact you probably * should) if you're embedding this code into a larger program.</strong> */ public static void main(final String[] args) { if (args.length < 3) { usage("Not enough arguments."); } else { final String flag = args[0]; final String infile = args[1]; final String outfile = args[2]; if ("-e".equals(flag)) { Base64.encodeFileToFile(infile, outfile); } else if ("-d".equals(flag)) { Base64.decodeFileToFile(infile, outfile); } else { usage("Unknown flag: " + flag); } // end else } // end else } // end main
/** * Attempts to decode Base64 data and deserialize a Java Object within. Returns <tt>null</tt> if there was an error. * * @param encodedObject * The Base64 data to decode * @return The decoded and deserialized object * @since 1.5 */ public static Object decodeToObject(final String encodedObject) { return decodeToObject(encodedObject, NO_OPTIONS); }
/** * Encodes a byte array into Base64 notation. Does not GZip-compress data. * * @param source * The data to convert * @since 1.4 */ public static String encodeBytes(final byte[] source) { return encodeBytes(source, 0, source.length, NO_OPTIONS); } // end encodeBytes
final byte[] decodabet = getDecodabet(options); b4[b4Posn++] = sbiCrop; if (b4Posn > 3) { outBuffPosn += decode4to3(b4, 0, outBuff, outBuffPosn, options); b4Posn = 0;
/** * 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 * @return four byte array in Base64 notation. * @since 1.5.1 */ private static byte[] encode3to4(final byte[] b4, final byte[] threeBytes, final int numSigBytes, final int options) { encode3to4(threeBytes, 0, numSigBytes, b4, 0, options); return b4; } // end encode3to4
/** * 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 * @since 1.4 */ public static String encodeObject(final Serializable serializableObject) { return encodeObject(serializableObject, NO_OPTIONS); } // end encodeObject
final byte[] decodeabet = getDecodabet(options);
final byte[] alphabet = getAlphabet(options);
/** * Encodes a byte array into Base64 notation. Does not GZip-compress data. * * @param source * The data to convert * @since 1.4 */ public static String encodeBytes(final byte[] source) { return encodeBytes(source, 0, source.length, NO_OPTIONS); } // end encodeBytes
byte[] decodabet = getDecodabet(options); b4[b4Posn++] = sbiCrop; if (b4Posn > 3) { outBuffPosn += decode4to3(b4, 0, outBuff, outBuffPosn, options); b4Posn = 0;
/** * 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 * @return four byte array in Base64 notation. * @since 1.5.1 */ private static byte[] encode3to4(final byte[] b4, final byte[] threeBytes, final int numSigBytes, final int options) { encode3to4(threeBytes, 0, numSigBytes, b4, 0, options); return b4; } // end encode3to4
/** * 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 * @since 1.4 */ public static String encodeObject(final Serializable serializableObject) { return encodeObject(serializableObject, NO_OPTIONS); } // end encodeObject
final byte[] decodeabet = getDecodabet(options);
final byte[] alphabet = getAlphabet(options);
/** * Encodes or decodes two files from the command line; <strong>feel free to delete this method (in fact you probably * should) if you're embedding this code into a larger program.</strong> */ public static void main(final String[] args) { if (args.length < 3) { usage("Not enough arguments."); } else { final String flag = args[0]; final String infile = args[1]; final String outfile = args[2]; if ("-e".equals(flag)) { Base64.encodeFileToFile(infile, outfile); } else if ("-d".equals(flag)) { Base64.decodeFileToFile(infile, outfile); } else { usage("Unknown flag: " + flag); } // end else } // end else } // end main
/** * Encodes a byte array into Base64 notation. Does not GZip-compress data. * * @param source * The data to convert * @since 1.4 */ public static String encodeBytes(byte[] source) { return encodeBytes(source, 0, source.length, NO_OPTIONS); } // end encodeBytes
/** * Decodes data from Base64 notation, automatically detecting gzip-compressed data and decompressing it. * * @param s * the string to decode * @return the decoded data * @since 1.4 */ public static byte[] decode(final String s) { return decode(s, NO_OPTIONS); }
final byte[] decodabet = getDecodabet(options); b4[b4Posn++] = sbiCrop; if (b4Posn > 3) { outBuffPosn += decode4to3(b4, 0, outBuff, outBuffPosn, options); b4Posn = 0;
/** * 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 * @return four byte array in Base64 notation. * @since 1.5.1 */ private static byte[] encode3to4(byte[] b4, byte[] threeBytes, int numSigBytes, int options) { encode3to4(threeBytes, 0, numSigBytes, b4, 0, options); return b4; } // end encode3to4