Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.archive.io
Class RecordingInputStream

    java.lang.Object
      java.io.InputStream
          org.archive.io.RecordingInputStream

All Implemented Interfaces:
  java.io.Closeable

    public class RecordingInputStream

extends java.io.InputStream

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
`protected byte[]` | `drainBuffer` Reusable buffer to avoid reallocation on each readFullyUntil
`protected static java.util.logging.Logger` | `logger`

Constructor Summary
`RecordingInputStream(int bufferSize, java.lang.String backingFilename)` Create a new RecordingInputStream.

Method Summary
`void` | `close()`
`void` | `closeRecorder()`
`void` | `copyContentBodyTo(java.io.File tempFile)`
`long` | `getContentBegin()`
`ReplayInputStream` | `getContentReplayInputStream()`
`byte[]` | `getDigestValue()` Return the digest value for any recorded, digested data.
`ReplayCharSequence` | `getReplayCharSequence()`
`ReplayCharSequence` | `getReplayCharSequence(java.lang.String characterEncoding)`
`ReplayInputStream` | `getReplayInputStream()`
`long` | `getResponseContentLength()`
`long` | `getSize()`
`boolean` | `isOpen()`
`void` | `mark(int readlimit)`
`void` | `markContentBegin()`
`boolean` | `markSupported()`
`void` | `open(java.io.InputStream wrappedStream)`
`int` | `read()`
`int` | `read(byte[] b)`
`int` | `read(byte[] b, int off, int len)`
`long` | `readFully()`
`void` | `readFullyOrUntil(long softMaxLength)` Read all of a stream (Or read until we timeout or have read to the max).
`void` | `reset()`
`void` | `setDigest(java.security.MessageDigest md)` Sets a digest function which may be applied to recorded data.
`void` | `setDigest(java.lang.String algorithm)` Sets a digest algorithm which may be applied to recorded data.
`void` | `setLimits(long hardMax, long timeoutMs, long maxRateKBps)` Set limits to be enforced by internal recording-out
`void` | `setSha1Digest()` Convenience method for setting SHA1 digest.
`void` | `startDigest()`

Methods inherited from class java.io.InputStream
`available, skip`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### logger

    protected static java.util.logging.Logger logger

### drainBuffer

    protected byte[] drainBuffer

  Reusable buffer to avoid reallocation on each readFullyUntil

Constructor Detail

### RecordingInputStream

    public RecordingInputStream(int bufferSize,
                                java.lang.String backingFilename)

  Create a new RecordingInputStream.

  Parameters:
    `bufferSize` - Size of buffer to use.
    `backingFilename` - Name of backing file.

Method Detail

### open

    public void open(java.io.InputStream wrappedStream)
              throws java.io.IOException

  Throws:
    `java.io.IOException`

### read

    public int read()
             throws java.io.IOException

  Specified by:
    `read` in class `java.io.InputStream`
  Throws:
    `java.io.IOException`

### read

    public int read(byte[] b,
                    int off,
                    int len)
             throws java.io.IOException

  Overrides:
    `read` in class `java.io.InputStream`
  Throws:
    `java.io.IOException`

### read

    public int read(byte[] b)
             throws java.io.IOException

  Overrides:
    `read` in class `java.io.InputStream`
  Throws:
    `java.io.IOException`

### close

    public void close()
               throws java.io.IOException

  Specified by:
    `close` in interface `java.io.Closeable`
  Overrides:
    `close` in class `java.io.InputStream`
  Throws:
    `java.io.IOException`

### getReplayInputStream

    public ReplayInputStream getReplayInputStream()
                                           throws java.io.IOException

  Throws:
    `java.io.IOException`

### getContentReplayInputStream

    public ReplayInputStream getContentReplayInputStream()
                                                  throws java.io.IOException

  Throws:
    `java.io.IOException`

### readFully

    public long readFully()
                   throws java.io.IOException

  Throws:
    `java.io.IOException`

### readFullyOrUntil

    public void readFullyOrUntil(long softMaxLength)
                          throws java.io.IOException,
                                 RecorderLengthExceededException,
                                 RecorderTimeoutException,
                                 java.lang.InterruptedException

  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.
    `hardMaxLength` - Maximum length to read; if zero or < 0, then no limit. If exceeded, throw RecorderLengthExceededException
    `timeout` - Timeout in milliseconds for total read; if zero or negative, timeout is `Long.MAX_VALUE`. If exceeded, throw RecorderTimeoutException
    `maxBytesPerMs` - How many bytes per millisecond.
  Throws:
    `java.io.IOException` - failed read.
    `RecorderLengthExceededException`
    `RecorderTimeoutException`
    `java.lang.InterruptedException`

### 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

    public void setDigest(java.lang.String algorithm)

  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

    public void setDigest(java.security.MessageDigest md)

  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

### getReplayCharSequence

    public ReplayCharSequence getReplayCharSequence()
                                             throws java.io.IOException

  Throws:
    `java.io.IOException`

### getReplayCharSequence

    public ReplayCharSequence getReplayCharSequence(java.lang.String characterEncoding)
                                             throws java.io.IOException

  Parameters:
    `characterEncoding` - Encoding of recorded stream.
  Returns:
    A ReplayCharSequence Will return null if an IOException. Call close on returned RCS when done.
  Throws:
    `java.io.IOException`

### getResponseContentLength

    public long getResponseContentLength()

### closeRecorder

    public void closeRecorder()
                       throws java.io.IOException

  Throws:
    `java.io.IOException`

### copyContentBodyTo

    public void copyContentBodyTo(java.io.File tempFile)
                           throws java.io.IOException

  Parameters:
    `tempFile` -
  Throws:
    `java.io.IOException`

### isOpen

    public boolean isOpen()

  Returns:
    True if we've been opened.

### mark

    public void mark(int readlimit)

  Overrides:
    `mark` in class `java.io.InputStream`

### markSupported

    public boolean markSupported()

  Overrides:
    `markSupported` in class `java.io.InputStream`

### reset

    public void reset()
               throws java.io.IOException

  Overrides:
    `reset` in class `java.io.InputStream`
  Throws:
    `java.io.IOException`

### setLimits

    public void setLimits(long hardMax,
                          long timeoutMs,
                          long maxRateKBps)

  Set limits to be enforced by internal recording-out

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2003-2008 Internet Archive. All Rights Reserved.