package org.opends.common; import org.glassfish.grizzly.streams.StreamReader; import java.io.InputStream; import java.io.IOException; public class StreamReaderInputStream extends InputStream { private StreamReader streamReader; public StreamReaderInputStream(StreamReader streamReader) { this.streamReader = streamReader; this.streamReader.setBlocking(true); } /** * {@inheritDoc} */ @Override public int available() { return streamReader.availableDataSize(); } /** * {@inheritDoc} */ @Override public int read() throws IOException { return (0xFF & streamReader.readByte()); } /** * {@inheritDoc} */ @Override public int read(byte[] b) throws IOException { return read(b, 0, b.length); } /** * {@inheritDoc} */ @Override public int read(byte[] b, int off, int len) throws IOException { streamReader.readByteArray(b, off, len); return len; } }