TarArchive

Inheritance: java.lang.Object, com.aspose.zip.ILicenseStateProvider

All Implemented Interfaces: com.aspose.ms.System.IDisposable, com.aspose.zip.IArchive, java.lang.AutoCloseable

public class TarArchive extends ILicenseStateProvider implements System.IDisposable, IArchive, AutoCloseable

This class represents tar archive file. Use it to compose, extract, or update tar archives.

Constructors

ConstructorDescription
TarArchive()Initializes a new instance of the TarArchive class.
TarArchive(InputStream sourceStream)Initializes a new instance of the Archive class and composes entries list can be extracted from the archive.
TarArchive(String path)Initializes a new instance of the TarArchive class and composes entries list can be extracted from the archive.

Methods

MethodDescription
close(){@inheritDoc}
createEntries(File directory)Adds to the archive all the files and directories recursively in the directory given.
createEntries(File directory, boolean includeRootDirectory)Adds to the archive all the files and directories recursively in the directory given.
createEntries(String sourceDirectory)Adds to the archive all the files and directories recursively in the directory given.
createEntries(String sourceDirectory, boolean includeRootDirectory)Adds to the archive all the files and directories recursively in the directory given.
createEntry(String name, File fileInfo)Create single entry within the archive.
createEntry(String name, File fileInfo, boolean openImmediately)Create single entry within the archive.
createEntry(String name, InputStream source)Create single entry within the archive.
createEntry(String name, InputStream source, File fileInfo)Create single entry within the archive.
createEntry(String name, String path)Create single entry within the archive.
createEntry(String name, String path, boolean openImmediately)Create single entry within the archive.
deleteEntry(TarEntry entry)Removes the first occurrence of a specific entry from the entries list.
deleteEntry(int entryIndex)Removes the entry from the entries list by index.
dispose()Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
extractToDirectory(String destinationDirectory)Extracts all the files in the archive to the directory provided.
fromGZip(InputStream source)Extracts supplied gzip archive and composes TarArchive from extracted data.
fromGZip(String path)Extracts supplied gzip archive and composes TarArchive from extracted data.
fromLZMA(InputStream source)Extracts supplied LZMA archive and composes TarArchive from extracted data.
fromLZMA(String path)Extracts supplied LZMA archive and composes TarArchive from extracted data.
fromLZip(InputStream source)Extracts supplied lzip archive and composes TarArchive from extracted data.
fromLZip(String path)Extracts supplied lzip archive and composes TarArchive from extracted data.
fromXz(InputStream source)Extracts supplied xz format archive and composes TarArchive from extracted data.
fromXz(String path)Extracts supplied xz format archive and composes TarArchive from extracted data.
getEntries()Gets entries of TarEntry type constituting the archive.
getFileEntries()Gets entries of IArchiveFileEntry type constituting the tar archive.
save(OutputStream output)Saves archive to the stream provided.
save(OutputStream output, TarFormat format)Saves archive to the stream provided.
save(String destinationFileName)Saves archive to destination file provided.
save(String destinationFileName, TarFormat format)Saves archive to destination file provided.
saveGzipped(OutputStream output)Saves archive to the stream with gzip compression.
saveGzipped(OutputStream output, TarFormat format)Saves archive to the stream with gzip compression.
saveGzipped(String path)Saves archive to the file by path with gzip compression.
saveGzipped(String path, TarFormat format)Saves archive to the file by path with gzip compression.
saveLZMACompressed(OutputStream output)Saves archive to the stream with LZMA compression.
saveLZMACompressed(OutputStream output, TarFormat format)Saves archive to the stream with LZMA compression.
saveLZMACompressed(String path)Saves archive to the file by path with lzma compression.
saveLZMACompressed(String path, TarFormat format)Saves archive to the file by path with lzma compression.
saveLzipped(OutputStream output)Saves archive to the stream with lzip compression.
saveLzipped(OutputStream output, TarFormat format)Saves archive to the stream with lzip compression.
saveLzipped(String path)Saves archive to the file by path with lzip compression.
saveLzipped(String path, TarFormat format)Saves archive to the file by path with lzip compression.
saveXzCompressed(OutputStream output)Saves archive to the stream with xz compression.
saveXzCompressed(OutputStream output, TarFormat format)Saves archive to the stream with xz compression.
saveXzCompressed(OutputStream output, TarFormat format, XzArchiveSettings settings)Saves archive to the stream with xz compression.
saveXzCompressed(String path)Saves archive to the file by path with xz compression.
saveXzCompressed(String path, TarFormat format)Saves archive to the file by path with xz compression.
saveXzCompressed(String path, TarFormat format, XzArchiveSettings settings)Saves archive to the file by path with xz compression.

