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 write the header and data blocks.
Users write file data by means of populating the provided, public byte array, then calling the single write(int) method to write a portion of that array. This design purposefully goes with efficiency, simplicity, and performance over Java convention, which would not use public fields.
At this time, we do not support appending. That would greatly decrease the generality and simplicity of the our design, since appending is trivial without compression and very difficult with compression.
Users must finish tar file creation by using the finish() method. Just like a normal OutputStream, if processing is aborted for any reason, the close() method must be used to free up system resources.
Security Note
Due to pitiful lack of support for file security in Java before version 1.6, this class will only explicitly set permissions if it is compiled for Java 1.6. If it was not, and if your tar entries contain private data in files with 0400 or similar, be aware that that file can be pretty much be extracted by anybody with access to the tar file.
finish, close
| Modifier and Type | Class and Description |
|---|---|
| public static interface |
| Modifier and Type | Field and Description |
|---|---|
| protected int | |
| protected long | |
| public static final boolean | |
| private final File | |
| public byte[] | |
| private final File | |
| private OutputStream | |
| pack-priv static final byte[] |
| Access | Constructor and Description |
|---|---|
| public | TarFileOutputStream(File
File targetFile)Convenience wrapper to use default blocksPerRecord and compressionType. |
| public | TarFileOutputStream(File
File targetFile, int int compressionType)Convenience wrapper to use default blocksPerRecord. |
| public | TarFileOutputStream(File
File targetFile, int int compressionType, int int blocksPerRecord)This class does no validation or enforcement of file naming conventions. |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public int | |
| public void | |
| public void | |
| public void | |
| public long | |
| public void | |
| public void | write(byte[]
byte[] byteArray, int int byteCount)This class and subclasses should write to the underlying writeStream ONLY WITH THIS METHOD. |
| public void | write(int
int byteCount)The normal way to write file data (as opposed to header data or padding) using this class. |
| public void | |
| public void | |
| public void |
| blocksPerRecord | back to summary |
|---|---|
| protected int blocksPerRecord | |
| bytesWritten | back to summary |
|---|---|
| protected long bytesWritten | |
| debug | back to summary |
|---|---|
| public static final boolean debug | |
| targetFile | back to summary |
|---|---|
| private final File targetFile | |
| writeBuffer | back to summary |
|---|---|
| public byte[] writeBuffer | |
| writeFile | back to summary |
|---|---|
| private final File writeFile | |
| writeStream | back to summary |
|---|---|
| private OutputStream writeStream | |
| ZERO_BLOCK | back to summary |
|---|---|
| pack-priv static final byte[] ZERO_BLOCK | |
| TarFileOutputStream | back to summary |
|---|---|
| public TarFileOutputStream(File targetFile) throws IOException Convenience wrapper to use default blocksPerRecord and compressionType.
| |
| TarFileOutputStream | back to summary |
|---|---|
| public TarFileOutputStream(File targetFile, int compressionType) throws IOException Convenience wrapper to use default blocksPerRecord.
| |
| TarFileOutputStream | back to summary |
|---|---|
| public TarFileOutputStream(File targetFile, int compressionType, int blocksPerRecord) 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). It also overwrites files without warning (just like FileOutputStream).
| |
| assertAtBlockBoundary | back to summary |
|---|---|
public void assertAtBlockBoundary()
| |
| bytesLeftInBlock | back to summary |
|---|---|
| public int bytesLeftInBlock() | |
| close | back to summary |
|---|---|
| public void close() throws IOException Implements java.io.Closeable. Important Note This method deletes the work file after closing it!
| |
| finish | back to summary |
|---|---|
| public void finish() throws IOException (Only) when this method returns successfully, the generated file will be a valid tar file. This method always performs a close, so you never need to call the close if your code makes it to this method. (You do need to call close if processing is aborted before calling finish()).
| |
| flush | back to summary |
|---|---|
| public void flush() throws IOException Implements java.io.Flushable.
| |
| getBytesWritten | back to summary |
|---|---|
| public long getBytesWritten() | |
| padCurrentBlock | back to summary |
|---|---|
| public void padCurrentBlock() throws IOException Rounds out the current block to the next block boundary. If we are currently at a block boundary, nothing is done.
| |
| write | back to summary |
|---|---|
| public void write(byte[] byteArray, int byteCount) throws IOException This class and subclasses should write to the underlying writeStream ONLY WITH THIS METHOD. That way we can be confident that bytesWritten will always be accurate.
| |
| write | back to summary |
|---|---|
| public void write(int byteCount) throws IOException The normal way to write file data (as opposed to header data or padding) using this class.
| |
| writeBlock | back to summary |
|---|---|
| public void writeBlock(byte[] block) throws IOException Write a user-specified 512-byte block. For efficiency, write(int) should be used when writing file body content.
| |
| writePadBlock | back to summary |
|---|---|
| public void writePadBlock() throws IOException Writes a single zero'd block.
| |
| writePadBlocks | back to summary |
|---|---|
| public void writePadBlocks(int blockCount) throws IOException Writes the specified quantity of zero'd blocks.
| |
| Modifier and Type | Field and Description |
|---|---|
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int |
| DEFAULT_BLOCKS_PER_RECORD | back to summary |
|---|---|
| public static final int DEFAULT_BLOCKS_PER_RECORD | |
| DEFAULT_COMPRESSION | back to summary |
|---|---|
| public static final int DEFAULT_COMPRESSION | |
| GZIP_COMPRESSION | back to summary |
|---|---|
| public static final int GZIP_COMPRESSION | |
| NO_COMPRESSION | back to summary |
|---|---|
| public static final int NO_COMPRESSION | |