Package com.aspose.zip
Class TarEntry
- java.lang.Object
-
- com.aspose.zip.TarEntry
-
- All Implemented Interfaces:
IArchiveFileEntry
public class TarEntry extends Object implements IArchiveFileEntry
Represents single file within tar archive.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidextract(OutputStream destination)Extracts the entry to the stream provided.Fileextract(String path)Extracts the entry to the filesystem by the path provided.LonggetLength()Gets the length of the entry in bytes.DategetModificationTime()Gets the modification time of the file or directory.StringgetName()Gets the name of the entry within the archive.longgetUncompressedSize()Gets the size of an original file.booleanisDirectory()Gets a value indicating whether the entry represents a directory.InputStreamopen()Opens the entry for extraction and provides a stream with entry content.voidsetName(String value)Sets the name of the entry within the archive.
-
-
-
Method Detail
-
getName
public final String getName()
Gets the name of the entry within the archive.
- Specified by:
getNamein interfaceIArchiveFileEntry- Returns:
- the name of the entry within the archive
-
setName
public final void setName(String value)
Sets the name of the entry within the archive.
- Parameters:
value- the name of the entry within the archive
-
getLength
public final Long getLength()
Gets the length of the entry in bytes.
- Specified by:
getLengthin interfaceIArchiveFileEntry- Returns:
- the length of the entry in bytes
-
getUncompressedSize
public final long getUncompressedSize()
Gets the size of an original file.
Has the same value as
Length(getLength())- Returns:
- the size of an original file.
-
isDirectory
public final boolean isDirectory()
Gets a value indicating whether the entry represents a directory.
- Returns:
- a value indicating whether the entry represents a directory
-
getModificationTime
public final Date getModificationTime()
Gets the modification time of the file or directory.
- Returns:
- the modification time of the file or directory.
-
open
public final InputStream open()
Opens the entry for extraction and provides a stream with entry content.
Usage:InputStream decompressed = entry.open(); byte[] buffer = new byte[8192]; int bytesRead; while (0 < (bytesRead = decompressed.read(buffer, 0, buffer.length))) { fileStream.write(buffer, 0, bytesRead); }Read from the stream to get the original content of the file. See examples section.
- Returns:
- the stream that represents the contents of the entry
-
extract
public final File extract(String path)
Extracts the entry to the filesystem by the path provided.
try (TarArchive archive = new TarArchive("archive.tar")) { archive.getEntries().get_Item(0).extract("data.bin"); }- Specified by:
extractin interfaceIArchiveFileEntry- Parameters:
path- the path to destination file. If the file already exists, it will be overwritten- Returns:
- the file info of the extracted 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.
-
extract
public final void extract(OutputStream destination)
Extracts the entry to the stream provided.
Extract an entry of tar archive.
try (TarArchive archive = new TarArchive("archive.tar")) { archive.getEntries().get_Item(0).extract(httpResponseStream); }- Specified by:
extractin interfaceIArchiveFileEntry- Parameters:
destination- Destination stream. Must be writable.- Throws:
com.aspose.ms.System.ArgumentException-destinationdoes not support writing.
-
-