This class is ignorant about Tar header fields, attributes and such. It is concerned with reading and writing blocks of data in conformance with Tar formatting, in a way convenient to those who want to get the header and data blocks.
Asymmetric to the Tar file writing side, the bufferBlocks setting here is used only for to adjust read buffer size (for file data reads), so the user can compromise between available memory and performance. Small buffer sizes will always work, but will incur more reads; on the other hand, buffer sizes larger than the largest component file is just a waste of memory.
We assume the responsibility to manage the setting because the decision should be based on available RAM more than anything else (therefore, we can't set a good value automatically).
As alluded to above, headers are read in separate reads, regardless of the readBufferBlocks setting. readBufferBlocks is used for reading file data.
I have purposefully not implemented skip(), because, though I haven't tested it, I believe our readBlock() and readBlocks() methods are at least as fast, since we use the larges read buffer within limits the user has set.
| Modifier and Type | Field and Description |
|---|---|
| protected long | |
| protected int | |
| protected byte[] | |
| protected int | |
| private InputStream |
| Access | Constructor and Description |
|---|---|
| public | TarFileInputStream(File
File sourceFile)Convenience wrapper to use default readBufferBlocks and compressionType. |
| public | TarFileInputStream(File
File sourceFile, int int compressionType)Convenience wrapper to use default readBufferBlocks. |
| public | TarFileInputStream(File
File sourceFile, int int compressionType, int int readBufferBlocks)This class does no validation or enforcement of file naming conventions. |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public int | |
| public void | readBlock()
readBlock() and readNextHeaderBlock are the methods that USERS of this class should use to read header blocks from the tar file. |
| public void | readBlocks(int
How many 512 blocks to read. blocks)readBlocks(int) is the method that USERS of this class should use to read file data from the tar file. |
| protected void | readCompressedBlocks(int blocks)
Work-around for the problem that compressed InputReaders don't fill the read buffer before returning. |
| public boolean | Returns: True if a header block was read and place at beginning of the readBuffer array. False if EOF was encountered without finding any blocks with first byte != 0. If false is returned, we have automatically closed the this TarFileInputStream too.readBlock() and readNextHeaderBlock are the methods that USERS of this class should use to read header blocks from the tar file. |
| bytesRead | back to summary |
|---|---|
| protected long bytesRead | |
| compressionType | back to summary |
|---|---|
| protected int compressionType | |
| readBuffer | back to summary |
|---|---|
| protected byte[] readBuffer | |
| readBufferBlocks | back to summary |
|---|---|
| protected int readBufferBlocks | |
| readStream | back to summary |
|---|---|
| private InputStream readStream | |
| TarFileInputStream | back to summary |
|---|---|
| public TarFileInputStream(File sourceFile) throws IOException Convenience wrapper to use default readBufferBlocks and compressionType.
| |
| TarFileInputStream | back to summary |
|---|---|
| public TarFileInputStream(File sourceFile, int compressionType) throws IOException Convenience wrapper to use default readBufferBlocks.
| |
| TarFileInputStream | back to summary |
|---|---|
| public TarFileInputStream(File sourceFile, int compressionType, int readBufferBlocks) throws IOException This class does no validation or enforcement of file naming conventions. If desired, the caller should enforce extensions like "tar" and "tar.gz" (and that they match the specified compression type). This object will automatically release its I/O resources when you get false back from a readNextHeaderBlock() call. If you abort before then, you must call the close() method like for a normal InputStream.
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Implements java.io.Closeable.
| |
| getReadBufferBlocks | back to summary |
|---|---|
| public int getReadBufferBlocks() | |
| readBlock | back to summary |
|---|---|
| public void readBlock() throws IOException, TarMalformatException readBlock() and readNextHeaderBlock are the methods that USERS of this class should use to read header blocks from the tar file. readBlock() should be used when you know that the current block should contain what you want. E.g. you know that the very first block of a tar file should contain a Tar Entry header block.
| |
| readBlocks | back to summary |
|---|---|
| public void readBlocks(int blocks) throws IOException, TarMalformatException readBlocks(int) is the method that USERS of this class should use to read file data from the tar file. This method reads from the tar file and writes to the readBuffer array. This class and subclasses should read from the underlying readStream ONLY WITH THIS METHOD. That way we can be confident that bytesRead will always be accurate. This method is different from a typical Java byte array read command in that when reading tar files
| |
| readCompressedBlocks | back to summary |
|---|---|
| protected void readCompressedBlocks(int blocks) throws IOException Work-around for the problem that compressed InputReaders don't fill the read buffer before returning. Has visibility 'protected' so that subclasses may override with different algorithms, or use different algorithms for different compression stream. | |
| readNextHeaderBlock | back to summary |
|---|---|
| public boolean readNextHeaderBlock() throws IOException, TarMalformatException readBlock() and readNextHeaderBlock are the methods that USERS of this class should use to read header blocks from the tar file. readNextHeaderBlock continues working through the Tar File from the current point until it finds a block with a non-0 first byte.
| |