All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.koushikdutta.async.stream.ByteBufferListInputStream Maven / Gradle / Ivy

Go to download

Asynchronous socket, http(s) (client+server) and websocket library for android. Based on nio, not threads.

There is a newer version: 3.1.0
Show newest version
package com.koushikdutta.async.stream;

import com.koushikdutta.async.ByteBufferList;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by koush on 6/1/13.
 */
public class ByteBufferListInputStream extends InputStream {
    ByteBufferList bb;
    public ByteBufferListInputStream(ByteBufferList bb) {
        this.bb = bb;
    }

    @Override
    public int read() throws IOException {
        if (bb.remaining() <= 0)
            return -1;
        return bb.get();
    }

    @Override
    public int read(byte[] buffer) throws IOException {
        return this.read(buffer, 0, buffer.length);
    }

    @Override
    public int read(byte[] buffer, int offset, int length) throws IOException {
        if (bb.remaining() <= 0)
            return -1;
        int toRead = Math.min(length, bb.remaining());
        bb.get(buffer, offset, toRead);
        return toRead;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy