Refine search
/** * Decode the contents of the input ByteBuffer into a CharBuffer. * * @param endOfInput indicates end of input * @throws IOException if an I/O error occurs */ private void processInput(final boolean endOfInput) throws IOException { // Prepare decoderIn for reading decoderIn.flip(); CoderResult coderResult; while (true) { coderResult = decoder.decode(decoderIn, decoderOut, endOfInput); if (coderResult.isOverflow()) { flushOutput(); } else if (coderResult.isUnderflow()) { break; } else { // The decoder is configured to replace malformed input and unmappable characters, // so we should not get here. throw new IOException("Unexpected coder result"); } } // Discard the bytes that have been read decoderIn.compact(); }
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; } }
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(); } } }
CoderResult cr = (inBuffer.hasRemaining() ? charsetEncoder.encode(inBuffer, outBuffer, true) : CoderResult.UNDERFLOW); if (cr.isUnderflow()) { cr = charsetEncoder.flush(outBuffer); if (cr.isUnderflow()) { break; if (cr.isOverflow()) { writePosition(outBuffer.position()); int maximumSize = (int) (inBuffer.remaining() * charsetEncoder.maxBytesPerChar());
if (result.isOverflow()) { } else if (result.isUnderflow()) { readMoreChars(); } else if (result.isError()) {
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; } }
} else if (res.isOverflow()) { } else if (res.isUnderflow()) {
while (byteBuffer.hasRemaining()) { final CoderResult result = decoder.decode(byteBuffer, charBuffer, eof); if (result.isOverflow()) { writer.write(chars, 0, charBuffer.position()); charBuffer.clear(); continue; if (result.isUnderflow()) { final int p = charBuffer.position(); if (p > 0) { if (result.isError()) { if (result.isMalformed()) { throw msg.malformedInput();
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; } }
CoderResult res = charsetDecoder.decode(dataBuf, outBuf, isEndOfInput); if (res.isUnderflow()) { if (res.isOverflow()) { assert outBuf.position() > 0;
if (result.isOverflow()) { } else if (result.isUnderflow()) { readMoreChars(); } else if (result.isError()) {
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"); } }
} else if (res.isOverflow()) { } else if (res.isUnderflow()) {
if (result.isOverflow()) { } else if (result.isUnderflow()) { readMoreChars(); } else if (result.isError()) {
private static void checkResult(CoderResult result) throws CharacterCodingException { if (result.isOverflow()) { throw new IllegalStateException("Somehow got byte buffer overflow"); } if (result.isError()) { result.throwException(); } }
CoderResult cr = (inBuffer.hasRemaining() ? charsetEncoder.encode(inBuffer, outBuffer, true) : CoderResult.UNDERFLOW); if (cr.isUnderflow()) { cr = charsetEncoder.flush(outBuffer); if (cr.isUnderflow()) { break; if (cr.isOverflow()) { writePosition(outBuffer.position()); int maximumSize = (int) (inBuffer.remaining() * charsetEncoder.maxBytesPerChar());
while (charBuffer.hasRemaining()) { final CoderResult result = encoder.encode(charBuffer, byteBuffer, false); if (result.isOverflow()) { return true; if (result.isUnderflow()) { filled = true; break; if (result.isError()) { if (result.isMalformed()) { throw msg.malformedInput();
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; } }
private void append(String str) throws CharacterCodingException { int n = str.length(); if (n > chArr.length) { chArr = new char[n + 256]; chBuf = CharBuffer.wrap(chArr); } str.getChars(0, n, chArr, 0); chBuf.position(0).limit(n); utf8.reset(); for (;;) { CoderResult cr = utf8.encode(chBuf, binBuf, true); if (cr.isOverflow()) { grow(); } else if (cr.isUnderflow()) { break; } else { cr.throwException(); } } }
if (result.isOverflow()) { } else if (result.isUnderflow()) { readMoreChars(); } else if (result.isError()) {