Example usage for java.nio.charset CoderResult isOverflow

List of usage examples for java.nio.charset CoderResult isOverflow

Introduction

In this page you can find the example usage for java.nio.charset CoderResult isOverflow.

Prototype

public boolean isOverflow() 

Source Link

Document

Tells whether or not this object describes an overflow condition.

Usage

From source file:co.cask.cdap.logging.gateway.handlers.ChunkedLogReaderCallback.java

private void encodeSend(CharBuffer inBuffer, boolean endOfInput) throws IOException {
    while (true) {
        CoderResult coderResult = charsetEncoder.encode(inBuffer, chunkBuffer, endOfInput);
        if (coderResult.isOverflow()) {
            // if reached buffer capacity then flush chunk
            chunkBuffer.flip();/*from w ww.j a  v  a2 s  . c o  m*/
            chunkResponder.sendChunk(ChannelBuffers.copiedBuffer(chunkBuffer));
            chunkBuffer.clear();
        } else if (coderResult.isError()) {
            // skip characters causing error, and retry
            inBuffer.position(inBuffer.position() + coderResult.length());
        } else {
            // log line was completely written
            break;
        }
    }
}

From source file:co.cask.cdap.logging.gateway.handlers.ChunkedLogReaderCallback.java

@Override
public void close() {
    try {/*from ww w.j  ava2s  . c  o  m*/
        // Write the last chunk
        encodeSend(CharBuffer.allocate(0), true);
        // Flush the encoder
        CoderResult coderResult;
        do {
            coderResult = charsetEncoder.flush(chunkBuffer);
            chunkBuffer.flip();
            chunkResponder.sendChunk(ChannelBuffers.copiedBuffer(chunkBuffer));
            chunkBuffer.clear();
        } while (coderResult.isOverflow());
    } catch (IOException e) {
        // If cannot send chunks, nothing can be done (since the client closed connection).
        // Just log the error as debug.
        LOG.debug("Failed to send chunk", e);
    } finally {
        try {
            patternLayout.stop();
        } finally {
            Closeables.closeQuietly(chunkResponder);
        }
    }
}

From source file:org.gradle.testkit.runner.internal.io.WriterOutputStream.java

/**
 * Decode the contents of the input ByteBuffer into a CharBuffer.
 *
 * @param endOfInput indicates end of input
 * @throws IOException if an I/O error occurs
 *//*from   w  w  w.  j a  v a 2s  . c  o  m*/
private void processInput(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();
}