Class TapeInputStream

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.apache.commons.compress.archivers.dump.TapeInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

class TapeInputStream extends FilterInputStream
Filter stream that mimics a physical tape drive capable of compressing the data stream.
  • Field Details

    • blockBuffer

      private byte[] blockBuffer
    • currBlkIdx

      private int currBlkIdx
    • blockSize

      private int blockSize
    • RECORD_SIZE

      private static final int RECORD_SIZE
      See Also:
    • readOffset

      private int readOffset
    • isCompressed

      private boolean isCompressed
    • bytesRead

      private long bytesRead
  • Constructor Details

    • TapeInputStream

      public TapeInputStream(InputStream in)
      Constructor
  • Method Details

    • resetBlockSize

      public void resetBlockSize(int recsPerBlock, boolean isCompressed) throws IOException
      Set the DumpArchive Buffer's block size. We need to sync the block size with the dump archive's actual block size since compression is handled at the block level.
      Parameters:
      recsPerBlock - records per block
      isCompressed - true if the archive is compressed
      Throws:
      IOException - more than one block has been read
      IOException - there was an error reading additional blocks.
      IOException - recsPerBlock is smaller than 1
    • available

      public int available() throws IOException
      Overrides:
      available in class FilterInputStream
      Throws:
      IOException
      See Also:
    • read

      public int read() throws IOException
      Overrides:
      read in class FilterInputStream
      Throws:
      IOException
      See Also:
    • read

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

      reads the full given length unless EOF is reached.

      Overrides:
      read in class FilterInputStream
      Parameters:
      len - length to read, must be a multiple of the stream's record size
      Throws:
      IOException
    • skip

      public long skip(long len) throws IOException
      Skip bytes. Same as read but without the arraycopy.

      skips the full given length unless EOF is reached.

      Overrides:
      skip in class FilterInputStream
      Parameters:
      len - length to read, must be a multiple of the stream's record size
      Throws:
      IOException
    • close

      public void close() throws IOException
      Close the input stream.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class FilterInputStream
      Throws:
      IOException - on error
    • peek

      public byte[] peek() throws IOException
      Peek at the next record from the input stream and return the data.
      Returns:
      The record data.
      Throws:
      IOException - on error
    • readRecord

      public byte[] readRecord() throws IOException
      Read a record from the input stream and return the data.
      Returns:
      The record data.
      Throws:
      IOException - on error
    • readBlock

      private void readBlock(boolean decompress) throws IOException
      Read next block. All decompression is handled here.
      Parameters:
      decompress - if false the buffer will not be decompressed. This is an optimization for longer seeks.
      Throws:
      IOException
    • readFully

      private void readFully(byte[] b, int off, int len) throws IOException
      Read buffer
      Throws:
      IOException
    • readRange

      private byte[] readRange(int len) throws IOException
      Throws:
      IOException
    • getBytesRead

      public long getBytesRead()
      Get number of bytes read.