private static CoderResult lookupN(ByteBuffer src, int n) { for (int i = 1; i < n; i++) { if (isNotContinuation(src.get())) return CoderResult.malformedForLength(i); } return CoderResult.malformedForLength(n); }
return CoderResult.malformedForLength(1); case 2: // always 1 return CoderResult.malformedForLength(1); case 3: b1 = src.get(); int b2 = src.get(); // no need to lookup b3 return CoderResult.malformedForLength(((b1 == (byte) 0xe0 && (b2 & 0xe0) == 0x80) || isNotContinuation(b2)) ? 1 : 2); case 4: // we don't care the speed here b1 = src.get() & 0xff; b2 = src.get() & 0xff; if (b1 > 0xf4 || (b1 == 0xf0 && (b2 < 0x90 || b2 > 0xbf)) || (b1 == 0xf4 && (b2 & 0xf0) != 0x80) || isNotContinuation(b2)) return CoderResult.malformedForLength(1); if (isNotContinuation(src.get())) return CoderResult.malformedForLength(2); return CoderResult.malformedForLength(3); default: throw new IllegalStateException();
result = CoderResult.malformedForLength(in.remaining()); } else { return result;
result = CoderResult.malformedForLength(in.remaining()); } else { return result;
@Override protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) { if (!in.hasRemaining()) { return CoderResult.UNDERFLOW; } data[INPUT_OFFSET] = getArray(in); data[OUTPUT_OFFSET]= getArray(out); data[INVALID_CHARS] = 0; // Make sure we don't see earlier errors. try { int error = NativeConverter.encode(converterHandle, input, inEnd, output, outEnd, data, false); if (ICU.U_FAILURE(error)) { if (error == ICU.U_BUFFER_OVERFLOW_ERROR) { return CoderResult.OVERFLOW; } else if (error == ICU.U_INVALID_CHAR_FOUND) { return CoderResult.unmappableForLength(data[INVALID_CHARS]); } else if (error == ICU.U_ILLEGAL_CHAR_FOUND) { return CoderResult.malformedForLength(data[INVALID_CHARS]); } else { throw new AssertionError(error); } } // Decoding succeeded: give us more data. return CoderResult.UNDERFLOW; } finally { setPosition(in); setPosition(out); } }
@Override protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) { if (!in.hasRemaining()) { return CoderResult.UNDERFLOW; } data[INPUT_OFFSET] = getArray(in); data[OUTPUT_OFFSET]= getArray(out); try { int error = NativeConverter.decode(converterHandle, input, inEnd, output, outEnd, data, false); if (ICU.U_FAILURE(error)) { if (error == ICU.U_BUFFER_OVERFLOW_ERROR) { return CoderResult.OVERFLOW; } else if (error == ICU.U_INVALID_CHAR_FOUND) { return CoderResult.unmappableForLength(data[INVALID_BYTES]); } else if (error == ICU.U_ILLEGAL_CHAR_FOUND) { return CoderResult.malformedForLength(data[INVALID_BYTES]); } else { throw new AssertionError(error); } } // Decoding succeeded: give us more data. return CoderResult.UNDERFLOW; } finally { setPosition(in); setPosition(out); } }
@Override protected final CoderResult implFlush(CharBuffer out) { try { // ICU needs to see an empty input. input = EmptyArray.BYTE; inEnd = 0; data[INPUT_OFFSET] = 0; data[OUTPUT_OFFSET] = getArray(out); data[INVALID_BYTES] = 0; // Make sure we don't see earlier errors. int error = NativeConverter.decode(converterHandle, input, inEnd, output, outEnd, data, true); if (ICU.U_FAILURE(error)) { if (error == ICU.U_BUFFER_OVERFLOW_ERROR) { return CoderResult.OVERFLOW; } else if (error == ICU.U_TRUNCATED_CHAR_FOUND) { if (data[INPUT_OFFSET] > 0) { return CoderResult.malformedForLength(data[INPUT_OFFSET]); } } } return CoderResult.UNDERFLOW; } finally { setPosition(out); implReset(); } }
@Override protected CoderResult implFlush(ByteBuffer out) { try { // ICU needs to see an empty input. input = EmptyArray.CHAR; inEnd = 0; data[INPUT_OFFSET] = 0; data[OUTPUT_OFFSET] = getArray(out); data[INVALID_CHARS] = 0; // Make sure we don't see earlier errors. int error = NativeConverter.encode(converterHandle, input, inEnd, output, outEnd, data, true); if (ICU.U_FAILURE(error)) { if (error == ICU.U_BUFFER_OVERFLOW_ERROR) { return CoderResult.OVERFLOW; } else if (error == ICU.U_TRUNCATED_CHAR_FOUND) { if (data[INPUT_OFFSET] > 0) { return CoderResult.malformedForLength(data[INPUT_OFFSET]); } } } return CoderResult.UNDERFLOW; } finally { setPosition(out); implReset(); } }
@Override protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) { if (in.hasRemaining() && !replacementErrorReturned) { replacementErrorReturned = true; return CoderResult.malformedForLength(in.remaining()); } in.position(in.limit()); return CoderResult.UNDERFLOW; }
private static CoderResult malformedForLength(ByteBuffer src, int sp, CharBuffer dst, int dp, int malformedNB) { updatePositions(src, sp, dst, dp); return CoderResult.malformedForLength(malformedNB); }
private static CoderResult malformedForLength(ByteBuffer src, int sp, CharBuffer dst, int dp, int malformedNB) { updatePositions(src, sp, dst, dp); return CoderResult.malformedForLength(malformedNB); }
private static CoderResult malformedForLength(ByteBuffer src, int sp, CharBuffer dst, int dp, int malformedNB) { updatePositions(src, sp, dst, dp); return CoderResult.malformedForLength(malformedNB); }
private static CoderResult malformedForLength(ByteBuffer src, int mark, int malformedNB) { src.position(mark); return CoderResult.malformedForLength(malformedNB); }
private static CoderResult malformedForLength(ByteBuffer src, int mark, int malformedNB) { src.position(mark); return CoderResult.malformedForLength(malformedNB); }
private static CoderResult malformedForLength(ByteBuffer src, int mark, int malformedNB) { src.position(mark); return CoderResult.malformedForLength(malformedNB); }
/** * <p>Resets the input buffer position to just before the last byte read, and returns * a result indicating to skip the last byte.</p> * * @param in The input buffer * @return CoderResult.malformedForLength(1); */ private CoderResult malformed(ByteBuffer in) { in.position(in.position() - 1); return CoderResult.malformedForLength(1); }
private static CoderResult lookupN(ByteBuffer src, int n) { for (int i = 1; i < n; i++) { if (isNotContinuation(src.get())) return CoderResult.malformedForLength(i); } return CoderResult.malformedForLength(n); }
private static CoderResult lookupN(ByteBuffer src, int n) { for (int i = 1; i < n; i++) { if (isNotContinuation(src.get())) return CoderResult.malformedForLength(i); } return CoderResult.malformedForLength(n); }
@Override protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) { if (in.hasRemaining() && !replacementErrorReturned) { replacementErrorReturned = true; return CoderResult.malformedForLength(in.remaining()); } in.position(in.limit()); return CoderResult.UNDERFLOW; }
protected CoderResult implFlush(CharBuffer out) { if ((base64mode && strict) || base64bitsWaiting()) return CoderResult.malformedForLength(1); return CoderResult.UNDERFLOW; }