Class RecordingInputStream
java.lang.Object
java.io.InputStream
org.archive.io.RecordingInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
Stream which records all data read from it, which it acquires from a wrapped
input stream.
Makes use of a RecordingOutputStream for recording because of its being
file backed so we can write massive amounts of data w/o worrying about
overflowing memory.
- Author:
- gojomo
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]Reusable buffer to avoid reallocation on each readFullyUntilprotected static Logger -
Constructor Summary
ConstructorsConstructorDescriptionRecordingInputStream(int bufferSize, String backingFilename) Create a new RecordingInputStream. -
Method Summary
Modifier and TypeMethodDescriptionReturns an OutputStream that can be used for recording input data.voidvoidvoidclose()voidlongbyte[]Return the digest value for any recorded, digested data.intExpose the amount of in-memory buffering used by the internal recording stream.longlonggetSize()booleanisOpen()voidmark(int readlimit) voidbooleanvoidopen(InputStream wrappedStream) intread()intread(byte[] b) intread(byte[] b, int off, int len) longvoidreadFullyOrUntil(long softMaxLength) Deprecated.voidreadToEndOfContent(long contentLength) voidreset()voidSets a digest algorithm which may be applied to recorded data.voidSets a digest function which may be applied to recorded data.voidsetLimits(long hardMax, long timeoutMs, long maxRateKBps) Set limits to be enforced by internal recording-outvoidConvenience method for setting SHA1 digest.voidMethods inherited from class java.io.InputStream
available, skip
-
Field Details
-
logger
-
drainBuffer
protected byte[] drainBufferReusable buffer to avoid reallocation on each readFullyUntil
-
-
Constructor Details
-
RecordingInputStream
Create a new RecordingInputStream.- Parameters:
bufferSize- Size of buffer to use.backingFilename- Name of backing file.
-
-
Method Details
-
open
- Throws:
IOException
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
getReplayInputStream
- Throws:
IOException
-
getMessageBodyReplayInputStream
- Throws:
IOException
-
readFully
- Throws:
IOException
-
readToEndOfContent
- Throws:
IOExceptionInterruptedException
-
readFullyOrUntil
public void readFullyOrUntil(long softMaxLength) throws IOException, RecorderLengthExceededException, RecorderTimeoutException, InterruptedException Deprecated.Read all of a stream (Or read until we timeout or have read to the max).- Parameters:
softMaxLength- Maximum length to read; if zero or < 0, then no limit. If met, return normally.- Throws:
IOException- failed read.RecorderLengthExceededExceptionRecorderTimeoutExceptionInterruptedException
-
getSize
public long getSize() -
markContentBegin
public void markContentBegin() -
getContentBegin
public long getContentBegin() -
startDigest
public void startDigest() -
setSha1Digest
public void setSha1Digest()Convenience method for setting SHA1 digest. -
setDigest
Sets a digest algorithm which may be applied to recorded data. As usually only a subset of the recorded data should be fed to the digest, you must also call startDigest() to begin digesting.- Parameters:
algorithm-
-
setDigest
Sets a digest function which may be applied to recorded data. As usually only a subset of the recorded data should be fed to the digest, you must also call startDigest() to begin digesting.- Parameters:
md-
-
getDigestValue
public byte[] getDigestValue()Return the digest value for any recorded, digested data. Call only after all data has been recorded; otherwise, the running digest state is ruined.- Returns:
- the digest final value
-
getResponseContentLength
public long getResponseContentLength() -
closeRecorder
- Throws:
IOException
-
isOpen
public boolean isOpen()- Returns:
- True if we've been opened.
-
mark
public void mark(int readlimit) - Overrides:
markin classInputStream
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classInputStream
-
reset
- Overrides:
resetin classInputStream- Throws:
IOException
-
setLimits
public void setLimits(long hardMax, long timeoutMs, long maxRateKBps) Set limits to be enforced by internal recording-out -
getRecordedBufferLength
public int getRecordedBufferLength()Expose the amount of in-memory buffering used by the internal recording stream.- Returns:
- int buffer size
-
chopAtMessageBodyBegin
public void chopAtMessageBodyBegin() -
clearForReuse
- Throws:
IOException
-
asOutputStream
Returns an OutputStream that can be used for recording input data. This is useful if the input comes in some form other than an InputStream. For example, if the input is provided by a callback periodically called with a chunk of data.
-