Package com.attivio.util.stream
Class RestartableInputStream
- java.lang.Object
-
- java.io.InputStream
-
- com.attivio.util.stream.RestartableInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public final class RestartableInputStream extends java.io.InputStream
Buffers an input stream to disk.
-
-
Constructor Summary
Constructors Constructor Description RestartableInputStream(java.io.InputStream stream)
Uses the default tmp directory.RestartableInputStream(java.io.InputStream stream, java.io.File tempDirectory)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
void
cleanup()
Cleanup the underlying temp file.void
close()
Closed the wrapped stream and cleanup any temp files createdprotected void
finalize()
Cleanup anyjava.io.File
getTempFile()
static RestartableInputStream
makeRestartable(java.io.InputStream stream)
Makes a RestartableInputStream fromstream
, using (if necessary) temporary disk storage.static RestartableInputStream
makeRestartable(java.io.InputStream stream, java.io.File tempDirectory)
Makes a RestartableInputStream fromstream
, using (if necessary) temporary disk storage.void
mark(int readLimit)
boolean
markSupported()
Returns trueint
read()
int
read(byte[] b)
int
read(byte[] b, int off, int len)
void
reset()
void
restart()
Restart the input stream from the beginning.long
skip(long n)
-
-
-
Constructor Detail
-
RestartableInputStream
public RestartableInputStream(java.io.InputStream stream) throws java.io.IOException
Uses the default tmp directory.- Throws:
java.io.IOException
-
RestartableInputStream
public RestartableInputStream(java.io.InputStream stream, java.io.File tempDirectory) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
cleanup
public void cleanup() throws java.io.IOException
Cleanup the underlying temp file.- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOException
- Specified by:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
available
public int available() throws java.io.IOException
- Overrides:
available
in classjava.io.InputStream
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
Closed the wrapped stream and cleanup any temp files created- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.InputStream
- Throws:
java.io.IOException
-
mark
public void mark(int readLimit)
- Overrides:
mark
in classjava.io.InputStream
-
markSupported
public boolean markSupported()
Returns true- Overrides:
markSupported
in classjava.io.InputStream
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] b) throws java.io.IOException
- Overrides:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
reset
public void reset() throws java.io.IOException
- Overrides:
reset
in classjava.io.InputStream
- Throws:
java.io.IOException
-
skip
public long skip(long n) throws java.io.IOException
- Overrides:
skip
in classjava.io.InputStream
- Throws:
java.io.IOException
-
finalize
protected void finalize() throws java.io.IOException
Cleanup any- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.io.IOException
-
getTempFile
public java.io.File getTempFile()
-
restart
public void restart() throws java.io.IOException
Restart the input stream from the beginning.- Throws:
java.io.IOException
-
makeRestartable
public static RestartableInputStream makeRestartable(java.io.InputStream stream, java.io.File tempDirectory) throws java.io.IOException
Makes a RestartableInputStream fromstream
, using (if necessary) temporary disk storage.- Parameters:
stream
-tempDirectory
-- Returns:
- the input
stream
wrapped by a RestartableInputStream - Throws:
java.io.IOException
-
makeRestartable
public static RestartableInputStream makeRestartable(java.io.InputStream stream) throws java.io.IOException
Makes a RestartableInputStream fromstream
, using (if necessary) temporary disk storage.- Parameters:
stream
-- Returns:
- the input
stream
wrapped by a RestartableInputStream - Throws:
java.io.IOException
-
-