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_ERROR
Fail if a big number (e.g.
|
static int |
BIGNUMBER_POSIX
POSIX/PAX extensions are used to store big numbers in the archive.
|
static int |
BIGNUMBER_STAR
star/GNU tar/BSD tar extensions are used to store big number in the archive.
|
static int |
LONGFILE_ERROR
Fail if a long file name is required in the archive.
|
static int |
LONGFILE_GNU
GNU tar extensions are used to store long file names in the archive.
|
static int |
LONGFILE_POSIX
POSIX/PAX extensions are used to store long file names in the archive.
|
static int |
LONGFILE_TRUNCATE
Long paths will be truncated in the archive.
|
| Constructor and Description |
|---|
TarArchiveOutputStream(java.io.OutputStream os)
Constructor for TarArchiveOutputStream.
|
TarArchiveOutputStream(java.io.OutputStream os,
int blockSize)
Constructor for TarArchiveOutputStream.
|
TarArchiveOutputStream(java.io.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(java.io.OutputStream os,
int blockSize,
int recordSize,
java.lang.String encoding)
Deprecated.
recordSize must always be 512 bytes. An IllegalArgumentException will be thrown
if any other value is used.
|
TarArchiveOutputStream(java.io.OutputStream os,
int blockSize,
java.lang.String encoding)
Constructor for TarArchiveOutputStream.
|
TarArchiveOutputStream(java.io.OutputStream os,
java.lang.String encoding)
Constructor for TarArchiveOutputStream.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the underlying OutputStream.
|
void |
closeArchiveEntry()
Close an entry.
|
ArchiveEntry |
createArchiveEntry(java.io.File inputFile,
java.lang.String entryName)
Create an archive entry using the inputFile and entryName provided.
|
ArchiveEntry |
createArchiveEntry(java.nio.file.Path inputPath,
java.lang.String entryName,
java.nio.file.LinkOption... options)
Create an archive entry using the inputPath 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, writepublic 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(java.io.OutputStream os)
Uses a block size of 512 bytes.
os - the output stream to usepublic TarArchiveOutputStream(java.io.OutputStream os,
java.lang.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(java.io.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(java.io.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(java.io.OutputStream os,
int blockSize,
int recordSize,
java.lang.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(java.io.OutputStream os,
int blockSize,
java.lang.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 java.io.IOException
finish in class ArchiveOutputStreamjava.io.IOException - on errorpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.OutputStreamjava.io.IOException - on error@Deprecated public int getRecordSize()
public void putArchiveEntry(ArchiveEntry archiveEntry) throws java.io.IOException
putArchiveEntry in class ArchiveOutputStreamarchiveEntry - The TarEntry to be written to the archive.java.io.IOException - on errorjava.lang.ClassCastException - if archiveEntry is not an instance of TarArchiveEntryjava.lang.IllegalArgumentException - if the longFileMode equals
LONGFILE_ERROR and the file
name is too longjava.lang.IllegalArgumentException - if the bigNumberMode equals
BIGNUMBER_ERROR and one of the numeric values
exceeds the limits of a traditional tar header.public void closeArchiveEntry()
throws java.io.IOException
closeArchiveEntry in class ArchiveOutputStreamjava.io.IOException - on errorpublic void write(byte[] wBuf,
int wOffset,
int numToWrite)
throws java.io.IOException
write in class java.io.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.java.io.IOException - on errorpublic void flush()
throws java.io.IOException
flush in interface java.io.Flushableflush in class java.io.OutputStreamjava.io.IOExceptionpublic ArchiveEntry createArchiveEntry(java.io.File inputFile, java.lang.String entryName) throws java.io.IOException
ArchiveOutputStreamcreateArchiveEntry in class ArchiveOutputStreaminputFile - the file to create the entry fromentryName - name to use for the entryjava.io.IOException - if an I/O error occurspublic ArchiveEntry createArchiveEntry(java.nio.file.Path inputPath, java.lang.String entryName, java.nio.file.LinkOption... options) throws java.io.IOException
ArchiveOutputStreamreturn createArchiveEntry(inputFile.toFile(), entryName);Subclasses should override this method.
createArchiveEntry in class ArchiveOutputStreaminputPath - the file to create the entry fromentryName - name to use for the entryoptions - options indicating how symbolic links are handled.java.io.IOException - if an I/O error occursCopyright © 2010 - 2023 Adobe. All Rights Reserved