Top Description Fields Constructors Methods
org.apache.commons.compress.archivers.dump

pack-priv final Class TapeInputStream

extends FilterInputStream
Class Inheritance
Imports
java.io.FilterInputStream, .IOException, .InputStream, java.util.Arrays, java.util.zip.DataFormatException, .Inflater, org.apache.commons.compress.utils.ExactMath, .IOUtils

Filter stream that mimics a physical tape drive capable of compressing the data stream.

Field Summary

Modifier and TypeField and Description
private byte[]
private int
private long
private int
private boolean
private int
private static final int
Inherited from java.io.FilterInputStream:
in

Constructor Summary

AccessConstructor and Description
pack-priv
TapeInputStream(final InputStream
the underlying input stream.
in
)

Constructs a new instance.

Method Summary

Modifier and TypeMethod and Description
public int
available()

Overrides java.io.FilterInputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream.
public void
close()

Overrides java.io.FilterInputStream.close.

Implements java.io.Closeable.close.

Close the input stream.
public long

Returns:

number of bytes read.
getBytesRead
()

Gets number of bytes read.

public byte[]

Returns:

The record data.
peek
()

Peek at the next record from the input stream and return the data.

public int
read()

Overrides java.io.FilterInputStream.read.

Reads the next byte of data from the input stream.
public int
read(final byte[]
the buffer into which the data is read.
b
,
int
the start offset in array b at which the data is written.
off
,
final int
length to read, must be a multiple of the stream's record size
len
)

Overrides java.io.FilterInputStream.read.

Reads up to len bytes of data from this input stream into an array of bytes.
private void
readBlock(final boolean
if false the buffer will not be decompressed. This is an optimization for longer seeks.
decompress
)

Read next block.

private void
readFully(final byte[] b, final int off, final int len)

Read buffer

private byte[]
readRange(final int len)

public byte[]

Returns:

The record data.
readRecord
()

Read a record from the input stream and return the data.

public void
resetBlockSize(final int
records per block
recsPerBlock
,
final boolean
true if the archive is compressed
isCompressed
)

Sets the DumpArchive Buffer's block size.

public long
skip(final long
length to read, must be a multiple of the stream's record size
len
)

Overrides java.io.FilterInputStream.skip.

Skip bytes.
Inherited from java.io.FilterInputStream:
markmarkSupportedreadreset

Field Detail

blockBufferback to summary
private byte[] blockBuffer
blockSizeback to summary
private int blockSize
bytesReadback to summary
private long bytesRead
currBlkIdxback to summary
private int currBlkIdx
isCompressedback to summary
private boolean isCompressed
readOffsetback to summary
private int readOffset
RECORD_SIZEback to summary
private static final int RECORD_SIZE

Constructor Detail

TapeInputStreamback to summary
pack-priv TapeInputStream(final InputStream in)

Constructs a new instance.

Parameters
in:InputStream

the underlying input stream.

Method Detail

availableback to summary
public int available() throws IOException

Overrides java.io.FilterInputStream.available.

Doc from java.io.FilterInputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. The next caller might be the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

Returns:int

an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
See Also
java.io.InputStream#available
closeback to summary
public void close() throws IOException

Overrides java.io.FilterInputStream.close.

Implements java.io.Closeable.close.

Close the input stream.

Annotations
@Override
Exceptions
IOException:
on error
getBytesReadback to summary
public long getBytesRead()

Gets number of bytes read.

Returns:long

number of bytes read.

peekback to summary
public byte[] peek() throws IOException

Peek at the next record from the input stream and return the data.

Returns:byte[]

The record data.

Exceptions
IOException:
on error
readback to summary
public int read() throws IOException

Overrides java.io.FilterInputStream.read.

Doc from java.io.FilterInputStream.read.

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Returns:int

the next byte of data, or -1 if the end of the stream is reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
See Also
java.io.InputStream#read()
readback to summary
public int read(final byte[] b, int off, final int len) throws IOException

Overrides java.io.FilterInputStream.read.

Doc from java.io.FilterInputStream.read.

Reads up to len bytes of data from this input stream into an array of bytes. If len is not zero, the method blocks until some input is available; otherwise, no bytes are read and 0 is returned.

reads the full given length unless EOF is reached.

Parameters
b:byte[]

the buffer into which the data is read.

off:int

the start offset in array b at which the data is written.

len:int

length to read, must be a multiple of the stream's record size

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readBlockback to summary
private void readBlock(final boolean decompress) throws IOException

Read next block. All decompression is handled here.

Parameters
decompress:boolean

if false the buffer will not be decompressed. This is an optimization for longer seeks.

readFullyback to summary
private void readFully(final byte[] b, final int off, final int len) throws IOException

Read buffer

readRangeback to summary
private byte[] readRange(final int len) throws IOException
readRecordback to summary
public byte[] readRecord() throws IOException

Read a record from the input stream and return the data.

Returns:byte[]

The record data.

Exceptions
IOException:
on error
resetBlockSizeback to summary
public void resetBlockSize(final int recsPerBlock, final boolean isCompressed) throws IOException

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:int

records per block

isCompressed:boolean

true if the archive is compressed

Exceptions
IOException:
  • more than one block has been read
  • there was an error reading additional blocks.
  • recsPerBlock is smaller than 1
skipback to summary
public long skip(final long len) throws IOException

Overrides java.io.FilterInputStream.skip.

Skip bytes. Same as read but without the arraycopy.

skips the full given length unless EOF is reached.

Parameters
len:long

length to read, must be a multiple of the stream's record size

Returns:long

Doc from java.io.FilterInputStream.skip.

the actual number of bytes skipped.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.FilterInputStream.skip.

if in.skip(n) throws an IOException.