@Override
    public void onWrite() throws IOException {
        if (mCallback != null) {
            mCallback.onWrite();
        }
        // Write pending buffers.
        while (!mPendingBuffers.isEmpty()) {
            ByteBuffer buffer = mPendingBuffers.pollFirst();
            int remaining = buffer.remaining();
            int sent = channelWrite(buffer);
            if (sent < remaining) {
                // Should wait next onWrite.
                mPendingBuffers.offerFirst(buffer);
                return;
            }
        }
        interestRead();
    }
Read data from remote server and put it into the given buffer.

@param buffer A buffer to store data.
@return The read length.
@throws IOException if an I/O error occurs.
netbare-core/src/main/java/com/github/megatronking/netbare/tunnel/NioTunnel.java