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 ByteReplayCharSequence

    java.lang.Object
      org.archive.io.ByteReplayCharSequence

All Implemented Interfaces:
  java.lang.CharSequence, ReplayCharSequence

     class ByteReplayCharSequence

extends java.lang.Object
implements ReplayCharSequence

Provides a (Replay)CharSequence view on recorded stream bytes (a prefix buffer and overflow backing file). Treats the byte stream as 8-bit.

Uses a wraparound rolling buffer of the last windowSize bytes read from disk in memory; as long as the 'random access' of a CharSequence user stays within this window, access should remain fairly efficient. (So design any regexps pointed at these CharSequences to work within that range!)

When rereading of a location is necessary, the whole window is recentered around the location requested. (TODO: More research into whether this is the best strategy.)

An implementation of a ReplayCharSequence done with ByteBuffers -- one to wrap the passed prefix buffer and the second, a memory-mapped ByteBuffer view into the backing file -- was consistently slower: ~10%. My tests did the following. Made a buffer filled w/ regular content. This buffer was used as the prefix buffer. The buffer content was written MULTIPLER times to a backing file. I then did accesses w/ the following pattern: Skip forward 32 bytes, then back 16 bytes, and then read forward from byte 16-32. Repeat. Though I varied the size of the buffer to the size of the backing file,from 3-10, the difference of 10% or so seemed to persist. Same if I tried to favor get() over get(index). I used a profiler, JMP, to study times taken (St.Ack did above comment).

TODO determine in memory mapped files is better way to do this; probably not -- they don't offer the level of control over total memory used that this approach does.

Version:
  $Revision: 5027 $, $Date: 2007-03-29 00:30:33 +0000 (Thu, 29 Mar 2007) $
Author:
  Gordon Mohr

Field Summary
`protected int` | `length` Total length of character stream to replay minus the HTTP headers if present.
`protected static java.util.logging.Logger` | `logger`

Constructor Summary
`ByteReplayCharSequence(byte[] buffer, long size, long responseBodyStart, java.lang.String backingFilename)` Constructor.

Method Summary
`char` | `charAt(int index)` Get character at passed absolute position.
`void` | `close()` Cleanup resources.
`protected void` | `finalize()`
`int` | `length()`
`java.lang.CharSequence` | `subSequence(int start, int end)`
`java.lang.String` | `substring(int offset, int len)` Deprecated. please use subSequence() and then toString() directly
`java.lang.String` | `toString()`

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

Field Detail

### logger

    protected static java.util.logging.Logger logger

### length

    protected int length

  Total length of character stream to replay minus the HTTP headers if present. Used to find EOS.

Constructor Detail

### ByteReplayCharSequence

    public ByteReplayCharSequence(byte[] buffer,
                                  long size,
                                  long responseBodyStart,
                                  java.lang.String backingFilename)
                           throws java.io.IOException

  Constructor.

  Parameters:
    `buffer` - In-memory buffer of recordings prefix. We read from here first and will only go to the backing file if `size` requested is greater than `buffer.length`.
    `size` - Total size of stream to replay in bytes. Used to find EOS. This is total length of content including HTTP headers if present.
    `responseBodyStart` - Where the response body starts in bytes. Used to skip over the HTTP headers if present.
    `backingFilename` - Path to backing file with content in excess of whats in `buffer`.
  Throws:
    `java.io.IOException`

Method Detail

### length

    public int length()

  Specified by:
    `length` in interface `java.lang.CharSequence`
  Returns:
    Length of characters in stream to replay. Starts counting at the HTTP header/body boundary.

### charAt

    public char charAt(int index)

  Get character at passed absolute position. Called by `charAt(int)` which has a relative index into the content, one that doesn't account for HTTP header if present.

  Specified by:
    `charAt` in interface `java.lang.CharSequence`
  Parameters:
    `index` - Index into content adjusted to accomodate initial offset to get us past the HTTP header if present (i.e. `contentOffset`).
  Returns:
    Characater at offset `index`.

### subSequence

    public java.lang.CharSequence subSequence(int start,
                                              int end)

  Specified by:
    `subSequence` in interface `java.lang.CharSequence`

### close

    public void close()
               throws java.io.IOException

  Cleanup resources.

  Specified by:
    `close` in interface `ReplayCharSequence`
  Throws:
    `java.io.IOException` - Failed close of random access file.

### finalize

    protected void finalize()
                     throws java.lang.Throwable

  Overrides:
    `finalize` in class `java.lang.Object`
  Throws:
    `java.lang.Throwable`

### substring

    public java.lang.String substring(int offset,
                                      int len)

  Deprecated. please use subSequence() and then toString() directly

  Convenience method for getting a substring.

### toString

    public java.lang.String toString()

  Specified by:
    `toString` in interface `java.lang.CharSequence`
  Overrides:
    `toString` in class `java.lang.Object`

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.