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.util
Class HttpRecorder

    java.lang.Object
      org.archive.util.HttpRecorder

    public class HttpRecorder

extends java.lang.Object

Pairs together a RecordingInputStream and RecordingOutputStream to capture exactly a single HTTP transaction. Initially only supports HTTP/1.0 (one request, one response per stream) Call `markContentBegin()` to demarc the transition between HTTP header and body.

Author:
  gojomo

Field Summary
`protected static java.util.logging.Logger` | `logger`

Constructor Summary
`protected` | `HttpRecorder()` Constructor with limited access.
`` | `HttpRecorder(java.io.File tempDir, java.lang.String backingFilenameBase)` Create an HttpRecorder.
`` | `HttpRecorder(java.io.File tempDir, java.lang.String backingFilenameBase, int outBufferSize, int inBufferSize)` Create an HttpRecorder.

Method Summary
`void` | `cleanup()` Cleanup backing files.
`void` | `close()` Close all streams.
`void` | `closeRecorders()` Close both input and output recorders.
`java.lang.String` | `getCharacterEncoding()`
`static HttpRecorder` | `getHttpRecorder()` Get the current threads' HttpRecorder.
`RecordingInputStream` | `getRecordedInput()` Return the internal RecordingInputStream
`RecordingOutputStream` | `getRecordedOutput()`
`ReplayCharSequence` | `getReplayCharSequence()`
`ReplayInputStream` | `getReplayInputStream()`
`long` | `getResponseContentLength()`
`java.io.InputStream` | `inputWrap(java.io.InputStream is)` Wrap the provided stream with the internal RecordingInputStream open() throws an exception if RecordingInputStream is already open.
`void` | `markContentBegin()` Mark current position as the point where the HTTP headers end.
`java.io.OutputStream` | `outputWrap(java.io.OutputStream os)` Wrap the provided stream with the internal RecordingOutputStream open() throws an exception if RecordingOutputStream is already open.
`void` | `setCharacterEncoding(java.lang.String characterEncoding)`
`static HttpRecorder` | `wrapInputStreamWithHttpRecord(java.io.File dir, java.lang.String basename, java.io.InputStream in, java.lang.String encoding)` Record the input stream for later playback by an extractor, etc.

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

Constructor Detail

### HttpRecorder

    protected HttpRecorder()

  Constructor with limited access. Used internally for case where we're wrapping an already downloaded stream with a HttpRecorder.

### HttpRecorder

    public HttpRecorder(java.io.File tempDir,
                        java.lang.String backingFilenameBase,
                        int outBufferSize,
                        int inBufferSize)

  Create an HttpRecorder.

  Parameters:
    `tempDir` - Directory into which we drop backing files for recorded input and output.
    `backingFilenameBase` - Backing filename base to which we'll append suffices `ris` for recorded input stream and `ros` for recorded output stream.
    `outBufferSize` - Size of output buffer to use.
    `inBufferSize` - Size of input buffer to use.

### HttpRecorder

    public HttpRecorder(java.io.File tempDir,
                        java.lang.String backingFilenameBase)

  Create an HttpRecorder.

  Parameters:
    `tempDir` - Directory into which we drop backing files for recorded input and output.
    `backingFilenameBase` - Backing filename base to which we'll append suffices `ris` for recorded input stream and `ros` for recorded output stream.

Method Detail

### inputWrap

    public java.io.InputStream inputWrap(java.io.InputStream is)
                                  throws java.io.IOException

  Wrap the provided stream with the internal RecordingInputStream open() throws an exception if RecordingInputStream is already open.

  Parameters:
    `is` - InputStream to wrap.
  Returns:
    The input stream wrapper which itself is an input stream. Pass this in place of the passed stream so input can be recorded.
  Throws:
    `java.io.IOException`

### outputWrap

    public java.io.OutputStream outputWrap(java.io.OutputStream os)
                                    throws java.io.IOException

  Wrap the provided stream with the internal RecordingOutputStream open() throws an exception if RecordingOutputStream is already open.

  Parameters:
    `os` - The output stream to wrap.
  Returns:
    The output stream wrapper which is itself an output stream. Pass this in place of the passed stream so output can be recorded.
  Throws:
    `java.io.IOException`

### close

    public void close()

  Close all streams.

### getRecordedInput

    public RecordingInputStream getRecordedInput()

  Return the internal RecordingInputStream

  Returns:
    A RIS.

### getRecordedOutput

    public RecordingOutputStream getRecordedOutput()

  Returns:
    The RecordingOutputStream.

### markContentBegin

    public void markContentBegin()

  Mark current position as the point where the HTTP headers end.

### getResponseContentLength

    public long getResponseContentLength()

### closeRecorders

    public void closeRecorders()

  Close both input and output recorders. Recorders are the output streams to which we are recording. `close()` closes the stream that is being recorded and the recorder. This method explicitly closes the recorder only.

### cleanup

    public void cleanup()

  Cleanup backing files. Call when completely done w/ recorder. Removes any backing files that may have been dropped.

### getHttpRecorder

    public static HttpRecorder getHttpRecorder()

  Get the current threads' HttpRecorder.

  Returns:
    This threads' HttpRecorder. Returns null if can't find a HttpRecorder in current instance.

### setCharacterEncoding

    public void setCharacterEncoding(java.lang.String characterEncoding)

  Parameters:
    `characterEncoding` - Character encoding of recording.

### getCharacterEncoding

    public java.lang.String getCharacterEncoding()

  Returns:
    Returns the characterEncoding.

### getReplayCharSequence

    public ReplayCharSequence getReplayCharSequence()
                                             throws java.io.IOException

  Returns:
    A ReplayCharSequence. Call close on the RCS when done w/ it. Will return indeterminate results if the underlying recording streams have not been closed first.
  Throws:
    `java.io.IOException`
    `java.io.IOException`

### getReplayInputStream

    public ReplayInputStream getReplayInputStream()
                                           throws java.io.IOException

  Returns:
    A replay input stream.
  Throws:
    `java.io.IOException`

### wrapInputStreamWithHttpRecord

    public static HttpRecorder wrapInputStreamWithHttpRecord(java.io.File dir,
                                                             java.lang.String basename,
                                                             java.io.InputStream in,
                                                             java.lang.String encoding)
                                                      throws java.io.IOException

  Record the input stream for later playback by an extractor, etc. This is convenience method used to setup an artificial HttpRecorder scenario used in unit tests, etc.

  Parameters:
    `dir` - Directory to write backing file to.
    `basename` - of what we're recording.
    `in` - Stream to read.
    `encoding` - Stream encoding.
  Returns:
    An `HttpRecorder`.
  Throws:
    `java.io.IOException`

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.