import java.io.UnsupportedEncodingException;
+import be.nikiroo.utils.StringUtils;
+
/**
* Utilities for encoding and decoding the Base64 representation of
* binary data. See RFCs <a
* incorrect padding
*/
public static byte[] decode(String str, int flags) {
- try{
- return decode(str.getBytes("UTF-8"), flags);
- } catch (UnsupportedEncodingException e) {
- // All conforming JVM are expected to support UTF-8
- return null;
- }
+ return decode(StringUtils.getBytes(str), flags);
}
/**
* @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 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;
* @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;
((input[p++] & 0xff) << 8) |
(input[p++] & 0xff);
tailLen = 0;
- };
+ }
break;
case 2: