Class ReplayInputStream

All Implemented Interfaces:
RepositionableStream, Closeable, AutoCloseable

public class ReplayInputStream extends SeekInputStream
Replays the bytes recorded from a RecordingInputStream or RecordingOutputStream. This InputStream supports mark and reset.
Author:
gojomo
  • Field Details

    • responseBodyStart

      protected long responseBodyStart
      Where the response body starts, if marked
    • backingFile

      protected File backingFile
  • Constructor Details

    • ReplayInputStream

      public ReplayInputStream(byte[] buffer, long size, long responseBodyStart, String backingFilename) throws 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:
      IOException - If we fail to open an input stream on backing file.
    • ReplayInputStream

      public ReplayInputStream(byte[] buffer, long size, String backingFilename) throws 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:
      IOException - If we fail to open an input stream on backing file.
    • ReplayInputStream

      public ReplayInputStream(InputStream fillStream) throws IOException
      Create a ReplayInputStream from the given source stream. Requires reading the entire stream (and possibly overflowing to a temporary file). Primary reason for doing so would be to have a repositionable version of the original stream's contents. If created via this constructor, use the destroy() method to ensure prompt deletion of any associated tmp file when done.
      Parameters:
      fillStream -
      Throws:
      IOException
  • Method Details

    • setupDiskStream

      protected void setupDiskStream(File backingFile) throws IOException
      Throws:
      IOException
    • destroy

      public void destroy()
      Close & destroy any internally-generated temporary files.
    • setToResponseBodyStart

      public long setToResponseBodyStart() throws IOException
      Throws:
      IOException
    • read

      public int read() throws IOException
      Specified by:
      read in class InputStream
      Throws:
      IOException
    • read

      public int read(byte[] b, int off, int len) throws IOException
      Overrides:
      read in class InputStream
      Throws:
      IOException
    • readFullyTo

      public void readFullyTo(OutputStream os) throws IOException
      Throws:
      IOException
    • readFullyTo

      public static void readFullyTo(InputStream in, OutputStream os) throws IOException
      Throws:
      IOException
    • readHeaderTo

      public void readHeaderTo(OutputStream os) throws IOException
      Throws:
      IOException
    • readContentTo

      public void readContentTo(OutputStream os) throws IOException
      Throws:
      IOException
    • readContentTo

      public void readContentTo(OutputStream os, long maxSize) throws IOException
      Convenience method to copy content out to target stream.
      Parameters:
      os - stream to write content to
      maxSize - maximum count of bytes to copy
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InputStream
      Throws:
      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 IOException
      Reposition the stream.
      Parameters:
      p - the new position for this stream
      Throws:
      IOException - if an IO error occurs
    • position

      public long position() throws IOException
      Description copied from interface: RepositionableStream
      Returns the current stream position.
      Returns:
      the current stream position.
      Throws:
      IOException
    • getBuffer

      protected byte[] getBuffer()