Dépôt officiel du code source de l'ERP OpenConcerto
/trunk/OpenConcerto/src/org/openconcerto/utils/Base64.java |
---|
35,11 → 35,11 |
* change some method calls that you were making to support the new options format (<tt>int</tt>s |
* that you "OR" together).</li> |
* <li>v1.5.1 - Fixed bug when decompressing and decoding to a byte[] using |
* <tt>decode( String s, boolean gzipCompressed )</tt>. Added the ability to "suspend" encoding |
* in the Output Stream so you can turn on and off the encoding if you need to embed base64 data in |
* an otherwise "normal" stream (like an XML file).</li> |
* <li>v1.5 - Output stream pases on flush() command but doesn't do anything itself. This helps |
* when using GZIP streams. Added the ability to GZip-compress objects before encoding them.</li> |
* <tt>decode( String s, boolean gzipCompressed )</tt>. Added the ability to "suspend" encoding in |
* the Output Stream so you can turn on and off the encoding if you need to embed base64 data in an |
* otherwise "normal" stream (like an XML file).</li> |
* <li>v1.5 - Output stream pases on flush() command but doesn't do anything itself. This helps when |
* using GZIP streams. Added the ability to GZip-compress objects before encoding them.</li> |
* <li>v1.4 - Added helper methods to read/write files.</li> |
* <li>v1.3.6 - Fixed OutputStream.flush() so that 'position' is reset.</li> |
* <li>v1.3.5 - Added flag to turn on and off line breaks. Fixed bug in input stream where last |
50,9 → 50,9 |
* |
* <p> |
* I am placing this code in the Public Domain. Do with it as you will. This software comes with no |
* guarantees or warranties but with plenty of well-wishing instead! Please visit <a |
* href="http://iharder.net/base64">http://iharder.net/base64</a> periodically to check for updates |
* or to contribute improvements. |
* guarantees or warranties but with plenty of well-wishing instead! Please visit |
* <a href="http://iharder.net/base64">http://iharder.net/base64</a> periodically to check for |
* updates or to contribute improvements. |
* </p> |
* |
* @author Robert Harder |
95,11 → 95,11 |
/** The 64 valid Base64 values. */ |
private final static byte[] ALPHABET; |
private final static byte[] _NATIVE_ALPHABET = /* May be something funny like EBCDIC */ |
{ (byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F', (byte) 'G', (byte) 'H', (byte) 'I', (byte) 'J', (byte) 'K', (byte) 'L', (byte) 'M', (byte) 'N', (byte) 'O', (byte) 'P', |
(byte) 'Q', (byte) 'R', (byte) 'S', (byte) 'T', (byte) 'U', (byte) 'V', (byte) 'W', (byte) 'X', (byte) 'Y', (byte) 'Z', (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd', (byte) 'e', |
(byte) 'f', (byte) 'g', (byte) 'h', (byte) 'i', (byte) 'j', (byte) 'k', (byte) 'l', (byte) 'm', (byte) 'n', (byte) 'o', (byte) 'p', (byte) 'q', (byte) 'r', (byte) 's', (byte) 't', |
(byte) 'u', (byte) 'v', (byte) 'w', (byte) 'x', (byte) 'y', (byte) 'z', (byte) '0', (byte) '1', (byte) '2', (byte) '3', (byte) '4', (byte) '5', (byte) '6', (byte) '7', (byte) '8', |
(byte) '9', (byte) '+', (byte) '/' }; |
{ (byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F', (byte) 'G', (byte) 'H', (byte) 'I', (byte) 'J', (byte) 'K', (byte) 'L', (byte) 'M', (byte) 'N', (byte) 'O', |
(byte) 'P', (byte) 'Q', (byte) 'R', (byte) 'S', (byte) 'T', (byte) 'U', (byte) 'V', (byte) 'W', (byte) 'X', (byte) 'Y', (byte) 'Z', (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd', |
(byte) 'e', (byte) 'f', (byte) 'g', (byte) 'h', (byte) 'i', (byte) 'j', (byte) 'k', (byte) 'l', (byte) 'm', (byte) 'n', (byte) 'o', (byte) 'p', (byte) 'q', (byte) 'r', (byte) 's', |
(byte) 't', (byte) 'u', (byte) 'v', (byte) 'w', (byte) 'x', (byte) 'y', (byte) 'z', (byte) '0', (byte) '1', (byte) '2', (byte) '3', (byte) '4', (byte) '5', (byte) '6', (byte) '7', |
(byte) '8', (byte) '9', (byte) '+', (byte) '/' }; |
/** Determine which ALPHABET to use. */ |
static { |
167,7 → 167,8 |
* 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>. |
* <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 |
181,13 → 182,13 |
} // end encode3to4 |
/** |
* Encodes up to three bytes of the array <var>source</var> and writes the resulting four |
* Base64 bytes to <var>destination</var>. The source and destination arrays can be manipulated |
* Encodes up to three bytes of the array <var>source</var> and writes the resulting four Base64 |
* bytes to <var>destination</var>. The source and destination arrays can be manipulated |
* anywhere along their length by specifying <var>srcOffset</var> and <var>destOffset</var>. |
* This method does not check to make sure your arrays are large enough to accomodate |
* <var>srcOffset</var> + 3 for the <var>source</var> array or <var>destOffset</var> + 4 for |
* the <var>destination</var> array. The actual number of significant bytes in your array is |
* given by <var>numSigBytes</var>. |
* <var>srcOffset</var> + 3 for the <var>source</var> array or <var>destOffset</var> + 4 for the |
* <var>destination</var> array. The actual number of significant bytes in your array is given |
* by <var>numSigBytes</var>. |
* |
* @param source the array to convert |
* @param srcOffset the index where conversion begins |
342,9 → 343,13 |
* @since 1.4 |
*/ |
public static String encodeBytes(byte[] source) { |
return encodeBytes(source, 0, source.length, NO_OPTIONS); |
return encodeBytes(source, 0, source.length, DONT_BREAK_LINES); |
} // end encodeBytes |
public static String encodeBytesBreakLines(byte[] source) { |
return encodeBytes(source, NO_OPTIONS); |
} |
/** |
* Encodes a byte array into Base64 notation. |
* <p> |
381,9 → 386,13 |
* @since 1.4 |
*/ |
public static String encodeBytes(byte[] source, int off, int len) { |
return encodeBytes(source, off, len, NO_OPTIONS); |
return encodeBytes(source, off, len, DONT_BREAK_LINES); |
} // end encodeBytes |
public static String encodeBytesBreakLines(byte[] source, int off, int len) { |
return encodeBytes(source, off, len, NO_OPTIONS); |
} |
/** |
* Encodes a byte array into Base64 notation. |
* <p> |
505,8 → 514,8 |
* of them) to <var>destination</var>. The source and destination arrays can be manipulated |
* anywhere along their length by specifying <var>srcOffset</var> and <var>destOffset</var>. |
* This method does not check to make sure your arrays are large enough to accomodate |
* <var>srcOffset</var> + 4 for the <var>source</var> array or <var>destOffset</var> + 3 for |
* the <var>destination</var> array. This method returns the actual number of bytes that were |
* <var>srcOffset</var> + 4 for the <var>source</var> array or <var>destOffset</var> + 3 for the |
* <var>destination</var> array. This method returns the actual number of bytes that were |
* converted from the Base64 encoding. |
* |
* |
694,8 → 703,8 |
} // end decode |
/** |
* Attempts to decode Base64 data and deserialize a Java Object within. Returns <tt>null</tt> |
* if there was an error. |
* 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 |
909,8 → 918,8 |
/* ******** I N N E R C L A S S I N P U T S T R E A M ******** */ |
/** |
* A {@link Base64.InputStream} will read data from another <tt>java.io.InputStream</tt>, |
* given in the constructor, and encode/decode to/from Base64 notation on the fly. |
* A {@link Base64.InputStream} will read data from another <tt>java.io.InputStream</tt>, given |
* in the constructor, and encode/decode to/from Base64 notation on the fly. |
* |
* @see Base64 |
* @since 1.3 |
1107,8 → 1116,8 |
/* ******** I N N E R C L A S S O U T P U T S T R E A M ******** */ |
/** |
* A {@link Base64.OutputStream} will write data to another <tt>java.io.OutputStream</tt>, |
* given in the constructor, and encode/decode to/from Base64 notation on the fly. |
* A {@link Base64.OutputStream} will write data to another <tt>java.io.OutputStream</tt>, given |
* in the constructor, and encode/decode to/from Base64 notation on the fly. |
* |
* @see Base64 |
* @since 1.3 |