TarArchive()

public TarArchive()

Initializes a new instance of the TarArchive class.

The following example shows how to compress a file.


     try (TarArchive archive = new TarArchive()) {
             archive.createEntry(first.bin, "data.bin");
             archive.save("archive.tar");
     }
 

TarArchive(InputStream sourceStream)

public TarArchive(InputStream sourceStream)

Initializes a new instance of the Archive class and composes entries list can be extracted from the archive.

The following example shows how to extract all of the entries to a directory.


     try (TarArchive archive = new TarArchive(new FileInputStream("archive.tar"))) {
             archive.extractToDirectory("C:\\extracted");
     } catch (IOException ex) {
         System.out.println(ex);
     }
 

This constructor does not unpack any entry. See TarEntry.open() method for unpacking.

Parameters:

ParameterTypeDescription
sourceStreamjava.io.InputStreamThe source of the archive. It must be seekable.

TarArchive(String path)

public TarArchive(String path)

Initializes a new instance of the TarArchive class and composes entries list can be extracted from the archive.

The following example shows how to extract all of the entries to a directory.


     try (TarArchive archive = new TarArchive("archive.tar")) {
         archive.extractToDirectory("C:\\extracted");
     }
 

This constructor does not unpack any entry. See TarEntry.open() method for unpacking.

Parameters:

ParameterTypeDescription
pathjava.lang.StringThe path to the archive file.

close()

public void close()

createEntries(File directory)

public final TarArchive createEntries(File directory)

Adds to the archive all the files and directories recursively in the directory given.


     try (FileOutputStream tarFile = new FileOutputStream("archive.tar")) {
         try (TarArchive archive = new TarArchive()) {
             archive.createEntries(new java.io.File("C:\\folder"), false);
             archive.save(tarFile);
         }
     } catch (IOException ex) {
         System.out.println(ex);
     }
 

Parameters:

ParameterTypeDescription
directoryjava.io.FileDirectory to compress.

Returns: TarArchive - The archive with entries composed.

createEntries(File directory, boolean includeRootDirectory)

public final TarArchive createEntries(File directory, boolean includeRootDirectory)

Adds to the archive all the files and directories recursively in the directory given.


     try (FileOutputStream tarFile = new FileOutputStream("archive.tar")) {
         try (TarArchive archive = new TarArchive()) {
             archive.createEntries(new java.io.File("C:\\folder"), false);
             archive.save(tarFile);
         }
     } catch (IOException ex) {
         System.out.println(ex);
     }
 

Parameters:

ParameterTypeDescription
directoryjava.io.FileDirectory to compress.
includeRootDirectorybooleanIndicates whether to include the root directory itself or not.

Returns: TarArchive - The archive with entries composed.

createEntries(String sourceDirectory)

public final TarArchive createEntries(String sourceDirectory)

Adds to the archive all the files and directories recursively in the directory given.


     try (FileOutputStream tarFile = new FileOutputStream("archive.tar")) {
         try (TarArchive archive = new TarArchive()) {
             archive.createEntries("C:\\folder", false);
             archive.save(tarFile);
         }
     } catch (IOException ex) {
         System.out.println(ex);
     }
 

Parameters:

ParameterTypeDescription
sourceDirectoryjava.lang.StringDirectory to compress.

Returns: TarArchive - The archive with entries composed.

createEntries(String sourceDirectory, boolean includeRootDirectory)

