com.koushikdutta.async.stream.ByteBufferListInputStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of androidasync Show documentation
Show all versions of androidasync Show documentation
Asynchronous socket, http(s) (client+server) and websocket library for android. Based on nio, not threads.
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;
}
}