tar archives consist of a sequence of records of 512 bytes each that are grouped into blocks. Prior to Apache Commons Compress 1.14 it has been possible to configure a record size different from 512 bytes and arbitrary block sizes. Starting with Compress 1.15 512 is the only valid option for the record size and the block size must be a multiple of 512. Also the default block size changed from 10240 bytes prior to Compress 1.15 to 512 bytes with Compress 1.15.
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private static final ZipEncoding | |
| public static final int | BIGNUMBER_ERROR
Fail if a big number (e.g. size > 8GiB) is required in the archive. |
| public static final int | BIGNUMBER_POSIX
POSIX/PAX extensions are used to store big numbers in the archive. |
| public static final int | BIGNUMBER_STAR
star/GNU tar/BSD tar extensions are used to store big number in the archive. |
| private int | |
| private static final int | |
| pack-priv final String | charsetName
The provided encoding (for unit tests). |
| private boolean | |
| private final CountingOutputStream | |
| private long | |
| private String | |
| private long | |
| private boolean | finished
indicates if this archive is finished |
| private boolean | haveUnclosedEntry
Indicates if putArchiveEntry has been called without closeArchiveEntry |
| public static final int | LONGFILE_ERROR
Fail if a long file name is required in the archive. |
| public static final int | LONGFILE_GNU
GNU tar extensions are used to store long file names in the archive. |
| public static final int | LONGFILE_POSIX
POSIX/PAX extensions are used to store long file names in the archive. |
| public static final int | LONGFILE_TRUNCATE
Long paths will be truncated in the archive. |
| private int | |
| private final FixedLengthBlockOutputStream | |
| private static final int | |
| private final byte[] | |
| private final int | |
| private long | |
| private final ZipEncoding |
| Access | Constructor and Description |
|---|---|
| public | |
| public | TarArchiveOutputStream(final OutputStream
the output stream to use os, final int the block size to use. Must be a multiple of 512 bytes. blockSize)Constructs a new instance. |
| public | TarArchiveOutputStream(final OutputStream
the output stream to use os, final int the block size to use blockSize, final int the record size to use. Must be 512 bytes. recordSize)
Deprecated
recordSize must always be 512 bytes. An IllegalArgumentException will be thrown if any other value is used
Constructs a new instance.
|
| public | TarArchiveOutputStream(final OutputStream
the output stream to use os, final int the block size to use . Must be a multiple of 512 bytes. blockSize, final int the record size to use. Must be 512 bytes. recordSize, final String name of the encoding to use for file names encoding)
Deprecated
recordSize must always be 512 bytes. An IllegalArgumentException will be thrown if any other value is used.
Constructs a new instance.
|
| public | TarArchiveOutputStream(final OutputStream
the output stream to use os, final int the block size to use. Must be a multiple of 512 bytes. blockSize, final String name of the encoding to use for file names encoding)Constructs a new instance. |
| public | TarArchiveOutputStream(final OutputStream
the output stream to use os, final String name of the encoding to use for file names encoding)Constructs a new instance. |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| private void | |
| private void | addInstantPaxHeader(final Map<String, String> paxHeaders, final String header, final long seconds, final int nanos)
|
| private void | addPaxHeaderForBigNumber(final Map<String, String> paxHeaders, final String header, final long value, final long maxValue)
|
| private void | |
| public void | close()
Overrides java. Implements java. |
| public void | closeArchiveEntry()
Implements abstract org. |
| public TarArchiveEntry | createArchiveEntry(final File
the file to create the entry from inputFile, final String name to use for the entry entryName)Implements abstract org. |
| public TarArchiveEntry | createArchiveEntry(final Path
the file to create the entry from inputPath, final String name to use for the entry entryName, final LinkOption... options indicating how symbolic links are handled. options)Overrides org. |
| private byte[] | |
| private void | |
| private void | failForBigNumber(final String field, final long value, final long maxValue, final String additionalMsg)
|
| private void | |
| private void | |
| public void | finish()
Implements abstract org. |
| public void | flush()
Overrides java. Implements java. |
| public long | getBytesWritten()
Overrides org. |
| public int | getCount()
Overrides org.
Deprecated
Gets the current number of bytes written to this stream.
|
| public int | Returns: The TarBuffer record size.
Deprecated
Gets the record size being used by this stream's TarBuffer.
|
| private boolean | Returns: whether a pax header has been written.entry the name belongs to entry, final String the name to write name, final Map<String, String> current map of pax headers paxHeaders, final String name of the pax header to write paxHeaderName, final byte type of the GNU entry to write linkType, final String the name of the field fieldName)Handles long file or link names according to the longFileMode setting. |
| private void | |
| public void | putArchiveEntry(final TarArchiveEntry
The TarEntry to be written to the archive. archiveEntry)Implements abstract org. |
| public void | setAddPaxHeadersForNonAsciiNames(final boolean
whether to add a PAX extension header for non-ASCII file names. b)Sets whether to add a PAX extension header for non-ASCII file names. |
| public void | |
| public void | |
| private boolean | Returns: true if the character could lead to problems when used inside a TarArchiveEntry name for a PAX header.Tests whether the character could lead to problems when used inside a TarArchiveEntry name for a PAX header. |
| private String | |
| private void | |
| public void | write(final byte[]
The buffer to write to the archive. wBuf, final int The offset in the buffer from which to get bytes. wOffset, final int The number of bytes to write. numToWrite)Overrides java. |
| private void | |
| pack-priv void | writePaxHeaders(final TarArchiveEntry entry, final String entryName, final Map<String, String> headers)
Writes a PAX extended header with the given map as contents. |
| private void | writeRecord(final byte[]
The record data to write to the archive. record)Writes an archive record to the archive. |
| addPaxHeadersForNonAsciiNames | back to summary |
|---|---|
| private boolean addPaxHeadersForNonAsciiNames | |
| ASCII | back to summary |
|---|---|
| private static final ZipEncoding ASCII | |
| BIGNUMBER_ERROR | back to summary |
|---|---|
| public static final int BIGNUMBER_ERROR Fail if a big number (e.g. size > 8GiB) is required in the archive. | |
| BIGNUMBER_POSIX | back to summary |
|---|---|
| public static final int BIGNUMBER_POSIX POSIX/PAX extensions are used to store big numbers in the archive. | |
| BIGNUMBER_STAR | back to summary |
|---|---|
| public static final int BIGNUMBER_STAR star/GNU tar/BSD tar extensions are used to store big number in the archive. | |
| bigNumberMode | back to summary |
|---|---|
| private int bigNumberMode | |
| BLOCK_SIZE_UNSPECIFIED | back to summary |
|---|---|
| private static final int BLOCK_SIZE_UNSPECIFIED | |
| charsetName | back to summary |
|---|---|
| pack-priv final String charsetName The provided encoding (for unit tests). | |
| closed | back to summary |
|---|---|
| private boolean closed | |
| countingOut | back to summary |
|---|---|
| private final CountingOutputStream countingOut | |
| currBytes | back to summary |
|---|---|
| private long currBytes | |
| currName | back to summary |
|---|---|
| private String currName | |
| currSize | back to summary |
|---|---|
| private long currSize | |
| finished | back to summary |
|---|---|
| private boolean finished indicates if this archive is finished | |
| haveUnclosedEntry | back to summary |
|---|---|
| private boolean haveUnclosedEntry Indicates if putArchiveEntry has been called without closeArchiveEntry | |
| LONGFILE_ERROR | back to summary |
|---|---|
| public static final int LONGFILE_ERROR Fail if a long file name is required in the archive. | |
| LONGFILE_GNU | back to summary |
|---|---|
| public static final int LONGFILE_GNU GNU tar extensions are used to store long file names in the archive. | |
| LONGFILE_POSIX | back to summary |
|---|---|
| public static final int LONGFILE_POSIX POSIX/PAX extensions are used to store long file names in the archive. | |
| LONGFILE_TRUNCATE | back to summary |
|---|---|
| public static final int LONGFILE_TRUNCATE Long paths will be truncated in the archive. | |
| longFileMode | back to summary |
|---|---|
| private int longFileMode | |
| out | back to summary |
|---|---|
| private final FixedLengthBlockOutputStream out | |
| RECORD_SIZE | back to summary |
|---|---|
| private static final int RECORD_SIZE | |
| recordBuf | back to summary |
|---|---|
| private final byte[] recordBuf | |
| recordsPerBlock | back to summary |
|---|---|
| private final int recordsPerBlock | |
| recordsWritten | back to summary |
|---|---|
| private long recordsWritten | |
| zipEncoding | back to summary |
|---|---|
| private final ZipEncoding zipEncoding | |
| TarArchiveOutputStream | back to summary |
|---|---|
| public TarArchiveOutputStream(final OutputStream os) Constructs a new instance. Uses a block size of 512 bytes.
| |
| TarArchiveOutputStream | back to summary |
|---|---|
| public TarArchiveOutputStream(final OutputStream os, final int blockSize) Constructs a new instance.
| |
| TarArchiveOutputStream | back to summary |
|---|---|
| public TarArchiveOutputStream(final OutputStream os, final int blockSize, final int recordSize)
Deprecated recordSize must always be 512 bytes. An IllegalArgumentException will be thrown if any other value is used Constructs a new instance.
| |
| TarArchiveOutputStream | back to summary |
|---|---|
| public TarArchiveOutputStream(final OutputStream os, final int blockSize, final int recordSize, final String encoding)
Deprecated recordSize must always be 512 bytes. An IllegalArgumentException will be thrown if any other value is used. Constructs a new instance.
| |
| TarArchiveOutputStream | back to summary |
|---|---|
| public TarArchiveOutputStream(final OutputStream os, final int blockSize, final String encoding) Constructs a new instance.
| |
| TarArchiveOutputStream | back to summary |
|---|---|
| public TarArchiveOutputStream(final OutputStream os, final String encoding) Constructs a new instance. Uses a block size of 512 bytes.
| |
| addFileTimePaxHeader | back to summary |
|---|---|
| private void addFileTimePaxHeader(final Map<String, String> paxHeaders, final String header, final FileTime value) | |
| addFileTimePaxHeaderForBigNumber | back to summary |
|---|---|
| private void addFileTimePaxHeaderForBigNumber(final Map<String, String> paxHeaders, final String header, final FileTime value, final long maxValue) | |
| addInstantPaxHeader | back to summary |
|---|---|
| private void addInstantPaxHeader(final Map<String, String> paxHeaders, final String header, final long seconds, final int nanos) | |
| addPaxHeaderForBigNumber | back to summary |
|---|---|
| private void addPaxHeaderForBigNumber(final Map<String, String> paxHeaders, final String header, final long value, final long maxValue) | |
| addPaxHeadersForBigNumbers | back to summary |
|---|---|
| private void addPaxHeadersForBigNumbers(final Map<String, String> paxHeaders, final TarArchiveEntry entry) | |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides java. Implements java. Closes the underlying OutputStream.
| |
| closeArchiveEntry | back to summary |
|---|---|
| public void closeArchiveEntry() throws IOException Implements abstract org. Closes an entry. This method MUST be called for all file entries that contain data. The reason is that we must buffer data written to the stream in order to satisfy the buffer's record based writes. Thus, there may be data fragments still being assembled that must be written to the output stream before this entry is closed and the next entry written.
| |
| createArchiveEntry | back to summary |
|---|---|
| public TarArchiveEntry createArchiveEntry(final File inputFile, final String entryName) throws IOException Implements abstract org. Doc from org. Creates an archive entry using the inputFile and entryName provided.
| |
| createArchiveEntry | back to summary |
|---|---|
| public TarArchiveEntry createArchiveEntry(final Path inputPath, final String entryName, final LinkOption... options) throws IOException Overrides org. Doc from org. Creates an archive entry using the inputPath and entryName provided. The default implementation calls simply delegates as: return createArchiveEntry(inputFile.toFile(), entryName); Subclasses should override this method.
| |
| encodeExtendedPaxHeadersContents | back to summary |
|---|---|
| private byte[] encodeExtendedPaxHeadersContents(final Map<String, String> headers) | |
| failForBigNumber | back to summary |
|---|---|
| private void failForBigNumber(final String field, final long value, final long maxValue) | |
| failForBigNumber | back to summary |
|---|---|
| private void failForBigNumber(final String field, final long value, final long maxValue, final String additionalMsg) | |
| failForBigNumbers | back to summary |
|---|---|
| private void failForBigNumbers(final TarArchiveEntry entry) | |
| failForBigNumberWithPosixMessage | back to summary |
|---|---|
| private void failForBigNumberWithPosixMessage(final String field, final long value, final long maxValue) | |
| finish | back to summary |
|---|---|
| public void finish() throws IOException Implements abstract org. Finishes the TAR archive without closing the underlying OutputStream. An archive consists of a series of file entries terminated by an end-of-archive entry, which consists of two 512 blocks of zero bytes. POSIX.1 requires two EOF records, like some other implementations.
| |
| flush | back to summary |
|---|---|
| public void flush() throws IOException Overrides java. Implements java. Doc from java. Flushes this output stream and forces any buffered output bytes
to be written out. The general contract of If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.
| |
| getBytesWritten | back to summary |
|---|---|
| public long getBytesWritten() Overrides org. Doc from org. Gets the current number of bytes written to this stream.
| |
| getCount | back to summary |
|---|---|
| public int getCount() Overrides org. Doc from org. Deprecated
Gets the current number of bytes written to this stream.
| |
| getRecordSize | back to summary |
|---|---|
| public int getRecordSize()
Deprecated
Gets the record size being used by this stream's TarBuffer.
| |
| handleLongName | back to summary |
|---|---|
| private boolean handleLongName(final TarArchiveEntry entry, final String name, final Map<String, String> paxHeaders, final String paxHeaderName, final byte linkType, final String fieldName) throws IOException Handles long file or link names according to the longFileMode setting. I.e. if the given name is too long to be written to a plain tar header then
| |
| padAsNeeded | back to summary |
|---|---|
| private void padAsNeeded() throws IOException | |
| putArchiveEntry | back to summary |
|---|---|
| public void putArchiveEntry(final TarArchiveEntry archiveEntry) throws IOException Implements abstract org. Puts an entry on the output stream. This writes the entry's header record and positions the output stream for writing the contents of the entry. Once this method is called, the stream is ready for calls to write() to write the entry's contents. Once the contents are written, closeArchiveEntry() MUST be called to ensure that all buffered data is completely written to the output stream.
| |
| setAddPaxHeadersForNonAsciiNames | back to summary |
|---|---|
| public void setAddPaxHeadersForNonAsciiNames(final boolean b) Sets whether to add a PAX extension header for non-ASCII file names.
| |
| setBigNumberMode | back to summary |
|---|---|
| public void setBigNumberMode(final int bigNumberMode) Sets the big number mode. This can be BIGNUMBER_ERROR(0), BIGNUMBER_STAR(1) or BIGNUMBER_POSIX(2). This specifies the treatment of big files (sizes > TarConstants.MAXSIZE) and other numeric values too big to fit into a traditional tar header. Default is BIGNUMBER_ERROR.
| |
| setLongFileMode | back to summary |
|---|---|
| public void setLongFileMode(final int longFileMode) Sets the long file mode. This can be LONGFILE_ERROR(0), LONGFILE_TRUNCATE(1), LONGFILE_GNU(2) or LONGFILE_POSIX(3). This specifies the treatment of long file names (names >= TarConstants.NAMELEN). Default is LONGFILE_ERROR.
| |
| shouldBeReplaced | back to summary |
|---|---|
| private boolean shouldBeReplaced(final char c) Tests whether the character could lead to problems when used inside a TarArchiveEntry name for a PAX header.
| |
| stripTo7Bits | back to summary |
|---|---|
| private String stripTo7Bits(final String name) | |
| transferModTime | back to summary |
|---|---|
| private void transferModTime(final TarArchiveEntry from, final TarArchiveEntry to) | |
| write | back to summary |
|---|---|
| public void write(final byte[] wBuf, final int wOffset, final int numToWrite) throws IOException Overrides java. Writes bytes to the current tar archive entry. This method is aware of the current entry and will throw an exception if you attempt to write bytes past the length specified for the current entry.
| |
| writeEOFRecord | back to summary |
|---|---|
| private void writeEOFRecord() throws IOException Writes an EOF (end of archive) record to the tar archive. An EOF record consists of a record of all zeros. | |
| writePaxHeaders | back to summary |
|---|---|
| pack-priv void writePaxHeaders(final TarArchiveEntry entry, final String entryName, final Map<String, String> headers) throws IOException Writes a PAX extended header with the given map as contents.
| |
| writeRecord | back to summary |
|---|---|
| private void writeRecord(final byte[] record) throws IOException Writes an archive record to the archive.
| |