X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2FBase64.java;h=784fc929aef19b9f51c3dcb9f891cb9bb59e3122;hb=12784931c8ae440fec10dfd6ea97e7b16ba64988;hp=efb57b4a0cf1d62fa8025d96f26361bc2a61ec2f;hpb=cd0c27d2e457ea19fcd9def879e1534a528292c2;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/Base64.java b/src/be/nikiroo/utils/Base64.java index efb57b4..784fc92 100644 --- a/src/be/nikiroo/utils/Base64.java +++ b/src/be/nikiroo/utils/Base64.java @@ -1,5 +1,7 @@ package be.nikiroo.utils; +import java.io.IOException; + /** *

Encodes and decodes to and from Base64 notation.

*

Homepage: http://iharder.net/base64.

@@ -208,7 +210,7 @@ class Base64 /** Preferred encoding. */ - private final static String PREFERRED_ENCODING = "US-ASCII"; + private final static String PREFERRED_ENCODING = "UTF-8"; private final static byte WHITE_SPACE_ENC = -5; // Indicates white space in encoding @@ -1249,8 +1251,24 @@ class Base64 } // end catch // + return niki_decode(bytes, 0, bytes.length, options); + } + + /** + * Decodes data from Base64 notation, automatically + * detecting gzip-compressed data and decompressing it. + * + * @param s the string to decode + * @param options encode options such as URL_SAFE + * @return the decoded data + * @throws java.io.IOException if there is an error + * @throws NullPointerException if s is null + * @since niki + */ + public static byte[] niki_decode( byte[] bytes, int offset, int count, int options ) throws java.io.IOException { + // Decode - bytes = decode( bytes, 0, bytes.length, options ); + bytes = decode( bytes, offset, count, options ); // Check to see if it's gzip-compressed // GZIP Magic Two-Byte Number: 0x8b1f (35615) @@ -2013,7 +2031,9 @@ class Base64 @Override public void close() throws java.io.IOException { // 1. Ensure that pending characters are written - flushBase64(); + + // niki: removed since it is now in flush() + //flushBase64(); // 2. Actually close the stream // Base class both flushes and closes. @@ -2050,7 +2070,12 @@ class Base64 this.suspendEncoding = false; } // end resumeEncoding - + @Override + // added by niki + public void flush() throws IOException { + flushBase64(); + super.flush(); + } } // end inner class OutputStream