public final TarArchive createEntries(String sourceDirectory, boolean includeRootDirectory)

Adds to the archive all the files and directories recursively in the directory given.


     try (FileOutputStream tarFile = new FileOutputStream("archive.tar")) {
         try (TarArchive archive = new TarArchive()) {
             archive.createEntries("C:\\folder", false);
             archive.save(tarFile);
         }
     } catch (IOException ex) {
         System.out.println(ex);
     }
 

Parameters:

ParameterTypeDescription
sourceDirectoryjava.lang.StringDirectory to compress.
includeRootDirectorybooleanIndicates whether to include the root directory itself or not.

Returns: TarArchive - The archive with entries composed.

createEntry(String name, File fileInfo)

public final TarEntry createEntry(String name, File fileInfo)

Create single entry within the archive.


     File fi = new File("data.bin");
     try (TarArchive archive = new TarArchive()) {
         archive.createEntry("data.bin", fi);
         archive.save(tarFile);
     }
 

The entry name is solely set within name parameter. The file name provided in fileInfo parameter does not affect the entry name.

fileInfo can refer to DirectoryInfo if the entry is directory.

Parameters:

ParameterTypeDescription
namejava.lang.StringThe name of the entry.
fileInfojava.io.FileThe metadata of file or folder to be compressed.

Returns: TarEntry - Tar entry instance.

createEntry(String name, File fileInfo, boolean openImmediately)

public final TarEntry createEntry(String name, File fileInfo, boolean openImmediately)

Create single entry within the archive.


     File fi = new File("data.bin");
     try (TarArchive archive = new TarArchive()) {
         archive.createEntry("data.bin", fi);
         archive.save(tarFile);
     }
 

The entry name is solely set within name parameter. The file name provided in fileInfo parameter does not affect the entry name.

fileInfo can refer to DirectoryInfo if the entry is directory.

If the file is opened immediately with openImmediately parameter it becomes blocked until archive is disposed.

Parameters:

ParameterTypeDescription
namejava.lang.StringThe name of the entry.
fileInfojava.io.FileThe metadata of file or folder to be compressed.
openImmediatelybooleanTrue if open the file immediately, otherwise open the file on archive saving.

Returns: TarEntry - Tar entry instance.

createEntry(String name, InputStream source)

public final TarEntry createEntry(String name, InputStream source)

Create single entry within the archive.


     try (TarArchive archive = new TarArchive()) {
         archive.createEntry("bytes", new ByteArrayInputStream(new byte[] {0x00, (byte) 0xFF}));
         archive.save(tarFile);
     }
 

The entry name is solely set within name parameter.

Parameters:

ParameterTypeDescription
namejava.lang.StringThe name of the entry.
sourcejava.io.InputStreamThe input stream for the entry.

Returns: TarEntry - Tar entry instance.

createEntry(String name, InputStream source, File fileInfo)

public final TarEntry createEntry(String name, InputStream source, File fileInfo)

Create single entry within the archive.


     try (TarArchive archive = new TarArchive()) {
         archive.createEntry("bytes", new ByteArrayInputStream(new byte[] {0x00, (byte) 0xFF}));
         archive.save(tarFile);
     }
 

The entry name is solely set within name parameter. The file name provided in fileInfo parameter does not affect the entry name.

fileInfo can refer to DirectoryInfo if the entry is directory.

Parameters:

ParameterTypeDescription
namejava.lang.StringThe name of the entry.
sourcejava.io.InputStreamThe input stream for the entry.
fileInfojava.io.FileThe metadata of file or folder to be compressed.

Returns: TarEntry - Tar entry instance.

createEntry(String name, String path)

public final TarEntry createEntry(String name, String path)

Create single entry within the archive.


     try (TarArchive archive = new TarArchive()) {
             archive.createEntry(first.bin, "data.bin");
             archive.save(outputTarFile);
     }
 

The entry name is solely set within name parameter. The file name provided in path parameter does not affect the entry name.

Parameters:

ParameterTypeDescription
namejava.lang.StringThe name of the entry.
pathjava.lang.StringPath to file to be compressed.

Returns: TarEntry - Tar entry instance.

createEntry(String name, String path, boolean openImmediately)

public final TarEntry createEntry(String name, String path, boolean openImmediately)

Create single entry within the archive.


     try (TarArchive archive = new TarArchive()) {
             archive.createEntry(first.bin, "data.bin");
             archive.save(outputTarFile);
     }
 

The entry name is solely set within name parameter. The file name provided in path parameter does not affect the entry name.

If the file is opened immediately with openImmediately parameter it becomes blocked until archive is disposed.

Parameters:

ParameterTypeDescription
namejava.lang.StringThe name of the entry.
pathjava.lang.StringPath to file to be compressed.
openImmediatelybooleanTrue if open the file immediately, otherwise open the file on archive saving.

Returns: TarEntry - Tar entry instance.

deleteEntry(TarEntry entry)

public final TarArchive deleteEntry(TarEntry entry)

Removes the first occurrence of a specific entry from the entries list.

Here is how you can remove all entries except the last one:


     try (TarArchive archive = new TarArchive("archive.tar")) {
         while (archive.getEntries().size() > 1)
             archive.deleteEntry(archive.getEntries().get_Item(0));
         archive.save(outputTarFile);
     }
 

Parameters:

ParameterTypeDescription
entryTarEntryThe entry to remove from the entries list.

Returns: TarArchive - The archive with the entry deleted.

deleteEntry(int entryIndex)

public final TarArchive deleteEntry(int entryIndex)

Removes the entry from the entries list by index.


     try (TarArchive archive = new TarArchive("two_files.tar")) {
         archive.deleteEntry(0);
         archive.save("single_file.tar");
     }
 

Parameters:

ParameterTypeDescription
entryIndexintThe zero-based index of the entry to remove.

Returns: TarArchive - The archive with the entry deleted.

dispose()

public final void dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

extractToDirectory(String destinationDirectory)

public final void extractToDirectory(String destinationDirectory)

Extracts all the files in the archive to the directory provided.


     try (TarArchive archive = new TarArchive("archive.tar")) {
         archive.extractToDirectory("C:\\extracted");
     }
 

If the directory does not exist, it will be created.

Parameters:

ParameterTypeDescription
destinationDirectoryjava.lang.StringThe path to the directory to place the extracted files in.

fromGZip(InputStream source)

public static TarArchive fromGZip(InputStream source)

Extracts supplied gzip archive and composes TarArchive from extracted data.

Important: gzip archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.

Parameters:

ParameterTypeDescription
sourcejava.io.InputStreamThe source of the archive.

GZip extraction stream is not seekable by the nature of compression algorithm. Tar archive provides facility to extract arbitrary record, so it has to operate seekable stream under the hood. |

Returns: TarArchive - An instance of TarArchive

fromGZip(String path)

public static TarArchive fromGZip(String path)

Extracts supplied gzip archive and composes TarArchive from extracted data.

Important: gzip archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.

Parameters:

ParameterTypeDescription
pathjava.lang.StringThe path to the archive file.

GZip extraction stream is not seekable by the nature of compression algorithm. Tar archive provides facility to extract arbitrary record, so it has to operate seekable stream under the hood. |

Returns: TarArchive - An instance of TarArchive

fromLZMA(InputStream source)

public static TarArchive fromLZMA(InputStream source)

Extracts supplied LZMA archive and composes TarArchive from extracted data.

Important: LZMA archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.

LZMA extraction stream is not seekable by the nature of compression algorithm. Tar archive provides facility to extract arbitrary record, so it has to operate seekable stream under the hood.

Parameters:

ParameterTypeDescription
sourcejava.io.InputStreamThe source stream.

Returns: TarArchive - An instance of TarArchive

fromLZMA(String path)

public static TarArchive fromLZMA(String path)

Extracts supplied LZMA archive and composes TarArchive from extracted data.

Important: LZMA archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.

LZMA extraction stream is not seekable by the nature of compression algorithm. Tar archive provides facility to extract arbitrary record, so it has to operate seekable stream under the hood.

Parameters:

ParameterTypeDescription
pathjava.lang.StringThe path to the archive file.

Returns: TarArchive - An instance of TarArchive

fromLZip(InputStream source)

public static TarArchive fromLZip(InputStream source)

Extracts supplied lzip archive and composes TarArchive from extracted data.

Important: lzip archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.

Parameters:

ParameterTypeDescription
sourcejava.io.InputStreamthe source of the archive.

Lzip extraction stream is not seekable by the nature of compression algorithm. Tar archive provides facility to extract arbitrary record, so it has to operate seekable stream under the hood |

Returns: TarArchive - an instance of TarArchive

fromLZip(String path)

public static TarArchive fromLZip(String path)

Extracts supplied lzip archive and composes TarArchive from extracted data.

Important: lzip archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.

Parameters:

ParameterTypeDescription
pathjava.lang.Stringthe path to the archive file.

Lzip extraction stream is not seekable by the nature of compression algorithm. Tar archive provides facility to extract arbitrary record, so it has to operate seekable stream under the hood |

Returns: TarArchive - an instance of TarArchive

fromXz(InputStream source)

public static TarArchive fromXz(InputStream source)

Extracts supplied xz format archive and composes TarArchive from extracted data.

Important: xz archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.

Tar archive provides facility to extract arbitrary record, so it has to operate seekable stream under the hood.

Parameters:

ParameterTypeDescription
sourcejava.io.InputStreamThe source of the archive.

Returns: TarArchive - An instance of TarArchive

fromXz(String path)

public static TarArchive fromXz(String path)

Extracts supplied xz format archive and composes TarArchive from extracted data.

Important: xz archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.

Tar archive provides facility to extract arbitrary record, so it has to operate seekable stream under the hood.

Parameters:

ParameterTypeDescription
pathjava.lang.StringThe path to the archive file.

Returns: TarArchive - An instance of TarArchive

getEntries()

public final List<TarEntry> getEntries()

Gets entries of TarEntry type constituting the archive.

Returns: java.util.List<com.aspose.zip.TarEntry> - entries of TarEntry type constituting the archive.

getFileEntries()

public final Iterable<IArchiveFileEntry> getFileEntries()

Gets entries of IArchiveFileEntry type constituting the tar archive.

Returns: java.lang.Iterable<com.aspose.zip.IArchiveFileEntry> - entries of IArchiveFileEntry type constituting the tar archive.

save(OutputStream output)

public final void save(OutputStream output)

Saves archive to the stream provided.


     try (FileOutputStream tarFile = new FileOutputStream("archive.tar")) {
         try (TarArchive archive = new TarArchive()) {
             archive.createEntry("entry1", "data.bin");
             archive.save(tarFile);
         }
     } catch (IOException ex) {
         System.out.println(ex);
     }
 

Parameters:

ParameterTypeDescription
outputjava.io.OutputStreamDestination stream.

output must be writable. |

save(OutputStream output, TarFormat format)

public final void save(OutputStream output, TarFormat format)

Saves archive to the stream provided.


     try (FileOutputStream tarFile = new FileOutputStream("archive.tar")) {
         try (TarArchive archive = new TarArchive()) {
             archive.createEntry("entry1", "data.bin");
             archive.save(tarFile);
         }
     } catch (IOException ex) {
         System.out.println(ex);
     }
 

Parameters:

ParameterTypeDescription
outputjava.io.OutputStreamDestination stream.

output must be writable. | | format | TarFormat | Defines tar header format. Null value will be treated as USTar when possible. |

save(String destinationFileName)

public final void save(String destinationFileName)

Saves archive to destination file provided.


     try (TarArchive archive = new TarArchive()) {
         archive.createEntry("entry1", "data.bin");
         archive.save("myarchive.tar");
 }
 

Parameters:

ParameterTypeDescription
destinationFileNamejava.lang.StringThe path of the archive to be created. If the specified file name points to an existing file, it will be overwritten.

It is possible to save an archive to the same path as it was loaded from. However, this is not recommended because this approach uses copying to temporary file. |

save(String destinationFileName, TarFormat format)

public final void save(String destinationFileName, TarFormat format)

Saves archive to destination file provided.


     try (TarArchive archive = new TarArchive()) {
         archive.createEntry("entry1", "data.bin");
         archive.save("myarchive.tar");
 }
 

Parameters:

ParameterTypeDescription
destinationFileNamejava.lang.StringThe path of the archive to be created. If the specified file name points to an existing file, it will be overwritten.

It is possible to save an archive to the same path as it was loaded from. However, this is not recommended because this approach uses copying to temporary file. | | format | TarFormat | Defines tar header format. Null value will be treated as USTar when possible. |

saveGzipped(OutputStream output)

public final void saveGzipped(OutputStream output)

Saves archive to the stream with gzip compression.


     try (FileOutputStream result = new FileOutputStream("result.tar.gz")) {
         try (FileInputStream source = new FileInputStream("data.bin")) {
             try (TarArchive archive = new TarArchive()) {
                 archive.createEntry("entry.bin", source);
                 archive.saveGzipped(result);
             }
         }
     } catch (IOException ex) {
         System.out.println(ex);
     }
 

Parameters:

ParameterTypeDescription
outputjava.io.OutputStreamDestination stream.

output must be writable. |

saveGzipped(OutputStream output, TarFormat format)

public final void saveGzipped(OutputStream output, TarFormat format)

Saves archive to the stream with gzip compression.


     try (FileOutputStream result = new FileOutputStream("result.tar.gz")) {
         try (FileInputStream source = new FileInputStream("data.bin")) {
             try (TarArchive archive = new TarArchive()) {
                 archive.createEntry("entry.bin", source);
                 archive.saveGzipped(result);
             }
         }
     } catch (IOException ex) {
         System.out.println(ex);
     }
 

Parameters:

ParameterTypeDescription
outputjava.io.OutputStreamDestination stream.

output must be writable. | | format | TarFormat | Defines tar header format. Null value will be treated as USTar when possible. |

saveGzipped(String path)

public final void saveGzipped(String path)

Saves archive to the file by path with gzip compression.


     try (FileInputStream source = new FileInputStream("data.bin")) {
         try (TarArchive archive = new TarArchive()) {
             archive.createEntry("entry.bin", source);
             archive.saveGzipped("result.tar.gz");
         }
     } catch (IOException ex) {
         System.out.println(ex);
     }
 

Parameters:

ParameterTypeDescription
pathjava.lang.StringThe path of the archive to be created. If the specified file name points to an existing file, it will be overwritten.

saveGzipped(String path, TarFormat format)

public final void saveGzipped(String path, TarFormat format)

Saves archive to the file by path with gzip compression.


     try (FileInputStream source = new FileInputStream("data.bin")) {
         try (TarArchive archive = new TarArchive()) {
             archive.createEntry("entry.bin", source);
             archive.saveGzipped("result.tar.gz");
         }
     } catch (IOException ex) {
         System.out.println(ex);
     }
 

Parameters:

ParameterTypeDescription
pathjava.lang.StringThe path of the archive to be created. If the specified file name points to an existing file, it will be overwritten.
formatTarFormatDefines tar header format. Null value will be treated as USTar when possible.

saveLZMACompressed(OutputStream output)

public final void saveLZMACompressed(OutputStream output)

Saves archive to the stream with LZMA compression.


     try (FileOutputStream result = new FileOutputStream("result.tar.lzma")) {
         try (FileInputStream source = new FileInputStream("data.bin")) {
             try (TarArchive archive = new TarArchive()) {
                 archive.createEntry("entry.bin", source);
                 archive.saveLZMACompressed(result);
             }
         }
     } catch (IOException ex) {
     }
 

Important: tar archive is composed then compressed within this method, its content is kept internally. Beware of memory consumption.

Parameters:

ParameterTypeDescription
outputjava.io.OutputStreamDestination stream.

output must be writable. |

saveLZMACompressed(OutputStream output, TarFormat format)

public final void saveLZMACompressed(OutputStream output, TarFormat format)

Saves archive to the stream with LZMA compression.


     try (FileOutputStream result = new FileOutputStream("result.tar.lzma")) {
         try (FileInputStream source = new FileInputStream("data.bin")) {
             try (TarArchive archive = new TarArchive()) {
                 archive.createEntry("entry.bin", source);
                 archive.saveLZMACompressed(result);
             }
         }
     } catch (IOException ex) {
     }
 

Important: tar archive is composed then compressed within this method, its content is kept internally. Beware of memory consumption.

Parameters:

ParameterTypeDescription
outputjava.io.OutputStreamDestination stream.

output must be writable. | | format | TarFormat | Defines tar header format. Null value will be treated as USTar when possible. |

saveLZMACompressed(String path)

public final void saveLZMACompressed(String path)

Saves archive to the file by path with lzma compression.


     try (FileInputStream source = new FileInputStream("data.bin")) {
         try (TarArchive archive = new TarArchive()) {
             archive.createEntry("entry.bin", source);
             archive.saveLZMACompressed("result.tar.lzma");
         }
     } catch (IOException ex) {
     }
 

Important: tar archive is composed then compressed within this method, its content is kept internally. Beware of memory consumption.

Parameters:

ParameterTypeDescription
pathjava.lang.StringThe path of the archive to be created. If the specified file name points to an existing file, it will be overwritten.

saveLZMACompressed(String path, TarFormat format)

public final void saveLZMACompressed(String path, TarFormat format)

Saves archive to the file by path with lzma compression.


     try (FileInputStream source = new FileInputStream("data.bin")) {
         try (TarArchive archive = new TarArchive()) {
             archive.createEntry("entry.bin", source);
             archive.saveLZMACompressed("result.tar.lzma");
         }
     } catch (IOException ex) {
     }
 

Important: tar archive is composed then compressed within this method, its content is kept internally. Beware of memory consumption.

Parameters:

ParameterTypeDescription
pathjava.lang.StringThe path of the archive to be created. If the specified file name points to an existing file, it will be overwritten.
formatTarFormatDefines tar header format. Null value will be treated as USTar when possible.

saveLzipped(OutputStream output)

public final void saveLzipped(OutputStream output)

Saves archive to the stream with lzip compression.


     try (FileOutputStream result = new FileOutputStream("result.tar.lz")) {
         try (FileInputStream source = new FileInputStream("data.bin")) {
             try (TarArchive archive = new TarArchive()) {
                 archive.createEntry("entry.bin", source);
                 archive.saveLzipped(result);
             }
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
outputjava.io.OutputStreamdestination stream.

output must be writable |

saveLzipped(OutputStream output, TarFormat format)

public final void saveLzipped(OutputStream output, TarFormat format)

Saves archive to the stream with lzip compression.


     try (FileOutputStream result = new FileOutputStream("result.tar.lz")) {
         try (FileInputStream source = new FileInputStream("data.bin")) {
             try (TarArchive archive = new TarArchive()) {
                 archive.createEntry("entry.bin", source);
                 archive.saveLzipped(result, TarFormat.Gnu);
             }
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
outputjava.io.OutputStreamdestination stream.

output must be writable | | format | TarFormat | defines tar header format. Null value will be treated as USTar when possible |

saveLzipped(String path)

public final void saveLzipped(String path)

Saves archive to the file by path with lzip compression.


     try (FileInputStream source = new FileInputStream("data.bin")) {
         try (TarArchive archive = new TarArchive()) {
             archive.createEntry("entry.bin", source);
             archive.saveLzipped("result.tar.lz");
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
pathjava.lang.Stringthe path of the archive to be created. If the specified file name points to an existing file, it will be overwritten

saveLzipped(String path, TarFormat format)

public final void saveLzipped(String path, TarFormat format)

Saves archive to the file by path with lzip compression.


     try (FileInputStream source = new FileInputStream("data.bin")) {
         try (TarArchive archive = new TarArchive()) {
             archive.createEntry("entry.bin", source);
             archive.saveLzipped("result.tar.lz", TarFormat.Gnu);
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
pathjava.lang.Stringthe path of the archive to be created. If the specified file name points to an existing file, it will be overwritten
formatTarFormatdefines tar header format. Null value will be treated as USTar when possible

saveXzCompressed(OutputStream output)

public final void saveXzCompressed(OutputStream output)

Saves archive to the stream with xz compression.


     try (FileOutputStream result = new FileOutputStream("result.tar.xz")) {
         try (FileInputStream source = new FileInputStream("data.bin")) {
             try (TarArchive archive = new TarArchive()) {
                 archive.createEntry("entry.bin", source);
                 archive.saveXzCompressed(result);
             }
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
outputjava.io.OutputStreamDestination stream.

outputThe stream must be writable. |

saveXzCompressed(OutputStream output, TarFormat format)

public final void saveXzCompressed(OutputStream output, TarFormat format)

Saves archive to the stream with xz compression.


     try (FileOutputStream result = new FileOutputStream("result.tar.xz")) {
         try (FileInputStream source = new FileInputStream("data.bin")) {
             try (TarArchive archive = new TarArchive()) {
                 archive.createEntry("entry.bin", source);
                 archive.saveXzCompressed(result);
             }
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
outputjava.io.OutputStreamDestination stream.

outputThe stream must be writable. | | format | TarFormat | Defines tar header format. Null value will be treated as USTar when possible. |

saveXzCompressed(OutputStream output, TarFormat format, XzArchiveSettings settings)

public final void saveXzCompressed(OutputStream output, TarFormat format, XzArchiveSettings settings)

Saves archive to the stream with xz compression.


     try (FileOutputStream result = new FileOutputStream("result.tar.xz")) {
         try (FileInputStream source = new FileInputStream("data.bin")) {
             try (TarArchive archive = new TarArchive()) {
                 archive.createEntry("entry.bin", source);
                 archive.saveXzCompressed(result);
             }
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
outputjava.io.OutputStreamDestination stream.

outputThe stream must be writable. | | format | TarFormat | Defines tar header format. Null value will be treated as USTar when possible. | | settings | XzArchiveSettings | Set of setting particular xz archive: dictionary size, block size, check type. |

saveXzCompressed(String path)

public final void saveXzCompressed(String path)

Saves archive to the file by path with xz compression.


     try (FileInputStream source = new FileInputStream("data.bin")) {
         try (TarArchive archive = new TarArchive()) {
             archive.createEntry("entry.bin", source);
             archive.saveXzCompressed("result.tar.xz");
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
pathjava.lang.StringThe path of the archive to be created. If the specified file name points to an existing file, it will be overwritten.

saveXzCompressed(String path, TarFormat format)

public final void saveXzCompressed(String path, TarFormat format)

Saves archive to the file by path with xz compression.


     try (FileInputStream source = new FileInputStream("data.bin")) {
         try (TarArchive archive = new TarArchive()) {
             archive.createEntry("entry.bin", source);
             archive.saveXzCompressed("result.tar.xz");
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
pathjava.lang.StringThe path of the archive to be created. If the specified file name points to an existing file, it will be overwritten.
formatTarFormatDefines tar header format. Null value will be treated as USTar when possible.

saveXzCompressed(String path, TarFormat format, XzArchiveSettings settings)

public final void saveXzCompressed(String path, TarFormat format, XzArchiveSettings settings)

Saves archive to the file by path with xz compression.


     try (FileInputStream source = new FileInputStream("data.bin")) {
         try (TarArchive archive = new TarArchive()) {
             archive.createEntry("entry.bin", source);
             archive.saveXzCompressed("result.tar.xz");
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
pathjava.lang.StringThe path of the archive to be created. If the specified file name points to an existing file, it will be overwritten.
formatTarFormatDefines tar header format. Null value will be treated as USTar when possible.
settingsXzArchiveSettingsSet of setting particular xz archive: dictionary size, block size, check type.