Class TapeInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.apache.commons.compress.archivers.dump.TapeInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
Filter stream that mimics a physical tape drive capable of compressing the data stream.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]
private int
private long
private int
private boolean
private int
private static final int
Fields inherited from class java.io.FilterInputStream
in
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
void
close()
Close the input stream.long
Gets 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 bufferprivate byte[]
readRange
(int len) byte[]
Read a record from the input stream and return the data.void
resetBlockSize
(int recsPerBlock, boolean isCompressed) Sets the DumpArchive Buffer's block size.long
skip
(long len) Skip bytes.Methods inherited from class java.io.FilterInputStream
mark, markSupported, read, reset
-
Field Details
-
RECORD_SIZE
private static final int RECORD_SIZE- See Also:
-
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 Details
-
TapeInputStream
TapeInputStream(InputStream in) Constructs a new instance.- Parameters:
in
- the underlying input stream.
-
-
Method Details
-
available
- Overrides:
available
in classFilterInputStream
- Throws:
IOException
- See Also:
-
close
Close the input stream.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterInputStream
- Throws:
IOException
- on error
-
getBytesRead
public long getBytesRead()Gets number of bytes read.- Returns:
- number of bytes read.
-
peek
Peek at the next record from the input stream and return the data.- Returns:
- The record data.
- Throws:
IOException
- on error
-
read
- Overrides:
read
in classFilterInputStream
- Throws:
IOException
- See Also:
-
read
reads the full given length unless EOF is reached.
- Overrides:
read
in classFilterInputStream
- Parameters:
len
- length to read, must be a multiple of the stream's record size- Throws:
IOException
-
readBlock
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
Read buffer- Throws:
IOException
-
readRange
- Throws:
IOException
-
readRecord
Read a record from the input stream and return the data.- Returns:
- The record data.
- Throws:
IOException
- on error
-
resetBlockSize
Sets 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:
IOException
- more than one block has been readIOException
- there was an error reading additional blocks.IOException
- recsPerBlock is smaller than 1
-
skip
Skip bytes. Same as read but without the arraycopy.skips the full given length unless EOF is reached.
- Overrides:
skip
in classFilterInputStream
- Parameters:
len
- length to read, must be a multiple of the stream's record size- Throws:
IOException
-