git://git.nikiroo.be
/
fanfix.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
code cleanup, fix for ReplaceInputStream
[fanfix.git]
/
src
/
be
/
nikiroo
/
utils
/
streams
/
Base64.java
diff --git
a/src/be/nikiroo/utils/streams/Base64.java
b/src/be/nikiroo/utils/streams/Base64.java
index 9ccd02ce3e39e7da4a0b02e98a75ff2bebd5b219..76b4be49f731e9b2ee1387b0a3190fe9555dbd34 100644
(file)
--- a/
src/be/nikiroo/utils/streams/Base64.java
+++ b/
src/be/nikiroo/utils/streams/Base64.java
@@
-14,6
+14,11
@@
* limitations under the License.
*/
* limitations under the License.
*/
+/*
+ * Changes (@author niki):
+ * - default charset -> UTF-8
+ */
+
package be.nikiroo.utils.streams;
import java.io.UnsupportedEncodingException;
package be.nikiroo.utils.streams;
import java.io.UnsupportedEncodingException;
@@
-115,7
+120,12
@@
class Base64 {
* incorrect padding
*/
public static byte[] decode(String str, int flags) {
* incorrect padding
*/
public static byte[] decode(String str, int flags) {
- return decode(str.getBytes(), flags);
+ try{
+ return decode(str.getBytes("UTF-8"), flags);
+ } catch (UnsupportedEncodingException e) {
+ // All conforming JVM are expected to support UTF-8
+ return null;
+ }
}
/**
}
/**
@@
-250,7
+260,8
@@
class Base64 {
* @return an overestimate for the number of bytes {@code
* len} bytes could decode to.
*/
* @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;
}
return len * 3/4 + 10;
}
@@
-260,7
+271,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.
*/
* @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;
if (this.state == 6) return false;
int p = offset;
@@
-596,11
+608,13
@@
class Base64 {
* @return an overestimate for the number of bytes {@code
* len} bytes could encode to.
*/
* @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;
}
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;
// Using local variables makes the encoder about 9% faster.
final byte[] alphabet = this.alphabet;
final byte[] output = this.output;
@@
-628,7
+642,7
@@
class Base64 {
((input[p++] & 0xff) << 8) |
(input[p++] & 0xff);
tailLen = 0;
((input[p++] & 0xff) << 8) |
(input[p++] & 0xff);
tailLen = 0;
- }
;
+ }
break;
case 2:
break;
case 2: