Class TapeInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- org.apache.commons.compress.archivers.dump.TapeInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
class TapeInputStream extends java.io.FilterInputStreamFilter stream that mimics a physical tape drive capable of compressing the data stream.
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]blockBufferprivate intblockSizeprivate longbytesReadprivate intcurrBlkIdxprivate booleanisCompressedprivate intreadOffsetprivate static intRECORD_SIZE
-
Constructor Summary
Constructors Constructor Description TapeInputStream(java.io.InputStream in)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidclose()Close the input stream.longgetBytesRead()Get number of bytes read.byte[]peek()Peek at the next record from the input stream and return the data.intread()intread(byte[] b, int off, int len)private voidreadBlock(boolean decompress)Read next block.private voidreadFully(byte[] b, int off, int len)Read bufferprivate byte[]readRange(int len)byte[]readRecord()Read a record from the input stream and return the data.voidresetBlockSize(int recsPerBlock, boolean isCompressed)Set the DumpArchive Buffer's block size.longskip(long len)Skip bytes.
-
-
-
Field Detail
-
blockBuffer
private byte[] blockBuffer
-
currBlkIdx
private int currBlkIdx
-
blockSize
private int blockSize
-
RECORD_SIZE
private static final int RECORD_SIZE
- See Also:
- Constant Field Values
-
readOffset
private int readOffset
-
isCompressed
private boolean isCompressed
-
bytesRead
private long bytesRead
-
-
Method Detail
-
resetBlockSize
public void resetBlockSize(int recsPerBlock, boolean isCompressed) throws java.io.IOExceptionSet 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 blockisCompressed- true if the archive is compressed- Throws:
java.io.IOException- more than one block has been readjava.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:
availablein classjava.io.FilterInputStream- Throws:
java.io.IOException- See Also:
InputStream.available()
-
read
public int read() throws java.io.IOException- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException- See Also:
InputStream.read()
-
read
public int read(byte[] b, int off, int len) throws java.io.IOExceptionreads the full given length unless EOF is reached.
- Overrides:
readin classjava.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.IOExceptionSkip bytes. Same as read but without the arraycopy.skips the full given length unless EOF is reached.
- Overrides:
skipin classjava.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.IOExceptionClose the input stream.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.FilterInputStream- Throws:
java.io.IOException- on error
-
peek
public byte[] peek() throws java.io.IOExceptionPeek 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.IOExceptionRead 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.IOExceptionRead 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.IOExceptionRead buffer- Throws:
java.io.IOException
-
readRange
private byte[] readRange(int len) throws java.io.IOException- Throws:
java.io.IOException
-
getBytesRead
public long getBytesRead()
Get number of bytes read.
-
-