src/main/java/org/michailov/async/io/AsyncCharDecoder.java
private void decodeFromTempBuffer() {
        // Take a snapshot of the real char buffer.
        // (The real byte buffer is not needed now.)
        int writePosition = _charRingBuffer.getWritePosition();
        int writeStraight = _charRingBuffer.getAvailableToWriteStraight();

        // Map the virtual decoder char buffer over the native char buffer. 
        _mainCharBuffer.position(writePosition);
        _mainCharBuffer.limit(writePosition + writeStraight);

        // Copy one more byte from the real byte buffer to the temp buffer.
        // RingBuffer.read() automatically adjusts the read position.
        int b = _byteRingBuffer.read();
        int oldLimit = _tempByteBuffer.limit();
        _tempByteBuffer.limit(oldLimit + 1);
        _tempByteBuffer.put(oldLimit, (byte)b);
        _tempByteBuffer.position(0);
        
        // Attempt to decode.
        _charsetDecoder.reset();
        CoderResult coderResult = _charsetDecoder.decode(_tempByteBuffer, _mainCharBuffer, DECODE_AS_EOF);

        // Adjust the position on the physical char buffer. 
        int newWritePosition = _mainCharBuffer.position();
        int writeDelta = newWritePosition - writePosition;
        if (writeDelta > 0) {
            _charRingBuffer.advanceWritePosition(writeDelta);
        }
            
        // If decoding succeeded, it must continue from the main buffer.
        if (!coderResult.isError()) {
            _isTempBufferDirty = false;
        }
    }
/**
     * Copies the remainder of bytes to the temp buffer and adds 1 more byte.
     * Then attempts to decode those bytes from the temp buffer.
     */
Copies the remainder of bytes to the temp buffer and adds 1 more byte.
Then attempts to decode those bytes from the temp buffer.
Copies the remainder of bytes to the temp buffer and adds 1 more byte . Then attempts to decode those bytes from the temp buffer .
private void decodeFromTempBuffer() {
        int writePosition = _charRingBuffer.getWritePosition();
        int writeStraight = _charRingBuffer.getAvailableToWriteStraight();
        _mainCharBuffer.position(writePosition);
        _mainCharBuffer.limit(writePosition + writeStraight);
        int b = _byteRingBuffer.read();
        int oldLimit = _tempByteBuffer.limit();
        _tempByteBuffer.limit(oldLimit + 1);
        _tempByteBuffer.put(oldLimit, (byte)b);
        _tempByteBuffer.position(0);
        _charsetDecoder.reset();
        CoderResult coderResult = _charsetDecoder.decode(_tempByteBuffer, _mainCharBuffer, DECODE_AS_EOF);
        int newWritePosition = _mainCharBuffer.position();
        int writeDelta = newWritePosition - writePosition;
        if (writeDelta > 0) {
            _charRingBuffer.advanceWritePosition(writeDelta);
        }
        if (!coderResult.isError()) {
            _isTempBufferDirty = false;
        }
    }
private void decodeFromTempBuffer ( ) { int writePosition = _charRingBuffer . getWritePosition ( ) ; int writeStraight = _charRingBuffer . getAvailableToWriteStraight ( ) ; _mainCharBuffer . position ( writePosition ) ; _mainCharBuffer . limit ( writePosition + writeStraight ) ; int b = _byteRingBuffer . read ( ) ; int oldLimit = _tempByteBuffer . limit ( ) ; _tempByteBuffer . limit ( oldLimit + 1 ) ; _tempByteBuffer . put ( oldLimit , ( byte ) b ) ; _tempByteBuffer . position ( 0 ) ; _charsetDecoder . reset ( ) ; CoderResult coderResult = _charsetDecoder . decode ( _tempByteBuffer , _mainCharBuffer , DECODE_AS_EOF ) ; int newWritePosition = _mainCharBuffer . position ( ) ; int writeDelta = newWritePosition - writePosition ; if ( writeDelta > 0 ) { _charRingBuffer . advanceWritePosition ( writeDelta ) ; } if ( ! coderResult . isError ( ) ) { _isTempBufferDirty = false ; } }
Copies the remainder of bytes to the temp buffer and adds 1 more byte.
Copies the remainder of bytes to the temp buffer and adds 1 more byte .
// Take a snapshot of the real char buffer.
 // (The real byte buffer is not needed now.)
 // Map the virtual decoder char buffer over the native char buffer. 
 // Copy one more byte from the real byte buffer to the temp buffer.
 // RingBuffer.read() automatically adjusts the read position.
 // Attempt to decode.
 // Adjust the position on the physical char buffer. 
 // If decoding succeeded, it must continue from the main buffer.
