Example usage for io.netty.buffer ByteBuf readBytes

List of usage examples for io.netty.buffer ByteBuf readBytes

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf readBytes.

Prototype

public abstract int readBytes(FileChannel out, long position, int length) throws IOException;

Source Link

Document

Transfers this buffer's data starting at the current readerIndex to the specified channel starting at the given file position.

Usage

From source file:io.liveoak.common.codec.FileUploadInputStream.java

License:Open Source License

public FileUploadInputStream(FileUpload fileUpload, int bufSize) {
    super(new InputStream() {
        @Override/*from  w  w w.  j  a va  2s  .  c om*/
        public int read() throws IOException {
            throw new IllegalStateException("Implementation error!");
        }

        public int read(byte[] buf, int pos, int len) throws IOException {
            ByteBuf buffer = fileUpload.getChunk(len);
            if (buffer.readableBytes() == 0) {
                return -1;
            } else {
                int cc = len > buffer.readableBytes() ? buffer.readableBytes() : len;
                buffer.readBytes(buf, pos, cc);
                return cc;
            }
        }
    }, bufSize);
}