Package org.jets3t.service.io
Class RepeatableInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.jets3t.service.io.RepeatableInputStream
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,InputStreamWrapper
public class RepeatableInputStream extends InputStream implements InputStreamWrapper
A repeatable input stream wrapper for any input stream. This input stream relies on buffered data to repeat, and can therefore only be repeated when less data has been read than this buffer can hold.Note: Always use a
RepeatableFileInputStream
instead of this class if you are sourcing data from a file, as the file-based repeatable input stream can be repeated without any limitations.This class uses properties obtained through
Jets3tProperties
. For more information on these properties please refer to JetS3t Configuration- Author:
- James Murty
-
-
Constructor Summary
Constructors Constructor Description RepeatableInputStream(InputStream inputStream, int bufferSize)
Creates a repeatable input stream based on another input stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
void
close()
InputStream
getWrappedInputStream()
void
mark(int readlimit)
This method can only be used while less data has been read from the input stream than fits into the buffer.boolean
markSupported()
int
read()
int
read(byte[] out, int outOffset, int outLength)
void
reset()
Resets the input stream to the beginning by pointing the buffer offset to the beginning of the available data buffer.-
Methods inherited from class java.io.InputStream
nullInputStream, read, readAllBytes, readNBytes, readNBytes, skip, transferTo
-
-
-
-
Constructor Detail
-
RepeatableInputStream
public RepeatableInputStream(InputStream inputStream, int bufferSize)
Creates a repeatable input stream based on another input stream.- Parameters:
inputStream
- an input stream to wrap. The data read from the wrapped input stream is buffered as it is read, up to the buffer limit specified.bufferSize
- the number of bytes buffered by this class.
-
-
Method Detail
-
reset
public void reset() throws IOException
Resets the input stream to the beginning by pointing the buffer offset to the beginning of the available data buffer.- Overrides:
reset
in classInputStream
- Throws:
UnrecoverableIOException
- when the available buffer size has been exceeded, in which case the input stream data cannot be repeated.IOException
-
markSupported
public boolean markSupported()
- Overrides:
markSupported
in classInputStream
-
mark
public void mark(int readlimit)
This method can only be used while less data has been read from the input stream than fits into the buffer. The readLimit parameter is ignored entirely.- Overrides:
mark
in classInputStream
-
available
public int available() throws IOException
- Overrides:
available
in classInputStream
- Throws:
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
read
public int read(byte[] out, int outOffset, int outLength) throws IOException
- Overrides:
read
in classInputStream
- Throws:
IOException
-
read
public int read() throws IOException
- Specified by:
read
in classInputStream
- Throws:
IOException
-
getWrappedInputStream
public InputStream getWrappedInputStream()
- Specified by:
getWrappedInputStream
in interfaceInputStreamWrapper
- Returns:
- the underlying input stream wrapped by this class.
-
-