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
final 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)Constructs a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidclose()Close the input stream.longgetBytesRead()Gets 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)Sets the DumpArchive Buffer's block size.longskip(long len)Skip bytes.
-
-
-
Field Detail
-
RECORD_SIZE
private static final int RECORD_SIZE
- See Also:
- Constant Field Values
-
blockBuffer
private byte[] blockBuffer
-
currBlkIdx
private int currBlkIdx
-
blockSize
private int blockSize
-
readOffset
private int readOffset
-
isCompressed
private boolean isCompressed
-
bytesRead
private long bytesRead
-
-
Method Detail
-
available
public int available() throws java.io.IOException- Overrides:
availablein classjava.io.FilterInputStream- Throws:
java.io.IOException- See Also:
InputStream.available()
-
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
-
getBytesRead
public long getBytesRead()
Gets number of bytes read.- Returns:
- number of bytes read.
-
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
-
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
-
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
-
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
-
resetBlockSize
public void resetBlockSize(int recsPerBlock, boolean isCompressed) throws java.io.IOExceptionSets 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
-
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
-
-