Package com.palantir.common.compression
Class BufferedDelegateInputStream
- java.lang.Object
-
- java.io.InputStream
-
- com.palantir.common.compression.BufferedDelegateInputStream
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
LZ4CompressingInputStream
public abstract class BufferedDelegateInputStream extends InputStream
InputStream
that wraps a delegate InputStream, buffering reads to the delegate. Allows a customized strategy for refilling the internal buffer from the delegate stream for use cases such as decompressing a compressed stream.
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]
buffer
protected static int
BUFFER_START
protected InputStream
delegate
protected static int
READ_FAILED
-
Constructor Summary
Constructors Constructor Description BufferedDelegateInputStream(InputStream delegate, int bufferLength)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description int
available()
void
close()
int
read()
int
read(byte[] b, int off, int len)
Reads up tolen
bytes into the provided byte arrayb
.protected abstract int
refill()
Refills the internal buffer from the delegateInputStream
.-
Methods inherited from class java.io.InputStream
mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
-
-
-
-
Field Detail
-
READ_FAILED
protected static final int READ_FAILED
- See Also:
- Constant Field Values
-
BUFFER_START
protected static final int BUFFER_START
- See Also:
- Constant Field Values
-
delegate
protected final InputStream delegate
-
buffer
protected final byte[] buffer
-
-
Constructor Detail
-
BufferedDelegateInputStream
public BufferedDelegateInputStream(InputStream delegate, int bufferLength)
-
-
Method Detail
-
read
public final int read() throws IOException
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
public final int read(byte[] b, int off, int len) throws IOException
Reads up tolen
bytes into the provided byte arrayb
. If no remaining unread bytes are available in the internal buffer,refill
is called to refill the internal buffer. Otherwise, eitherlen
bytes or the number of bytes available in the buffer are read, whichever is smaller. To read from the buffer until either the end of the stream is reached orlen
bytes have been read, useByteStreams.read
.- Overrides:
read
in classInputStream
- Throws:
IOException
-
available
public final int available()
- Overrides:
available
in classInputStream
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
refill
protected abstract int refill() throws IOException
Refills the internal buffer from the delegateInputStream
.- Returns:
- The number of bytes written to the buffer while refilling it.
- Throws:
IOException
-
-