org.archive.io
Class ReplayInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.archive.io.SeekInputStream
          extended by org.archive.io.ReplayInputStream
All Implemented Interfaces:
it.unimi.dsi.fastutil.io.RepositionableStream, java.io.Closeable

public class ReplayInputStream
extends SeekInputStream

Replays the bytes recorded from a RecordingInputStream or RecordingOutputStream. This InputStream supports mark and reset.

Author:
gojomo

Field Summary
protected  long responseBodyStart
          Where the response body starts, if marked
 
Constructor Summary
ReplayInputStream(byte[] buffer, long size, long responseBodyStart, java.lang.String backingFilename)
          Constructor.
ReplayInputStream(byte[] buffer, long size, java.lang.String backingFilename)
          Constructor.
 
Method Summary
 void close()
           
 long getContentSize()
          Total size of content.
 long getHeaderSize()
          Total size of header.
 long getSize()
          Total size of stream content.
 long position()
           
 void position(long p)
          Reposition the stream.
 int read()
           
 int read(byte[] b, int off, int len)
           
 void readContentTo(java.io.OutputStream os)
           
 void readContentTo(java.io.OutputStream os, int maxSize)
           
 void readFullyTo(java.io.OutputStream os)
           
 void readHeaderTo(java.io.OutputStream os)
           
 long remaining()
           
 long setToResponseBodyStart()
           
 
Methods inherited from class org.archive.io.SeekInputStream
mark, markSupported, reset
 
Methods inherited from class java.io.InputStream
available, read, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

responseBodyStart

protected long responseBodyStart
Where the response body starts, if marked

Constructor Detail

ReplayInputStream

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

Parameters:
buffer - Buffer to read from.
size - Size of data to replay.
responseBodyStart - Start of the response body.
backingFilename - Backing file that sits behind the buffer. If size > than buffer then we go to backing file to read data that is beyond buffer.length.
Throws:
java.io.IOException - If we fail to open an input stream on backing file.

ReplayInputStream

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

Parameters:
buffer - Buffer to read from.
size - Size of data to replay.
backingFilename - Backing file that sits behind the buffer. If size > than buffer then we go to backing file to read data that is beyond buffer.length.
Throws:
java.io.IOException - If we fail to open an input stream on backing file.
Method Detail

setToResponseBodyStart

public long setToResponseBodyStart()
                            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

readFullyTo

public void readFullyTo(java.io.OutputStream os)
                 throws java.io.IOException
Throws:
java.io.IOException

readHeaderTo

public void readHeaderTo(java.io.OutputStream os)
                  throws java.io.IOException
Throws:
java.io.IOException

readContentTo

public void readContentTo(java.io.OutputStream os)
                   throws java.io.IOException
Throws:
java.io.IOException

readContentTo

public void readContentTo(java.io.OutputStream os,
                          int maxSize)
                   throws java.io.IOException
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

getSize

public long getSize()
Total size of stream content.

Returns:
Returns the size.

getHeaderSize

public long getHeaderSize()
Total size of header.

Returns:
the size of the header.

getContentSize

public long getContentSize()
Total size of content.

Returns:
the size of the content.

remaining

public long remaining()
Returns:
Amount THEORETICALLY remaining (TODO: Its not theoretical seemingly. The class implemetentation depends on it being exact).

position

public void position(long p)
              throws java.io.IOException
Reposition the stream.

Parameters:
p - the new position for this stream
Throws:
java.io.IOException - if an IO error occurs

position

public long position()
              throws java.io.IOException
Throws:
java.io.IOException


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