Refine search
/** * Fills the byte output buffer from the input char buffer. * * @throws CharacterCodingException * an error encoding data */ private void fillBuffer() throws CharacterCodingException { this.bbuf.compact(); final CoderResult result = this.encoder.encode(this.cbuf, this.bbuf, true); if (result.isError()) { result.throwException(); } this.bbuf.flip(); }
private void convert(CharBuffer chars) throws IOException { while (true) { CoderResult result = encoder.encode(chars, bytes, false); if (result.isOverflow()) { // Make room and try again. flushBytes(false); continue; } else if (result.isError()) { result.throwException(); } break; } }
public void flush() throws IOException { //Log.i("PackageManager", "flush mPos=" + mPos); if (mPos > 0) { if (mOutputStream != null) { CharBuffer charBuffer = CharBuffer.wrap(mText, 0, mPos); CoderResult result = mCharset.encode(charBuffer, mBytes, true); while (true) { if (result.isError()) { throw new IOException(result.toString()); } else if (result.isOverflow()) { flushBytes(); result = mCharset.encode(charBuffer, mBytes, true); continue; } break; } flushBytes(); mOutputStream.flush(); } else { mWriter.write(mText, 0, mPos); mWriter.flush(); } mPos = 0; } }
private void checkEncodeResult(CoderResult result) throws CharacterCodingException { if (result.isError()) { result.throwException(); } }
if (result.isOverflow()) { readMoreChars(); } else if (result.isError()) { result.throwException(); return 0; // Not called.
public void flush() throws IOException { //Log.i("PackageManager", "flush mPos=" + mPos); if (mPos > 0) { if (mOutputStream != null) { CharBuffer charBuffer = CharBuffer.wrap(mText, 0, mPos); CoderResult result = mCharset.encode(charBuffer, mBytes, true); while (true) { if (result.isError()) { throw new IOException(result.toString()); } else if (result.isOverflow()) { flushBytes(); result = mCharset.encode(charBuffer, mBytes, true); continue; } break; } flushBytes(); mOutputStream.flush(); } else { mWriter.write(mText, 0, mPos); mWriter.flush(); } mPos = 0; } }
private void _flushEncoder() throws IOException { _encodeLeftoverChar(_EMPTY_CHAR_BUFFER, true); // Ensure encoder transit to END state before flushing, in case the // encoder was never used and still in RESET state. _charsetEncoder.encode(_EMPTY_CHAR_BUFFER, _outputByteBuffer, true); while (true) { CoderResult coderResult = _charsetEncoder.flush(_outputByteBuffer); if (coderResult.isError()) { coderResult.throwException(); } if (coderResult.isUnderflow()) { break; } // Must be overflow, no need to check _flushBuffer(); } }
private void drainEncoder() throws IOException { // Strictly speaking, I think it's part of the CharsetEncoder contract that you call // encode with endOfInput true before flushing. Our ICU-based implementations don't // actually need this, and you'd hope that any reasonable implementation wouldn't either. // CharsetEncoder.encode doesn't actually pass the boolean through to encodeLoop anyway! CharBuffer chars = CharBuffer.allocate(0); while (true) { CoderResult result = encoder.encode(chars, bytes, true); if (result.isError()) { result.throwException(); } else if (result.isOverflow()) { flushBytes(false); continue; } break; } // Some encoders (such as ISO-2022-JP) have stuff to write out after all the // characters (such as shifting back into a default state). In our implementation, // this is actually the first time ICU is told that we've run out of input. CoderResult result = encoder.flush(bytes); while (!result.isUnderflow()) { if (result.isOverflow()) { flushBytes(false); result = encoder.flush(bytes); } else { result.throwException(); } } }
while (byteBuffer.hasRemaining()) { final CoderResult result = decoder.decode(byteBuffer, charBuffer, eof); if (result.isOverflow()) { writer.write(chars, 0, charBuffer.position()); charBuffer.clear(); if (result.isError()) { if (result.isMalformed()) { throw msg.malformedInput();
private void _encodeLoop(CharBuffer inputCharBuffer, boolean endOfInput) throws IOException { while (inputCharBuffer.hasRemaining()) { CoderResult coderResult = _charsetEncoder.encode( inputCharBuffer, _outputByteBuffer, endOfInput); if (coderResult.isError()) { coderResult.throwException(); } if (coderResult.isUnderflow()) { if (_autoFlush) { _flushBuffer(); } if ((_inputCharBuffer != inputCharBuffer) && inputCharBuffer.hasRemaining()) { _inputCharBuffer.put(inputCharBuffer.get()); } break; } // Must be overflow, no need to check _flushBuffer(); } }
if (result.isOverflow()) { readMoreChars(); } else if (result.isError()) { result.throwException(); return 0; // Not called.
while (charBuffer.hasRemaining()) { final CoderResult result = encoder.encode(charBuffer, byteBuffer, false); if (result.isOverflow()) { return true; break; if (result.isError()) { if (result.isMalformed()) { throw msg.malformedInput();
utf16CodeUnitsOut, endOfInput); if (result.isError() && decodingErrorAction.equals(CodingErrorAction.REPORT)) { result.throwException(); if (flushResult.isError() && decodingErrorAction.equals(CodingErrorAction.REPORT)) { flushResult.throwException();
if (result.isOverflow()) { readMoreChars(); } else if (result.isError()) { result.throwException(); return 0; // Not called.
private void logErrors(CoderResult coderResult) { if (coderResult.isOverflow()) { log.error("Buffer overflow, the character buffer is not large enough to decode the characters, some information may be lost"); } else if (coderResult.isError()) { log.warn("There was some error in decoding the file given the current charset"); } }
private void checkResult(final CoderResult result) throws IOException { if (result.isError()) { result.throwException(); } }
if (result.isOverflow()) { readMoreChars(); } else if (result.isError()) { result.throwException(); return 0; // Not called.
private void byte2char(ByteBuffer bytes, CharBuffer chars) throws IOException { decoder.reset(); chars.clear(); CoderResult result = decoder.decode(bytes, chars, true); if (result.isError() || result.isOverflow()) { throw new IOException(result.toString()); } else if (result.isUnderflow()) { chars.flip(); } } }
private void checkResult(final CoderResult result) throws IOException { if (result.isError()) { result.throwException(); } }
if (cr.isOverflow()) { CharBuffer o = CharBuffer.allocate(out.capacity() + expectedLength); out.flip(); if (cr.isError()) { cr.throwException();