Methods Summary |
---|
private boolean | base64bitsWaiting()
return tempChar != 0 || bitsRead >= 6;
|
protected java.nio.charset.CoderResult | decodeLoop(java.nio.ByteBuffer in, java.nio.CharBuffer out)
while (in.hasRemaining()) {
byte b = in.get();
if (base64mode) {
if (b == unshift) {
if (base64bitsWaiting())
return malformed(in);
if (justShifted) {
if (!out.hasRemaining())
return overflow(in);
out.put((char)shift);
} else
justUnshifted = true;
setUnshifted();
} else {
if (!out.hasRemaining())
return overflow(in);
CoderResult result = handleBase64(in, out, b);
if (result != null)
return result;
}
justShifted = false;
} else {
if (b == shift) {
base64mode = true;
if (justUnshifted && strict)
return malformed(in);
justShifted = true;
continue;
}
if (!out.hasRemaining())
return overflow(in);
out.put((char)b);
justUnshifted = false;
}
}
return CoderResult.UNDERFLOW;
|
private java.nio.charset.CoderResult | handleBase64(java.nio.ByteBuffer in, java.nio.CharBuffer out, byte lastRead)
Decodes a byte in base 64 mode. Will directly write a character to
the output buffer if completed.
CoderResult result = null;
int sextet = base64.getSextet(lastRead);
if (sextet >= 0) {
bitsRead += 6;
if (bitsRead < 16) {
tempChar += sextet << (16 - bitsRead);
} else {
bitsRead -= 16;
tempChar += sextet >> (bitsRead);
out.put((char)tempChar);
tempChar = (sextet << (16 - bitsRead)) & 0xFFFF;
}
} else {
if (strict)
return malformed(in);
out.put((char)lastRead);
if (base64bitsWaiting())
result = malformed(in);
setUnshifted();
}
return result;
|
protected java.nio.charset.CoderResult | implFlush(java.nio.CharBuffer out)
if ((base64mode && strict) || base64bitsWaiting())
return CoderResult.malformedForLength(1);
return CoderResult.UNDERFLOW;
|
protected void | implReset()
setUnshifted();
justUnshifted = false;
|
private java.nio.charset.CoderResult | malformed(java.nio.ByteBuffer in)
Resets the input buffer position to just before the last byte read, and
returns a result indicating to skip the last byte.
in.position(in.position() - 1);
return CoderResult.malformedForLength(1);
|
private java.nio.charset.CoderResult | overflow(java.nio.ByteBuffer in)
in.position(in.position() - 1);
return CoderResult.OVERFLOW;
|
private void | setUnshifted()
Updates internal state to reflect the decoder is no longer in base 64
mode
base64mode = false;
bitsRead = 0;
tempChar = 0;
|