mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-26 01:38:57 -05:00
eabe011e9a
* ByteBufferInputStream behaves like any other InputStream now * updated nekohtml
48 lines
791 B
Java
48 lines
791 B
Java
|
|
package net.sourceforge.tuned;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.nio.ByteBuffer;
|
|
|
|
|
|
public class ByteBufferInputStream extends InputStream {
|
|
|
|
private final ByteBuffer buffer;
|
|
|
|
|
|
public ByteBufferInputStream(ByteBuffer buffer) {
|
|
this.buffer = buffer;
|
|
}
|
|
|
|
|
|
@Override
|
|
public synchronized int read() throws IOException {
|
|
if (buffer.remaining() <= 0)
|
|
return -1;
|
|
|
|
return buffer.get();
|
|
}
|
|
|
|
|
|
@Override
|
|
public synchronized int read(byte[] b, int off, int len) throws IOException {
|
|
if (buffer.remaining() <= 0)
|
|
return -1;
|
|
|
|
int length = Math.min(len, buffer.remaining());
|
|
|
|
buffer.get(b, off, length);
|
|
|
|
return length;
|
|
}
|
|
|
|
|
|
@Override
|
|
public synchronized int available() throws IOException {
|
|
return buffer.remaining();
|
|
}
|
|
|
|
}
|