Add 'src/be/nikiroo/utils/' from commit '46add0670fdee4bd936a13fe2448c5e20a7ffd0a'
[fanfix.git] / src / be / nikiroo / utils / streams / Base64.java
index 9ccd02ce3e39e7da4a0b02e98a75ff2bebd5b219..d54794b0a4ee2284bb1c691cb329aa52dd65fb47 100644 (file)
  * limitations under the License.
  */
 
+/*
+ * Changes (@author niki):
+ * - default charset -> UTF-8
+ */
+
 package be.nikiroo.utils.streams;
 
 import java.io.UnsupportedEncodingException;
 
+import be.nikiroo.utils.StringUtils;
+
 /**
  * Utilities for encoding and decoding the Base64 representation of
  * binary data.  See RFCs <a
@@ -115,7 +122,7 @@ class Base64 {
      * incorrect padding
      */
     public static byte[] decode(String str, int flags) {
-        return decode(str.getBytes(), flags);
+               return decode(StringUtils.getBytes(str), flags);
     }
 
     /**
@@ -250,7 +257,8 @@ class Base64 {
          * @return an overestimate for the number of bytes {@code
          * len} bytes could decode to.
          */
-        public int maxOutputSize(int len) {
+        @Override
+               public int maxOutputSize(int len) {
             return len * 3/4 + 10;
         }
 
@@ -260,7 +268,8 @@ class Base64 {
          * @return true if the state machine is still healthy.  false if
          *         bad base-64 data has been detected in the input stream.
          */
-        public boolean process(byte[] input, int offset, int len, boolean finish) {
+        @Override
+               public boolean process(byte[] input, int offset, int len, boolean finish) {
             if (this.state == 6) return false;
 
             int p = offset;
@@ -596,11 +605,13 @@ class Base64 {
          * @return an overestimate for the number of bytes {@code
          * len} bytes could encode to.
          */
-        public int maxOutputSize(int len) {
+        @Override
+               public int maxOutputSize(int len) {
             return len * 8/5 + 10;
         }
 
-        public boolean process(byte[] input, int offset, int len, boolean finish) {
+        @Override
+               public boolean process(byte[] input, int offset, int len, boolean finish) {
             // Using local variables makes the encoder about 9% faster.
             final byte[] alphabet = this.alphabet;
             final byte[] output = this.output;
@@ -628,7 +639,7 @@ class Base64 {
                             ((input[p++] & 0xff) << 8) |
                             (input[p++] & 0xff);
                         tailLen = 0;
-                    };
+                    }
                     break;
 
                 case 2: