public class TarArchiveOutputStream extends ArchiveOutputStream
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 | 
|---|---|
| static int | BIGNUMBER_ERRORFail if a big number (e.g. | 
| static int | BIGNUMBER_POSIXPOSIX/PAX extensions are used to store big numbers in the archive. | 
| static int | BIGNUMBER_STARstar/GNU tar/BSD tar extensions are used to store big number in the archive. | 
| static int | LONGFILE_ERRORFail if a long file name is required in the archive. | 
| static int | LONGFILE_GNUGNU tar extensions are used to store long file names in the archive. | 
| static int | LONGFILE_POSIXPOSIX/PAX extensions are used to store long file names in the archive. | 
| static int | LONGFILE_TRUNCATELong paths will be truncated in the archive. | 
| Constructor and Description | 
|---|
| TarArchiveOutputStream(OutputStream os)Constructor for TarArchiveOutputStream. | 
| TarArchiveOutputStream(OutputStream os,
                      int blockSize)Constructor for TarArchiveOutputStream. | 
| TarArchiveOutputStream(OutputStream os,
                      int blockSize,
                      int recordSize)Deprecated. 
 recordSize must always be 512 bytes. An IllegalArgumentException will be thrown
 if any other value is used | 
| TarArchiveOutputStream(OutputStream os,
                      int blockSize,
                      int recordSize,
                      String encoding)Deprecated. 
 recordSize must always be 512 bytes. An IllegalArgumentException will be thrown
 if any other value is used. | 
| TarArchiveOutputStream(OutputStream os,
                      int blockSize,
                      String encoding)Constructor for TarArchiveOutputStream. | 
| TarArchiveOutputStream(OutputStream os,
                      String encoding)Constructor for TarArchiveOutputStream. | 
| Modifier and Type | Method and Description | 
|---|---|
| void | close()Closes the underlying OutputStream. | 
| void | closeArchiveEntry()Close an entry. | 
| ArchiveEntry | createArchiveEntry(File inputFile,
                  String entryName)Create an archive entry using the inputFile and entryName provided. | 
| void | finish()Ends the TAR archive without closing the underlying OutputStream. | 
| void | flush() | 
| long | getBytesWritten()Returns the current number of bytes written to this stream. | 
| int | getCount()Deprecated.  | 
| int | getRecordSize()Deprecated.   | 
| void | putArchiveEntry(ArchiveEntry archiveEntry)Put an entry on the output stream. | 
| void | setAddPaxHeadersForNonAsciiNames(boolean b)Whether to add a PAX extension header for non-ASCII file names. | 
| void | setBigNumberMode(int bigNumberMode)Set the big number mode. | 
| void | setLongFileMode(int longFileMode)Set the long file mode. | 
| void | write(byte[] wBuf,
     int wOffset,
     int numToWrite)Writes bytes to the current tar archive entry. | 
canWriteEntryData, count, count, writewritepublic static final int LONGFILE_ERROR
public static final int LONGFILE_TRUNCATE
public static final int LONGFILE_GNU
public static final int LONGFILE_POSIX
public static final int BIGNUMBER_ERROR
public static final int BIGNUMBER_STAR
public static final int BIGNUMBER_POSIX
public TarArchiveOutputStream(OutputStream os)
Uses a block size of 512 bytes.
os - the output stream to usepublic TarArchiveOutputStream(OutputStream os, String encoding)
Uses a block size of 512 bytes.
os - the output stream to useencoding - name of the encoding to use for file namespublic TarArchiveOutputStream(OutputStream os, int blockSize)
os - the output stream to useblockSize - the block size to use. Must be a multiple of 512 bytes.@Deprecated public TarArchiveOutputStream(OutputStream os, int blockSize, int recordSize)
os - the output stream to useblockSize - the block size to userecordSize - the record size to use. Must be 512 bytes.@Deprecated public TarArchiveOutputStream(OutputStream os, int blockSize, int recordSize, String encoding)
os - the output stream to useblockSize - the block size to use . Must be a multiple of 512 bytes.recordSize - the record size to use. Must be 512 bytes.encoding - name of the encoding to use for file namespublic TarArchiveOutputStream(OutputStream os, int blockSize, String encoding)
os - the output stream to useblockSize - the block size to use. Must be a multiple of 512 bytes.encoding - name of the encoding to use for file namespublic void setLongFileMode(int longFileMode)
longFileMode - the mode to usepublic void setBigNumberMode(int bigNumberMode)
bigNumberMode - the mode to usepublic void setAddPaxHeadersForNonAsciiNames(boolean b)
b - whether to add a PAX extension header for non-ASCII file names.@Deprecated public int getCount()
ArchiveOutputStreamgetCount in class ArchiveOutputStreampublic long getBytesWritten()
ArchiveOutputStreamgetBytesWritten in class ArchiveOutputStreampublic void finish() throws IOException
finish in class ArchiveOutputStreamIOException - on errorpublic void close() throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class OutputStreamIOException - on error@Deprecated public int getRecordSize()
public void putArchiveEntry(ArchiveEntry archiveEntry) throws IOException
putArchiveEntry in class ArchiveOutputStreamarchiveEntry - The TarEntry to be written to the archive.IOException - on errorClassCastException - if archiveEntry is not an instance of TarArchiveEntrypublic void closeArchiveEntry() throws IOException
closeArchiveEntry in class ArchiveOutputStreamIOException - on errorpublic void write(byte[] wBuf, int wOffset, int numToWrite) throws IOException
write in class OutputStreamwBuf - The buffer to write to the archive.wOffset - The offset in the buffer from which to get bytes.numToWrite - The number of bytes to write.IOException - on errorpublic void flush() throws IOException
flush in interface Flushableflush in class OutputStreamIOExceptionpublic ArchiveEntry createArchiveEntry(File inputFile, String entryName) throws IOException
ArchiveOutputStreamcreateArchiveEntry in class ArchiveOutputStreaminputFile - the file to create the entry fromentryName - name to use for the entryIOException - if an I/O error occursCopyright © 2018 The Apache Software Foundation. All rights reserved.