|
@@ -33,13 +33,13 @@ package de.mcs.utils.codecs;
|
|
* everything is more consolidated and cleaner. The code now detects when data
|
|
* everything is more consolidated and cleaner. The code now detects when data
|
|
* that's being decoded is gzip-compressed and will decompress it automatically.
|
|
* that's being decoded is gzip-compressed and will decompress it automatically.
|
|
* Generally things are cleaner. You'll probably have to change some method
|
|
* Generally things are cleaner. You'll probably have to change some method
|
|
- * calls that you were making to support the new options format (<tt>int</tt>s
|
|
|
|
- * that you "OR" together).</li>
|
|
|
|
|
|
+ * calls that you were making to support the new options format (int s that you
|
|
|
|
+ * "OR" together).</li>
|
|
* <li>v1.5.1 - Fixed bug when decompressing and decoding to a byte[] using
|
|
* <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>
|
|
|
|
|
|
+ * decode( String s, boolean gzipCompressed ). 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
|
|
* <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
|
|
* itself. This helps when using GZIP streams. Added the ability to
|
|
* GZip-compress objects before encoding them.</li>
|
|
* GZip-compress objects before encoding them.</li>
|
|
@@ -282,8 +282,8 @@ public final class Base64 {
|
|
/**
|
|
/**
|
|
* Serializes an object and returns the Base64-encoded version of that
|
|
* Serializes an object and returns the Base64-encoded version of that
|
|
* serialized object. If the object cannot be serialized or there is another
|
|
* 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.
|
|
|
|
|
|
+ * error, the method will return null. The object is not GZip-compressed
|
|
|
|
+ * before being encoded.
|
|
*
|
|
*
|
|
* @param serializableObject
|
|
* @param serializableObject
|
|
* The object to encode
|
|
* The object to encode
|
|
@@ -297,7 +297,7 @@ public final class Base64 {
|
|
/**
|
|
/**
|
|
* Serializes an object and returns the Base64-encoded version of that
|
|
* Serializes an object and returns the Base64-encoded version of that
|
|
* serialized object. If the object cannot be serialized or there is another
|
|
* serialized object. If the object cannot be serialized or there is another
|
|
- * error, the method will return <tt>null</tt>.
|
|
|
|
|
|
+ * error, the method will return null.
|
|
* <p>
|
|
* <p>
|
|
* Valid options:
|
|
* Valid options:
|
|
*
|
|
*
|
|
@@ -746,7 +746,7 @@ public final class Base64 {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Attempts to decode Base64 data and deserialize a Java Object within.
|
|
* Attempts to decode Base64 data and deserialize a Java Object within.
|
|
- * Returns <tt>null</tt> if there was an error.
|
|
|
|
|
|
+ * Returns null if there was an error.
|
|
*
|
|
*
|
|
* @param encodedObject
|
|
* @param encodedObject
|
|
* The Base64 data to decode
|
|
* The Base64 data to decode
|
|
@@ -793,7 +793,7 @@ public final class Base64 {
|
|
* byte array of data to encode in base64 form
|
|
* byte array of data to encode in base64 form
|
|
* @param filename
|
|
* @param filename
|
|
* Filename for saving encoded data
|
|
* Filename for saving encoded data
|
|
- * @return <tt>true</tt> if successful, <tt>false</tt> otherwise
|
|
|
|
|
|
+ * @return true if successful, false otherwise
|
|
* @since 2.1
|
|
* @since 2.1
|
|
*/
|
|
*/
|
|
public static boolean encodeToFile(final byte[] dataToEncode, final String filename) {
|
|
public static boolean encodeToFile(final byte[] dataToEncode, final String filename) {
|
|
@@ -823,7 +823,7 @@ public final class Base64 {
|
|
* Base64-encoded data as a string
|
|
* Base64-encoded data as a string
|
|
* @param filename
|
|
* @param filename
|
|
* Filename for saving decoded data
|
|
* Filename for saving decoded data
|
|
- * @return <tt>true</tt> if successful, <tt>false</tt> otherwise
|
|
|
|
|
|
+ * @return true if successful, false otherwise
|
|
* @since 2.1
|
|
* @since 2.1
|
|
*/
|
|
*/
|
|
public static boolean decodeToFile(final String dataToDecode, final String filename) {
|
|
public static boolean decodeToFile(final String dataToDecode, final String filename) {
|
|
@@ -871,7 +871,8 @@ public final class Base64 {
|
|
buffer = new byte[(int) file.length()];
|
|
buffer = new byte[(int) file.length()];
|
|
|
|
|
|
// Open a stream
|
|
// Open a stream
|
|
- bis = new Base64.Base64InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(file)), Base64.DECODE);
|
|
|
|
|
|
+ bis = new Base64.Base64InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(file)),
|
|
|
|
+ Base64.DECODE);
|
|
|
|
|
|
// Read until done
|
|
// Read until done
|
|
while ((numBytes = bis.read(buffer, length, 4096)) >= 0) {
|
|
while ((numBytes = bis.read(buffer, length, 4096)) >= 0) {
|
|
@@ -913,7 +914,8 @@ public final class Base64 {
|
|
int numBytes = 0;
|
|
int numBytes = 0;
|
|
|
|
|
|
// Open a stream
|
|
// Open a stream
|
|
- bis = new Base64.Base64InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(file)), Base64.ENCODE);
|
|
|
|
|
|
+ bis = new Base64.Base64InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(file)),
|
|
|
|
+ Base64.ENCODE);
|
|
|
|
|
|
// Read until done
|
|
// Read until done
|
|
while ((numBytes = bis.read(buffer, length, 4096)) >= 0) {
|
|
while ((numBytes = bis.read(buffer, length, 4096)) >= 0) {
|
|
@@ -939,8 +941,8 @@ public final class Base64 {
|
|
|
|
|
|
/**
|
|
/**
|
|
* A {@link Base64.Base64InputStream} will read data from another
|
|
* A {@link Base64.Base64InputStream} will read data from another
|
|
- * <tt>java.io.InputStream</tt>, given in the constructor, and encode/decode
|
|
|
|
- * to/from Base64 notation on the fly.
|
|
|
|
|
|
+ * java.io.InputStream, given in the constructor, and encode/decode to/from
|
|
|
|
+ * Base64 notation on the fly.
|
|
*
|
|
*
|
|
* @see Base64
|
|
* @see Base64
|
|
* @since 1.3
|
|
* @since 1.3
|
|
@@ -971,7 +973,7 @@ public final class Base64 {
|
|
* Constructs a {@link Base64.Base64InputStream} in DECODE mode.
|
|
* Constructs a {@link Base64.Base64InputStream} in DECODE mode.
|
|
*
|
|
*
|
|
* @param in
|
|
* @param in
|
|
- * the <tt>java.io.InputStream</tt> from which to read data.
|
|
|
|
|
|
+ * the java.io.InputStream from which to read data.
|
|
* @since 1.3
|
|
* @since 1.3
|
|
*/
|
|
*/
|
|
public Base64InputStream(final java.io.InputStream in) {
|
|
public Base64InputStream(final java.io.InputStream in) {
|
|
@@ -979,7 +981,8 @@ public final class Base64 {
|
|
} // end constructor
|
|
} // end constructor
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Constructs a {@link Base64.Base64InputStream} in either ENCODE or DECODE mode.
|
|
|
|
|
|
+ * Constructs a {@link Base64.Base64InputStream} in either ENCODE or DECODE
|
|
|
|
+ * mode.
|
|
* <p>
|
|
* <p>
|
|
* Valid options:
|
|
* Valid options:
|
|
*
|
|
*
|
|
@@ -992,7 +995,7 @@ public final class Base64 {
|
|
* Example: <code>new Base64.InputStream( in, Base64.DECODE )</code>
|
|
* Example: <code>new Base64.InputStream( in, Base64.DECODE )</code>
|
|
*
|
|
*
|
|
* @param in
|
|
* @param in
|
|
- * the <tt>java.io.InputStream</tt> from which to read data.
|
|
|
|
|
|
+ * the java.io.InputStream from which to read data.
|
|
* @param options
|
|
* @param options
|
|
* Specified options
|
|
* Specified options
|
|
* @see Base64#ENCODE
|
|
* @see Base64#ENCODE
|
|
@@ -1155,8 +1158,8 @@ public final class Base64 {
|
|
|
|
|
|
/**
|
|
/**
|
|
* A {@link Base64.Base64OutputStream} will write data to another
|
|
* A {@link Base64.Base64OutputStream} will write data to another
|
|
- * <tt>java.io.OutputStream</tt>, given in the constructor, and encode/decode
|
|
|
|
- * to/from Base64 notation on the fly.
|
|
|
|
|
|
+ * java.io.OutputStream, given in the constructor, and encode/decode to/from
|
|
|
|
+ * Base64 notation on the fly.
|
|
*
|
|
*
|
|
* @see Base64
|
|
* @see Base64
|
|
* @since 1.3
|
|
* @since 1.3
|
|
@@ -1190,7 +1193,7 @@ public final class Base64 {
|
|
* Constructs a {@link Base64.Base64OutputStream} in ENCODE mode.
|
|
* Constructs a {@link Base64.Base64OutputStream} in ENCODE mode.
|
|
*
|
|
*
|
|
* @param out
|
|
* @param out
|
|
- * the <tt>java.io.OutputStream</tt> to which data will be written.
|
|
|
|
|
|
+ * the java.io.OutputStream to which data will be written.
|
|
* @since 1.3
|
|
* @since 1.3
|
|
*/
|
|
*/
|
|
public Base64OutputStream(final java.io.OutputStream out) {
|
|
public Base64OutputStream(final java.io.OutputStream out) {
|
|
@@ -1198,7 +1201,8 @@ public final class Base64 {
|
|
} // end constructor
|
|
} // end constructor
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Constructs a {@link Base64.Base64OutputStream} in either ENCODE or DECODE mode.
|
|
|
|
|
|
+ * Constructs a {@link Base64.Base64OutputStream} in either ENCODE or DECODE
|
|
|
|
+ * mode.
|
|
* <p>
|
|
* <p>
|
|
* Valid options:
|
|
* Valid options:
|
|
*
|
|
*
|
|
@@ -1211,7 +1215,7 @@ public final class Base64 {
|
|
* Example: <code>new Base64.OutputStream( out, Base64.ENCODE )</code>
|
|
* Example: <code>new Base64.OutputStream( out, Base64.ENCODE )</code>
|
|
*
|
|
*
|
|
* @param out
|
|
* @param out
|
|
- * the <tt>java.io.OutputStream</tt> to which data will be written.
|
|
|
|
|
|
+ * the java.io.OutputStream to which data will be written.
|
|
* @param options
|
|
* @param options
|
|
* Specified options.
|
|
* Specified options.
|
|
* @see Base64#ENCODE
|
|
* @see Base64#ENCODE
|