| java.lang.Object java.io.OutputStream org.archive.io.RecordingOutputStream
RecordingOutputStream | public class RecordingOutputStream extends OutputStream (Code) | | An output stream that records all writes to wrapped output
stream.
A RecordingOutputStream can be wrapped around any other
OutputStream to record all bytes written to it. You can
then request a ReplayInputStream to read those bytes.
The RecordingOutputStream uses an in-memory buffer and
backing disk file to allow it to record streams of
arbitrary length limited only by available disk space.
As long as the stream recorded is smaller than the
in-memory buffer, no disk access will occur.
Recorded content can be recovered as a ReplayInputStream
(via getReplayInputStream() or, for only the content after
the content-begin-mark is set, getContentReplayInputStream() )
or as a ReplayCharSequence (via getReplayCharSequence()).
This class is also used as a straight output stream
by
RecordingInputStream to which it records all reads.
RecordingInputStream is exploiting the file backed buffer
facility of this class passing null for the stream
to wrap. TODO: Make a FileBackedOutputStream class that is
subclassed by RecordingInputStream.
author: gojomo |
Method Summary | |
protected void | checkLimits() Check any enforced limits. | public void | close() | protected synchronized void | closeDiskStream() | public void | closeRecorder() | public void | flush() | public long | getContentBegin() | public ReplayInputStream | getContentReplayInputStream() | public byte[] | getDigestValue() Return the digest value for any recorded, digested data. | public long | getRemainingLength() | public ReplayCharSequence | getReplayCharSequence() | public ReplayCharSequence | getReplayCharSequence(String characterEncoding) | public ReplayCharSequence | getReplayCharSequence(String characterEncoding, long startOffset) Parameters: characterEncoding - Encoding of recorded stream. | public ReplayInputStream | getReplayInputStream() | public ReplayInputStream | getReplayInputStream(long skip) | public long | getResponseContentLength() | public long | getSize() | public boolean | isOpen() | public void | mark() When used alongside a mark-supporting RecordingInputStream, remember
a position reachable by a future reset(). | public void | markContentBegin() Remember the current position as the start of the "response
body". | public void | open() Wrap the given stream, both recording and passing along any data written
to this RecordingOutputStream. | public void | open(OutputStream wrappedStream) Wrap the given stream, both recording and passing along any data written
to this RecordingOutputStream.
Parameters: wrappedStream - Stream to wrap. | public void | reset() When used alongside a mark-supporting RecordingInputStream, reset
the position to that saved by previous mark(). | public void | resetLimits() | public void | setDigest(String algorithm) Sets a digest function which may be applied to recorded data. | public void | setDigest(MessageDigest md) Sets a digest function which may be applied to recorded data. | public void | setLimits(long length, long milliseconds, long rateKBps) Set limits on length, time, and rate to enforce. | public void | setSha1Digest() Convenience method for setting SHA1 digest. | public void | startDigest() Starts digesting recorded data, if a MessageDigest has been
set. | public void | write(int b) | public void | write(byte[] b, int off, int len) |
MAX_HEADER_MATERIAL | final protected static long MAX_HEADER_MATERIAL(Code) | | Maximum amount of header material to accept without the content
body beginning -- if more, throw a RecorderTooMuchHeaderException.
TODO: make configurable? make smaller?
|
bufStreamBuf | protected byte[] bufStreamBuf(Code) | | Reusable buffer for FastBufferedOutputStream
|
maxLength | protected long maxLength(Code) | | maximum length of material to record before throwing exception
|
maxRateBytesPerMs | protected long maxRateBytesPerMs(Code) | | maximum rate to record (adds delays to hit target rate)
|
startTime | protected long startTime(Code) | | time recording begins for timeout, rate calculations
|
timeoutMs | protected long timeoutMs(Code) | | maximum time to record before throwing exception
|
RecordingOutputStream | public RecordingOutputStream(int bufferSize, String backingFilename)(Code) | | Create a new RecordingOutputStream.
Parameters: bufferSize - Buffer size to use. Parameters: backingFilename - Name of backing file to use. |
closeDiskStream | protected synchronized void closeDiskStream() throws IOException(Code) | | |
getContentBegin | public long getContentBegin()(Code) | | Return stored content-begin-mark (which is also end-of-headers)
|
getDigestValue | public byte[] getDigestValue()(Code) | | Return the digest value for any recorded, digested data. Call
only after all data has been recorded; otherwise, the running
digest state is ruined.
the digest final value |
getRemainingLength | public long getRemainingLength()(Code) | | Return number of bytes that could be recorded without hitting
length limit
long byte count |
getReplayCharSequence | public ReplayCharSequence getReplayCharSequence(String characterEncoding, long startOffset) throws IOException(Code) | | Parameters: characterEncoding - Encoding of recorded stream. A ReplayCharSequence Will return null if an IOException. Callclose on returned RCS when done. throws: IOException - |
getResponseContentLength | public long getResponseContentLength()(Code) | | |
getSize | public long getSize()(Code) | | |
isOpen | public boolean isOpen()(Code) | | True if this ROS is open. |
mark | public void mark()(Code) | | When used alongside a mark-supporting RecordingInputStream, remember
a position reachable by a future reset().
|
markContentBegin | public void markContentBegin()(Code) | | Remember the current position as the start of the "response
body". Useful when recording HTTP traffic as a way to start
replays after the headers.
|
open | public void open() throws IOException(Code) | | Wrap the given stream, both recording and passing along any data written
to this RecordingOutputStream.
throws: IOException - If failed creation of backing file. |
open | public void open(OutputStream wrappedStream) throws IOException(Code) | | Wrap the given stream, both recording and passing along any data written
to this RecordingOutputStream.
Parameters: wrappedStream - Stream to wrap. May be null for case where wewant to write to a file backed stream only. throws: IOException - If failed creation of backing file. |
reset | public void reset()(Code) | | When used alongside a mark-supporting RecordingInputStream, reset
the position to that saved by previous mark(). Until the position
again reached "new" material, none of the bytes pushed to this
stream will be digested or recorded.
|
resetLimits | public void resetLimits()(Code) | | Reset limits to effectively-unlimited defaults
|
setDigest | public void setDigest(MessageDigest md)(Code) | | 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 - Message digest function to use. |
setLimits | public void setLimits(long length, long milliseconds, long rateKBps)(Code) | | Set limits on length, time, and rate to enforce.
Parameters: length - Parameters: milliseconds - Parameters: rateKBps - |
startDigest | public void startDigest()(Code) | | Starts digesting recorded data, if a MessageDigest has been
set.
|
|
|