Class ReplayInputStream
java.lang.Object
java.io.InputStream
org.archive.io.SeekInputStream
org.archive.io.ReplayInputStream
- All Implemented Interfaces:
RepositionableStream,Closeable,AutoCloseable
Replays the bytes recorded from a RecordingInputStream or
RecordingOutputStream.
This InputStream supports mark and reset.
- Author:
- gojomo
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Fileprotected longWhere the response body starts, if marked -
Constructor Summary
ConstructorsConstructorDescriptionReplayInputStream(byte[] buffer, long size, long responseBodyStart, String backingFilename) Constructor.ReplayInputStream(byte[] buffer, long size, String backingFilename) Constructor.ReplayInputStream(InputStream fillStream) Create a ReplayInputStream from the given source stream. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voiddestroy()Close & destroy any internally-generated temporary files.protected byte[]longTotal size of content.longTotal size of header.longgetSize()Total size of stream content.longposition()Returns the current stream position.voidposition(long p) Reposition the stream.intread()intread(byte[] b, int off, int len) voidvoidreadContentTo(OutputStream os, long maxSize) Convenience method to copy content out to target stream.static voidreadFullyTo(InputStream in, OutputStream os) voidvoidlonglongprotected voidsetupDiskStream(File backingFile) Methods inherited from class org.archive.io.SeekInputStream
mark, markSupported, resetMethods inherited from class java.io.InputStream
available, read, skip
-
Field Details
-
responseBodyStart
protected long responseBodyStartWhere the response body starts, if marked -
backingFile
-
-
Constructor Details
-
ReplayInputStream
public ReplayInputStream(byte[] buffer, long size, long responseBodyStart, String backingFilename) throws IOException Constructor.- Parameters:
buffer- Buffer to read from.size- Size of data to replay.responseBodyStart- Start of the response body.backingFilename- Backing file that sits behind the buffer. Ifsize> than buffer then we go to backing file to read data that is beyond buffer.length.- Throws:
IOException- If we fail to open an input stream on backing file.
-
ReplayInputStream
Constructor.- Parameters:
buffer- Buffer to read from.size- Size of data to replay.backingFilename- Backing file that sits behind the buffer. Ifsize> than buffer then we go to backing file to read data that is beyond buffer.length.- Throws:
IOException- If we fail to open an input stream on backing file.
-
ReplayInputStream
Create a ReplayInputStream from the given source stream. Requires reading the entire stream (and possibly overflowing to a temporary file). Primary reason for doing so would be to have a repositionable version of the original stream's contents. If created via this constructor, use the destroy() method to ensure prompt deletion of any associated tmp file when done.- Parameters:
fillStream-- Throws:
IOException
-
-
Method Details
-
setupDiskStream
- Throws:
IOException
-
destroy
public void destroy()Close & destroy any internally-generated temporary files. -
setToResponseBodyStart
- Throws:
IOException
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
readFullyTo
- Throws:
IOException
-
readFullyTo
- Throws:
IOException
-
readHeaderTo
- Throws:
IOException
-
readContentTo
- Throws:
IOException
-
readContentTo
Convenience method to copy content out to target stream.- Parameters:
os- stream to write content tomaxSize- maximum count of bytes to copy- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
getSize
public long getSize()Total size of stream content.- Returns:
- Returns the size.
-
getHeaderSize
public long getHeaderSize()Total size of header.- Returns:
- the size of the header.
-
getContentSize
public long getContentSize()Total size of content.- Returns:
- the size of the content.
-
remaining
public long remaining()- Returns:
- Amount THEORETICALLY remaining (TODO: Its not theoretical seemingly. The class implemetentation depends on it being exact).
-
position
Reposition the stream.- Parameters:
p- the new position for this stream- Throws:
IOException- if an IO error occurs
-
position
Description copied from interface:RepositionableStreamReturns the current stream position.- Returns:
- the current stream position.
- Throws:
IOException
-
getBuffer
protected byte[] getBuffer()
-