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.InputStreamBuffers 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 intavailable()voidcleanup()Cleanup the underlying temp file.voidclose()Closed the wrapped stream and cleanup any temp files createdprotected voidfinalize()Cleanup anyjava.io.FilegetTempFile()static RestartableInputStreammakeRestartable(java.io.InputStream stream)Makes a RestartableInputStream fromstream, using (if necessary) temporary disk storage.static RestartableInputStreammakeRestartable(java.io.InputStream stream, java.io.File tempDirectory)Makes a RestartableInputStream fromstream, using (if necessary) temporary disk storage.voidmark(int readLimit)booleanmarkSupported()Returns trueintread()intread(byte[] b)intread(byte[] b, int off, int len)voidreset()voidrestart()Restart the input stream from the beginning.longskip(long n)
-
-
-
Constructor Detail
-
RestartableInputStream
public RestartableInputStream(java.io.InputStream stream) throws java.io.IOExceptionUses 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.IOExceptionCleanup the underlying temp file.- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOException- Specified by:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
available
public int available() throws java.io.IOException- Overrides:
availablein classjava.io.InputStream- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOExceptionClosed the wrapped stream and cleanup any temp files created- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.InputStream- Throws:
java.io.IOException
-
mark
public void mark(int readLimit)
- Overrides:
markin classjava.io.InputStream
-
markSupported
public boolean markSupported()
Returns true- Overrides:
markSupportedin classjava.io.InputStream
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException- Overrides:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b) throws java.io.IOException- Overrides:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
reset
public void reset() throws java.io.IOException- Overrides:
resetin classjava.io.InputStream- Throws:
java.io.IOException
-
skip
public long skip(long n) throws java.io.IOException- Overrides:
skipin classjava.io.InputStream- Throws:
java.io.IOException
-
finalize
protected void finalize() throws java.io.IOExceptionCleanup any- Overrides:
finalizein classjava.lang.Object- Throws:
java.io.IOException
-
getTempFile
public java.io.File getTempFile()
-
restart
public void restart() throws java.io.IOExceptionRestart 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
streamwrapped 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
streamwrapped by a RestartableInputStream - Throws:
java.io.IOException
-
-