Class TarArchive
- java.lang.Object
-
- com.aspose.zip.TarArchive
-
- All Implemented Interfaces:
IArchive,AutoCloseable
public class TarArchive extends Object implements IArchive, AutoCloseable
This class represents a tar archive file. Use it to compose, extract, or update tar archives.
-
-
Constructor Summary
Constructors Constructor Description TarArchive()Initializes a new instance of theTarArchiveclass.TarArchive(InputStream sourceStream)Initializes a new instance of theArchiveclass and composes an entry list can be extracted from the archive.TarArchive(String path)Initializes a new instance of theTarArchiveclass and composes an entry list can be extracted from the archive.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()TarArchivecreateEntries(File directory)Adds to the archive all the files and directories recursively in the directory given.TarArchivecreateEntries(File directory, boolean includeRootDirectory)Adds to the archive all the files and directories recursively in the directory given.TarArchivecreateEntries(String sourceDirectory)Adds to the archive all the files and directories recursively in the directory given.TarArchivecreateEntries(String sourceDirectory, boolean includeRootDirectory)Adds to the archive all the files and directories recursively in the directory given.TarEntrycreateEntry(String name, File file)Creates a single entry within the archive.TarEntrycreateEntry(String name, File file, boolean openImmediately)Creates a single entry within the archive.TarEntrycreateEntry(String name, InputStream source)Creates a single entry within the archive.TarEntrycreateEntry(String name, InputStream source, File file)Creates a single entry within the archive.TarEntrycreateEntry(String name, String path)Creates a single entry within the archive.TarEntrycreateEntry(String name, String path, boolean openImmediately)Creates a single entry within the archive.TarArchivedeleteEntry(int entryIndex)Removes the entry from the entry list by index.TarArchivedeleteEntry(TarEntry entry)Removes the first occurrence of a specific entry from the entry list.voidextractToDirectory(String destinationDirectory)Extracts all the files in the archive to the directory provided.static TarArchivefromGZip(InputStream source)Extracts supplied gzip archive and composesTarArchivefrom extracted data.static TarArchivefromGZip(String path)Extracts supplied gzip archive and composesTarArchivefrom extracted data.static TarArchivefromLZ4(InputStream source)Extracts supplied LZ4 archive and composesTarArchivefrom extracted data.static TarArchivefromLZ4(String path)Extracts supplied LZ4 archive and composesTarArchivefrom extracted data.static TarArchivefromLZip(InputStream source)Extracts supplied lzip archive and composesTarArchivefrom extracted data.static TarArchivefromLZip(String path)Extracts supplied lzip archive and composesTarArchivefrom extracted data.static TarArchivefromLZMA(InputStream source)Extracts supplied LZMA archive and composesTarArchivefrom extracted data.static TarArchivefromLZMA(String path)Extracts supplied LZMA archive and composesTarArchivefrom extracted data.static TarArchivefromXz(InputStream source)Extracts supplied xz format archive and composesTarArchivefrom extracted data.static TarArchivefromXz(String path)Extracts supplied xz format archive and composesTarArchivefrom extracted data.static TarArchivefromZ(InputStream source)Extracts supplied Z format archive and composesTarArchivefrom extracted data.static TarArchivefromZ(String path)Extracts supplied Z format archive and composesTarArchivefrom extracted data.static TarArchivefromZstandard(InputStream source)Extracts supplied Zstandard archive and composesTarArchivefrom extracted data.static TarArchivefromZstandard(String path)Extracts supplied Zstandard archive and composesTarArchivefrom extracted data.List<TarEntry>getEntries()Gets entries ofTarEntrytype constituting the archive.Iterable<IArchiveFileEntry>getFileEntries()Gets entries ofIArchiveFileEntrytype constituting the tar archive.ArchiveFormatgetFormat()Gets the archive format.voidsave(OutputStream output)Saves archive to the stream provided.voidsave(OutputStream output, TarFormat format)Saves archive to the stream provided.voidsave(String destinationFileName)Saves archive to the destination file provided.voidsave(String destinationFileName, TarFormat format)Saves archive to the destination file provided.voidsaveGzipped(OutputStream output)Saves archive to the stream with gzip compression.voidsaveGzipped(OutputStream output, TarFormat format)Saves archive to the stream with gzip compression.voidsaveGzipped(String path)Saves archive to the file by path with gzip compression.voidsaveGzipped(String path, TarFormat format)Saves archive to the file by path with gzip compression.voidsaveLZ4Compressed(OutputStream output)Saves archive to the stream with LZ4 compression.voidsaveLZ4Compressed(OutputStream output, TarFormat format)Saves archive to the stream with LZ4 compression.voidsaveLZ4Compressed(String path)Saves archive to the file by path with LZ4 compression.voidsaveLZ4Compressed(String path, TarFormat format)Saves archive to the file by path with LZ4 compression.voidsaveLzipped(OutputStream output)Saves archive to the stream with lzip compression.voidsaveLzipped(OutputStream output, TarFormat format)Saves archive to the stream with lzip compression.voidsaveLzipped(String path)Saves archive to the file by path with lzip compression.voidsaveLzipped(String path, TarFormat format)Saves archive to the file by path with lzip compression.voidsaveLZMACompressed(OutputStream output)Saves archive to the stream with LZMA compression.voidsaveLZMACompressed(OutputStream output, TarFormat format)Saves archive to the stream with LZMA compression.voidsaveLZMACompressed(String path)Saves archive to the file by path with lzma compression.voidsaveLZMACompressed(String path, TarFormat format)Saves archive to the file by path with lzma compression.voidsaveXzCompressed(OutputStream output)Saves archive to the stream with xz compression.voidsaveXzCompressed(OutputStream output, TarFormat format)Saves archive to the stream with xz compression.voidsaveXzCompressed(OutputStream output, TarFormat format, XzArchiveSettings settings)Saves archive to the stream with xz compression.voidsaveXzCompressed(String path)Saves archive to the file by path with xz compression.voidsaveXzCompressed(String path, TarFormat format)Saves archive to the file by path with xz compression.voidsaveXzCompressed(String path, TarFormat format, XzArchiveSettings settings)Saves archive to the file by path with xz compression.voidsaveZCompressed(OutputStream output)Saves archive to the stream with Z compression.voidsaveZCompressed(OutputStream output, TarFormat format)Saves archive to the stream with Z compression.voidsaveZCompressed(String path)Saves archive to the file by path with Z compression.voidsaveZCompressed(String path, TarFormat format)Saves archive to the file by path with Z compression.voidsaveZstandard(OutputStream output)Saves archive to the stream with Zstandard compression.voidsaveZstandard(OutputStream output, TarFormat format)Saves archive to the stream with Zstandard compression.voidsaveZstandard(String path)Saves archive to the file by path with Zstandard compression.voidsaveZstandard(String path, TarFormat format)Saves archive to the file by path with Zstandard compression.
-
-
-
Constructor Detail
-
TarArchive
public TarArchive()
Initializes a new instance of the
TarArchiveclass.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
public TarArchive(InputStream sourceStream)
Initializes a new instance of the
Archiveclass and composes an entry list can be extracted from the archive.The following example shows how to extract all 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:
sourceStream- the source of the archive
-
TarArchive
public TarArchive(String path)
Initializes a new instance of the
TarArchiveclass and composes an entry list can be extracted from the archive.The following example shows how to extract all 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:
path- the path to the archive file- Throws:
com.aspose.ms.System.ArgumentNullException-pathis null.com.aspose.ms.System.SecurityException- The caller does not have the required permission to access.com.aspose.ms.System.ArgumentException- Thepathis empty, contains only white spaces, or contains invalid characters.com.aspose.ms.System.IO.PathTooLongException- The specifiedpath, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.com.aspose.ms.System.NotSupportedException- File atpathcontains a colon (:) in the middle of the string.
-
-
Method Detail
-
getEntries
public final List<TarEntry> getEntries()
Gets entries of
TarEntrytype constituting the archive.- Returns:
- entries of
TarEntrytype constituting the archive
-
getFileEntries
public final Iterable<IArchiveFileEntry> getFileEntries()
Gets entries of
IArchiveFileEntrytype constituting the tar archive.- Specified by:
getFileEntriesin interfaceIArchive- Returns:
- entries of
IArchiveFileEntrytype constituting the tar archive
-
getFormat
public final ArchiveFormat getFormat()
Gets the archive format.
-
createEntry
public final TarEntry createEntry(String name, InputStream source)
Creates a 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
nameparameter.- Parameters:
name- the name of the entrysource- the input stream for the entry- Returns:
- Tar entry instance
- Throws:
com.aspose.ms.System.IO.PathTooLongException-nameis too long for tar as of IEEE 1003.1-1998 standard.com.aspose.ms.System.ArgumentException- File name, as a part ofname, exceeds 100 symbols.
-
createEntry
public final TarEntry createEntry(String name, InputStream source, File file)
Creates a 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
nameparameter. The file name provided infileparameter does not affect the entry name.- Parameters:
name- the name of the entrysource- the input stream for the entryfile- the metadata of file or folder to be compressed- Returns:
- Tar entry instance
- Throws:
com.aspose.ms.System.IO.PathTooLongException-nameis too long for tar as of IEEE 1003.1-1998 standard.com.aspose.ms.System.ArgumentException- File name, as a part ofname, exceeds 100 symbols.
-
createEntry
public final TarEntry createEntry(String name, File file)
Creates a 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
nameparameter. The file name provided infileparameter does not affect the entry name.- Parameters:
name- the name of the entryfile- the metadata of file or folder to be compressed- Returns:
- Tar entry instance
- Throws:
com.aspose.ms.System.IO.PathTooLongException-nameis too long for tar as of IEEE 1003.1-1998 standard.com.aspose.ms.System.ArgumentException- File name, as a part ofname, exceeds 100 symbols.
-
createEntry
public final TarEntry createEntry(String name, File file, boolean openImmediately)
Creates a 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
nameparameter. The file name provided infileparameter does not affect the entry name.If the file is opened immediately with
openImmediatelyparameter it becomes blocked until archive is disposed.- Parameters:
name- the name of the entryfile- the metadata of file or folder to be compressedopenImmediately- true, if open the file immediately, otherwise open the file on archive saving- Returns:
- Tar entry instance
- Throws:
com.aspose.ms.System.IO.PathTooLongException-nameis too long for tar as of IEEE 1003.1-1998 standard.com.aspose.ms.System.ArgumentException- File name, as a part ofname, exceeds 100 symbols.
-
createEntry
public final TarEntry createEntry(String name, String path)
Creates a 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
nameparameter. The file name provided inpathparameter does not affect the entry name.- Parameters:
name- the name of the entrypath- path to file to be compressed- Returns:
- Tar entry instance
- Throws:
com.aspose.ms.System.ArgumentNullException-pathis null.com.aspose.ms.System.SecurityException- The caller does not have the required permission to access.com.aspose.ms.System.ArgumentException- Thepathis empty, contains only white spaces, or contains invalid characters. - or - File name, as a part ofname, exceeds 100 symbols.com.aspose.ms.System.IO.PathTooLongException- The specifiedpath, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. - or -nameis too long for tar as of IEEE 1003.1-1998 standard.com.aspose.ms.System.NotSupportedException- File atpathcontains a colon (:) in the middle of the string.
-
createEntry
public final TarEntry createEntry(String name, String path, boolean openImmediately)
Creates a 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
nameparameter. The file name provided inpathparameter does not affect the entry name.If the file is opened immediately with
openImmediatelyparameter it becomes blocked until archive is disposed.- Parameters:
name- the name of the entrypath- path to file to be compressedopenImmediately- true, if open the file immediately, otherwise open the file on archive saving- Returns:
- Tar entry instance
- Throws:
com.aspose.ms.System.ArgumentNullException-pathis null.com.aspose.ms.System.SecurityException- The caller does not have the required permission to access.com.aspose.ms.System.ArgumentException- Thepathis empty, contains only white spaces, or contains invalid characters. - or - File name, as a part ofname, exceeds 100 symbols.com.aspose.ms.System.IO.PathTooLongException- The specifiedpath, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. - or -nameis too long for tar as of IEEE 1003.1-1998 standard.com.aspose.ms.System.NotSupportedException- File atpathcontains a colon (:) in the middle of the string.
-
createEntries
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:
directory- directory to compress- Returns:
- the archive with entries composed
-
createEntries
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:
directory- directory to compressincludeRootDirectory- indicates whether to include the root directory itself or not- Returns:
- the archive with entries composed
-
createEntries
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:
sourceDirectory- directory to compress- Returns:
- the archive with entries composed
- Throws:
com.aspose.ms.System.ArgumentNullException-sourceDirectoryis null.com.aspose.ms.System.SecurityException- The caller does not have the required permission to accesssourceDirectory.com.aspose.ms.System.ArgumentException-sourceDirectorycontains invalid characters such as ", <, >, or |.com.aspose.ms.System.IO.PathTooLongException- The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. The specified path, file name, or both are too long.
-
createEntries
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:
sourceDirectory- directory to compressincludeRootDirectory- indicates whether to include the root directory itself or not- Returns:
- the archive with entries composed
- Throws:
com.aspose.ms.System.ArgumentNullException-sourceDirectoryis null.com.aspose.ms.System.SecurityException- The caller does not have the required permission to accesssourceDirectory.com.aspose.ms.System.ArgumentException-sourceDirectorycontains invalid characters such as ", <, >, or |.com.aspose.ms.System.IO.PathTooLongException- The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. The specified path, file name, or both are too long.
-
deleteEntry
public final TarArchive deleteEntry(TarEntry entry)
Removes the first occurrence of a specific entry from the entry 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:
entry- the entry to remove from the entries list- Returns:
- the archive with the entry deleted
-
deleteEntry
public final TarArchive deleteEntry(int entryIndex)
Removes the entry from the entry list by index.
try (TarArchive archive = new TarArchive("two_files.tar")) { archive.deleteEntry(0); archive.save("single_file.tar"); }- Parameters:
entryIndex- the zero-based index of the entry to remove- Returns:
- the archive with the entry deleted
- Throws:
com.aspose.ms.System.ArgumentOutOfRangeException-entryIndexis less than 0.-or-entryIndexis equal to or greater thanEntriescount.
-
extractToDirectory
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.
- Specified by:
extractToDirectoryin interfaceIArchive- Parameters:
destinationDirectory- the path to the directory to place the extracted files in- Throws:
com.aspose.ms.System.ArgumentNullException- path is nullcom.aspose.ms.System.IO.PathTooLongException- The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters and file names must be less than 260 characters.com.aspose.ms.System.SecurityException- The caller does not have the required permission to access the existing directory.com.aspose.ms.System.NotSupportedException- If the directory does not exist, the path contains a colon character (:) that is not part of a drive label ("C:\").com.aspose.ms.System.ArgumentException- path is a zero-length string, contains only white space, or contains one or more invalid characters.com.aspose.ms.System.IO.IOException- The directory specified by path is a file. -or- The network name is not known.
-
save
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:
output- destination stream.outputmust be writable- Throws:
com.aspose.ms.System.ArgumentException-outputis not writable, oroutputis the same stream we extract from, or it is impossible to save archive informatdue to format restrictions.
-
save
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:
output- destination stream.outputmust be writableformat- defines the tar header format. Null value will be treated as USTar when possible- Throws:
com.aspose.ms.System.ArgumentException-outputis not writable, oroutputis the same stream we extract from, or it is impossible to save archive informatdue to format restrictions.
-
save
public final void save(String destinationFileName)
Saves archive to the destination file provided.
try (TarArchive archive = new TarArchive()) { archive.createEntry("entry1", "data.bin"); archive.save("myarchive.tar"); }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 a temporary file
- Parameters:
destinationFileName- the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten.- Throws:
com.aspose.ms.System.ArgumentException-destinationFileNameis a zero-length string, contains only white space, or contains one or more invalid characters.com.aspose.ms.System.ArgumentNullException-destinationFileNameis null.com.aspose.ms.System.IO.PathTooLongException- The specifieddestinationFileName, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.com.aspose.ms.System.IO.DirectoryNotFoundException- The specifieddestinationFileNameis invalid, (for example, it is on an unmapped drive).com.aspose.ms.System.IO.IOException- An I/O error occurred while opening the file.com.aspose.ms.System.NotSupportedException-destinationFileNameis in an invalid format.
-
save
public final void save(String destinationFileName, TarFormat format)
Saves archive to the destination file provided.
try (TarArchive archive = new TarArchive()) { archive.createEntry("entry1", "data.bin"); archive.save("myarchive.tar"); }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 a temporary file
- Parameters:
destinationFileName- the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten.format- defines the tar header format. Null value will be treated as USTar when possible- Throws:
com.aspose.ms.System.ArgumentException-destinationFileNameis a zero-length string, contains only white space, or contains one or more invalid characters.com.aspose.ms.System.ArgumentNullException-destinationFileNameis null.com.aspose.ms.System.IO.PathTooLongException- The specifieddestinationFileName, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.com.aspose.ms.System.IO.DirectoryNotFoundException- The specifieddestinationFileNameis invalid, (for example, it is on an unmapped drive).com.aspose.ms.System.IO.IOException- An I/O error occurred while opening the file.com.aspose.ms.System.NotSupportedException-destinationFileNameis in an invalid format.
-
saveGzipped
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:
output- destination stream.outputmust be writable- Throws:
com.aspose.ms.System.ArgumentNullException-outputis null.com.aspose.ms.System.ArgumentException-outputis not writable.
-
saveGzipped
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:
output- destination stream.outputmust be writableformat- defines the tar header format. Null value will be treated as USTar when possible- Throws:
com.aspose.ms.System.ArgumentNullException-outputis null.com.aspose.ms.System.ArgumentException-outputis not writable.
-
saveGzipped
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:
path- the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten
-
saveGzipped
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:
path- the path of the archive to be created. If the specified file name points to an existing file, it will be overwrittenformat- defines the tar header format. Null value will be treated as USTar when possible
-
saveZstandard
public final void saveZstandard(OutputStream output)
Saves archive to the stream with Zstandard compression.
try (FileOutputStream result = new FileOutputStream("result.tar.zst")) { try (FileInputStream source = new FileInputStream("data.bin")) { try (TarArchive archive = new TarArchive()) { archive.createEntry("entry.bin", source); archive.saveZstandard(result); } } } catch (IOException ex) { }- Parameters:
output- destination stream.outputmust be writable- Throws:
com.aspose.ms.System.ArgumentNullException-outputis null.com.aspose.ms.System.ArgumentException-outputis not writable.
-
saveZstandard
public final void saveZstandard(OutputStream output, TarFormat format)
Saves archive to the stream with Zstandard compression.
try (FileOutputStream result = new FileOutputStream("result.tar.zst")) { try (FileInputStream source = new FileInputStream("data.bin")) { try (TarArchive archive = new TarArchive()) { archive.createEntry("entry.bin", source); archive.saveZstandard(result); } } } catch (IOException ex) { }- Parameters:
output- destination stream.outputmust be writableformat- defines the tar header format. Null value will be treated as USTar when possible- Throws:
com.aspose.ms.System.ArgumentNullException-outputis null.com.aspose.ms.System.ArgumentException-outputis not writable.
-
saveZstandard
public final void saveZstandard(String path)
Saves archive to the file by path with Zstandard compression.
try (FileInputStream source = new FileInputStream("data.bin")) { try (TarArchive archive = new TarArchive()) { archive.createEntry("entry.bin", source); archive.saveZstandard("result.tar.zst"); } } catch (IOException ex) { }- Parameters:
path- the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten
-
saveZstandard
public final void saveZstandard(String path, TarFormat format)
Saves archive to the file by path with Zstandard compression.
try (FileInputStream source = new FileInputStream("data.bin")) { try (TarArchive archive = new TarArchive()) { archive.createEntry("entry.bin", source); archive.saveZstandard("result.tar.zst"); } } catch (IOException ex) { }- Parameters:
path- the path of the archive to be created. If the specified file name points to an existing file, it will be overwrittenformat- defines the tar header format. Null value will be treated as USTar when possible
-
saveLzipped
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:
output- destination stream.outputmust be writable- Throws:
com.aspose.ms.System.ArgumentNullException-outputis null.com.aspose.ms.System.ArgumentException-outputis not writable.
-
saveLzipped
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:
output- destination stream.outputmust be writableformat- defines the tar header format. Null value will be treated as USTar when possible- Throws:
com.aspose.ms.System.ArgumentNullException-outputis null.com.aspose.ms.System.ArgumentException-outputis not writable.
-
saveLzipped
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:
path- the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten
-
saveLzipped
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:
path- the path of the archive to be created. If the specified file name points to an existing file, it will be overwrittenformat- defines the tar header format. Null value will be treated as USTar when possible
-
saveLZMACompressed
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:
output- destination stream.outputmust be writable- Throws:
com.aspose.ms.System.ArgumentNullException-outputis null.com.aspose.ms.System.ArgumentException-outputis not writable.
-
saveLZMACompressed
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:
output- destination stream.outputmust be writableformat- defines the tar header format. Null value will be treated as USTar when possible- Throws:
com.aspose.ms.System.ArgumentNullException-outputis null.com.aspose.ms.System.ArgumentException-outputis not writable.
-
saveLZMACompressed
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:
path- the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten
-
saveLZMACompressed
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:
path- the path of the archive to be created. If the specified file name points to an existing file, it will be overwrittenformat- defines the tar header format. Null value will be treated as USTar when possible
-
saveLZ4Compressed
public final void saveLZ4Compressed(OutputStream output)
Saves archive to the stream with LZ4 compression.
try (FileOutputStream result = new FileOutputStream("result.tar.lz4")) { try (FileInputStream source = new FileInputStream("data.bin")) { try (TarArchive archive = new TarArchive()) { archive.createEntry("entry.bin", source); archive.saveLZ4Compressed(result); } } } catch (IOException ex) { }- Parameters:
output- Destination stream.- Throws:
com.aspose.ms.System.ArgumentNullException-outputis null.com.aspose.ms.System.ArgumentException-outputis not writable.
-
saveLZ4Compressed
public final void saveLZ4Compressed(OutputStream output, TarFormat format)
Saves archive to the stream with LZ4 compression.
try (FileOutputStream result = new FileOutputStream("result.tar.lz4")) { try (FileInputStream source = new FileInputStream("data.bin")) { try (TarArchive archive = new TarArchive()) { archive.createEntry("entry.bin", source); archive.saveLZ4Compressed(result); } } } catch (IOException ex) { }- Parameters:
output- Destination stream.format- Defines the tar header format. Null value will be treated as USTar when possible.- Throws:
com.aspose.ms.System.ArgumentNullException-outputis null.com.aspose.ms.System.ArgumentException-outputis not writable.
-
saveLZ4Compressed
public final void saveLZ4Compressed(String path)
Saves archive to the file by path with LZ4 compression.
try (FileInputStream source = new FileInputStream("data.bin")) { try (TarArchive archive = new TarArchive()) { archive.createEntry("entry.bin", source); archive.saveLZ4Compressed("result.tar.lz4"); } } catch (IOException ex) { }- Parameters:
path- The path of the archive to be created. If the specified file name points to an existing file, it will be overwritten.- Throws:
com.aspose.ms.System.ArgumentException-pathis a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.com.aspose.ms.System.ArgumentNullException-pathis null.com.aspose.ms.System.IO.PathTooLongException- The specifiedpath, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.com.aspose.ms.System.IO.DirectoryNotFoundException- The specifiedpathis invalid, (for example, it is on an unmapped drive).com.aspose.ms.System.NotSupportedException-pathis in an invalid format.
-
saveLZ4Compressed
public final void saveLZ4Compressed(String path, TarFormat format)
Saves archive to the file by path with LZ4 compression.
try (FileInputStream source = new FileInputStream("data.bin")) { try (TarArchive archive = new TarArchive()) { archive.createEntry("entry.bin", source); archive.saveLZ4Compressed("result.tar.lz4"); } } catch (IOException ex) { }- Parameters:
path- The path of the archive to be created. If the specified file name points to an existing file, it will be overwritten.format- Defines the tar header format. Null value will be treated as USTar when possible.- Throws:
com.aspose.ms.System.ArgumentException-pathis a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.com.aspose.ms.System.ArgumentNullException-pathis null.com.aspose.ms.System.IO.PathTooLongException- The specifiedpath, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.com.aspose.ms.System.IO.DirectoryNotFoundException- The specifiedpathis invalid, (for example, it is on an unmapped drive).com.aspose.ms.System.NotSupportedException-pathis in an invalid format.
-
saveXzCompressed
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:
output- destination stream.outputThe stream must be writable- Throws:
com.aspose.ms.System.ArgumentNullException-outputis null.com.aspose.ms.System.ArgumentException-outputis not writable.
-
saveXzCompressed
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:
output- destination stream.outputThe stream must be writableformat- defines the tar header format. Null value will be treated as USTar when possible- Throws:
com.aspose.ms.System.ArgumentNullException-outputis null.com.aspose.ms.System.ArgumentException-outputis not writable.
-
saveXzCompressed
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:
output- destination stream.outputThe stream must be writableformat- defines the tar header format. Null value will be treated as USTar when possiblesettings- set of setting particular xz archive: dictionary size, block size, check type- Throws:
com.aspose.ms.System.ArgumentNullException-outputis null.com.aspose.ms.System.ArgumentException-outputis not writable.
-
saveXzCompressed
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:
path- the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten
-
saveXzCompressed
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:
path- the path of the archive to be created. If the specified file name points to an existing file, it will be overwrittenformat- defines tar header format. Null value will be treated as USTar when possible
-
saveXzCompressed
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:
path- the path of the archive to be created. If the specified file name points to an existing file, it will be overwrittenformat- defines the tar header format. Null value will be treated as USTar when possiblesettings- set of setting particular xz archive: dictionary size, block size, check type
-
saveZCompressed
public final void saveZCompressed(OutputStream output)
Saves archive to the stream with Z compression.
try (FileOutputStream result = new FileOutputStream("result.tar.Z")) { try (FileInputStream source = new FileInputStream("data.bin")) { try (TarArchive archive = new TarArchive()) { archive.createEntry("entry.bin", source); archive.saveZCompressed(result); } } } catch (IOException ex) { }- Parameters:
output- the destination stream- Throws:
com.aspose.ms.System.ArgumentNullException-outputis null.com.aspose.ms.System.ArgumentException-outputis not writable.
-
saveZCompressed
public final void saveZCompressed(OutputStream output, TarFormat format)
Saves archive to the stream with Z compression.
try (FileOutputStream result = new FileOutputStream("result.tar.Z")) { try (FileInputStream source = new FileInputStream("data.bin")) { try (TarArchive archive = new TarArchive()) { archive.createEntry("entry.bin", source); archive.saveZCompressed(result); } } } catch (IOException ex) { }- Parameters:
output- the destination streamformat- defines the tar header format. Null value will be treated as USTar when possible- Throws:
com.aspose.ms.System.ArgumentNullException-outputis null.com.aspose.ms.System.ArgumentException-outputis not writable.
-
saveZCompressed
public final void saveZCompressed(String path)
Saves archive to the file by path with Z compression.
try (FileInputStream source = new FileInputStream("data.bin")) { try (TarArchive archive = new TarArchive()) { archive.createEntry("entry.bin", source); archive.saveZCompressed("result.tar.Z"); } } catch (IOException ex) { }- Parameters:
path- the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten
-
saveZCompressed
public final void saveZCompressed(String path, TarFormat format)
Saves archive to the file by path with Z compression.
try (FileInputStream source = new FileInputStream("data.bin")) { try (TarArchive archive = new TarArchive()) { archive.createEntry("entry.bin", source); archive.saveZCompressed("result.tar.Z"); } } catch (IOException ex) { }- Parameters:
path- the path of the archive to be created. If the specified file name points to an existing file, it will be overwrittenformat- defines the tar header format. Null value will be treated as USTar when possible
-
fromGZip
public static TarArchive fromGZip(InputStream source)
Extracts supplied gzip archive and composes
TarArchivefrom extracted data.Important: gzip archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.
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
- Parameters:
source- the source of the archive.- Returns:
- an instance of
TarArchive
-
fromGZip
public static TarArchive fromGZip(String path)
Extracts supplied gzip archive and composes
TarArchivefrom extracted data.Important: gzip archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.
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
- Parameters:
path- the path to the archive file.- Returns:
- an instance of
TarArchive
-
fromZstandard
public static TarArchive fromZstandard(InputStream source)
Extracts supplied Zstandard archive and composes
TarArchivefrom extracted data.Important: Zstandard archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.
- Parameters:
source- the source of the archive- Returns:
- an instance of
TarArchive
-
fromZstandard
public static TarArchive fromZstandard(String path)
Extracts supplied Zstandard archive and composes
TarArchivefrom extracted data.Important: Zstandard archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.
- Parameters:
path- the path to the archive file- Returns:
- an instance of
TarArchive
-
fromLZip
public static TarArchive fromLZip(InputStream source)
Extracts supplied lzip archive and composes
TarArchivefrom extracted data.Important: lzip archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.
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
- Parameters:
source- the source of the archive.- Returns:
- an instance of
TarArchive
-
fromLZip
public static TarArchive fromLZip(String path)
Extracts supplied lzip archive and composes
TarArchivefrom extracted data.Important: lzip archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.
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
- Parameters:
path- the path to the archive file.- Returns:
- an instance of
TarArchive
-
fromLZMA
public static TarArchive fromLZMA(InputStream source)
Extracts supplied LZMA archive and composes
TarArchivefrom 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:
source- the source of the archive- Returns:
- an instance of
TarArchive
-
fromLZ4
public static TarArchive fromLZ4(String path)
Extracts supplied LZ4 archive and composes
TarArchivefrom extracted data.Important: LZ4 archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.
- Parameters:
path- The path to the archive file.LZ4 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:
- An instance of
TarArchive - Throws:
com.aspose.ms.System.ArgumentNullException-pathis null.com.aspose.ms.System.SecurityException- The caller does not have the required permission to accesscom.aspose.ms.System.ArgumentException- Thepathis empty, contains only white spaces, or contains invalid characters.com.aspose.ms.System.IO.PathTooLongException- The specifiedpath, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.com.aspose.ms.System.NotSupportedException- File atpathis in an invalid format.com.aspose.ms.System.IO.DirectoryNotFoundException- The specified path is invalid, such as being on an unmapped drive.com.aspose.ms.System.IO.FileNotFoundException- The file is not found.com.aspose.ms.System.IO.EndOfStreamException- The file is too short.com.aspose.ms.System.IO.InvalidDataException- The file has the wrong signature.
-
fromLZ4
public static TarArchive fromLZ4(InputStream source)
Extracts supplied LZ4 archive and composes
TarArchivefrom extracted data.Important: LZ4 archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.
- Parameters:
source- The source of the archive.LZ4 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:
- An instance of
TarArchive - Throws:
com.aspose.ms.System.ArgumentException- Cannot read fromsourcecom.aspose.ms.System.ArgumentNullException-sourceis null.com.aspose.ms.System.IO.EndOfStreamException-sourceis too short.com.aspose.ms.System.IO.InvalidDataException- Thesourcehas the wrong signature.
-
fromLZMA
public static TarArchive fromLZMA(String path)
Extracts supplied LZMA archive and composes
TarArchivefrom 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:
path- the path to the archive file- Returns:
- an instance of
TarArchive
-
fromXz
public static TarArchive fromXz(InputStream source)
Extracts supplied xz format archive and composes
TarArchivefrom 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:
source- the source of the archive- Returns:
- an instance of
TarArchive
-
fromXz
public static TarArchive fromXz(String path)
Extracts supplied xz format archive and composes
TarArchivefrom 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:
path- the path to the archive file- Returns:
- an instance of
TarArchive
-
fromZ
public static TarArchive fromZ(InputStream source)
Extracts supplied Z format archive and composes
TarArchivefrom extracted data.Important: Z archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.
- Parameters:
source- the source of the archive- Returns:
- an instance of
TarArchive
-
fromZ
public static TarArchive fromZ(String path)
Extracts supplied Z format archive and composes
TarArchivefrom extracted data.Important: Z archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.
- Parameters:
path- the path to the archive file- Returns:
- an instance of
TarArchive
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceIArchive
-
-