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.FilterInputStream
Filter stream that mimics a physical tape drive capable of compressing the data stream.
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]
blockBuffer
private int
blockSize
private long
bytesRead
private int
currBlkIdx
private boolean
isCompressed
private int
readOffset
private static int
RECORD_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 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 bufferbyte[]
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.
-
-
-
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.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 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:
available
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
- See Also:
InputStream.available()
-
read
public int read() throws java.io.IOException
- Overrides:
read
in classjava.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 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.IOException
Skip bytes. Same as read but without the arraycopy.skips the full given length unless EOF is reached.
- Overrides:
skip
in 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.IOException
Close the input stream.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.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.
-
-