public static CharsetDecoderICU newInstance(Charset cs, String icuCanonicalName) { // This complexity is necessary to ensure that even if the constructor, superclass // constructor, or call to updateCallback throw, we still free the native peer. long address = 0; try { address = NativeConverter.openConverter(icuCanonicalName); float averageCharsPerByte = NativeConverter.getAveCharsPerByte(address); CharsetDecoderICU result = new CharsetDecoderICU(cs, averageCharsPerByte, address); address = 0; // CharsetDecoderICU has taken ownership; its finalizer will do the free. result.updateCallback(); return result; } finally { if (address != 0) { NativeConverter.closeConverter(address); } } }
@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(); } }
public CharsetDecoder newDecoder() { return CharsetDecoderICU.newInstance(this, icuCanonicalName); }
@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 void implReplaceWith(String newReplacement) { updateCallback(); }
@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 void implOnMalformedInput(CodingErrorAction newAction) { updateCallback(); }
@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(); } }
public static CharsetDecoderICU newInstance(Charset cs, String icuCanonicalName) { // This complexity is necessary to ensure that even if the constructor, superclass // constructor, or call to updateCallback throw, we still free the native peer. long address = 0; try { address = NativeConverter.openConverter(icuCanonicalName); float averageCharsPerByte = NativeConverter.getAveCharsPerByte(address); CharsetDecoderICU result = new CharsetDecoderICU(cs, averageCharsPerByte, address); address = 0; // CharsetDecoderICU has taken ownership; its finalizer will do the free. result.updateCallback(); return result; } finally { if (address != 0) { NativeConverter.closeConverter(address); } } }
@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 void implOnUnmappableCharacter(CodingErrorAction newAction) { updateCallback(); }
public CharsetDecoder newDecoder() { return CharsetDecoderICU.newInstance(this, icuCanonicalName); }
@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(); } }
public static CharsetDecoderICU newInstance(Charset cs, String icuCanonicalName) { // This complexity is necessary to ensure that even if the constructor, superclass // constructor, or call to updateCallback throw, we still free the native peer. long address = 0; try { address = NativeConverter.openConverter(icuCanonicalName); float averageCharsPerByte = NativeConverter.getAveCharsPerByte(address); CharsetDecoderICU result = new CharsetDecoderICU(cs, averageCharsPerByte, address); address = 0; // CharsetDecoderICU has taken ownership; its finalizer will do the free. result.updateCallback(); return result; } finally { if (address != 0) { NativeConverter.closeConverter(address); } } }
@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 void implReplaceWith(String newReplacement) { updateCallback(); }
public CharsetDecoder newDecoder() { return CharsetDecoderICU.newInstance(this, icuCanonicalName); }
@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(); } }
public static CharsetDecoderICU newInstance(Charset cs, String icuCanonicalName) { // This complexity is necessary to ensure that even if the constructor, superclass // constructor, or call to updateCallback throw, we still free the native peer. long address = 0; try { address = NativeConverter.openConverter(icuCanonicalName); float averageCharsPerByte = NativeConverter.getAveCharsPerByte(address); CharsetDecoderICU result = new CharsetDecoderICU(cs, averageCharsPerByte, address); address = 0; // CharsetDecoderICU has taken ownership; its finalizer will do the free. result.updateCallback(); return result; } finally { if (address != 0) { NativeConverter.closeConverter(address); } } }
@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); } }