Class TapeInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    class TapeInputStream
    extends java.io.FilterInputStream
    Filter stream that mimics a physical tape drive capable of compressing the data stream.
    • Constructor Summary

      Constructors 
      Constructor Description
      TapeInputStream​(java.io.InputStream in)
      Constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()  
      void close()
      Close the input stream.
      long getBytesRead()
      Get number of bytes read.
      byte[] peek()
      Peek at the next record from the input stream and return the data.
      int read()  
      int read​(byte[] b, int off, int len)
      private void readBlock​(boolean decompress)
      Read next block.
      private void readFully​(byte[] b, int off, int len)
      Read buffer
      byte[] readRecord()
      Read a record from the input stream and return the data.
      void resetBlockSize​(int recsPerBlock, boolean isCompressed)
      Set the DumpArchive Buffer's block size.
      long skip​(long len)
      Skip bytes.
      • Methods inherited from class java.io.FilterInputStream

        mark, markSupported, read, reset
      • Methods inherited from class java.io.InputStream

        nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • blockBuffer

        private byte[] blockBuffer
      • currBlkIdx

        private int currBlkIdx
      • blockSize

        private int blockSize
      • readOffset

        private int readOffset
      • isCompressed

        private boolean isCompressed
      • bytesRead

        private long bytesRead
    • Constructor Detail

      • TapeInputStream

        public TapeInputStream​(java.io.InputStream in)
        Constructor
    • Method Detail

      • resetBlockSize

        public void resetBlockSize​(int recsPerBlock,
                                   boolean isCompressed)
                            throws java.io.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:
        java.io.IOException - more than one block has been read
        java.io.IOException - there was an error reading additional blocks.
        java.io.IOException - recsPerBlock is smaller than 1
      • available

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

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

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException

        reads the full given length unless EOF is reached.

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

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

        skips the full given length unless EOF is reached.

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

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

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

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

        private void readBlock​(boolean decompress)
                        throws java.io.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:
        java.io.IOException
      • readFully

        private void readFully​(byte[] b,
                               int off,
                               int len)
                        throws java.io.IOException
        Read buffer
        Throws:
        java.io.IOException
      • getBytesRead

        public long getBytesRead()
        Get number of bytes read.