TarEntry
Inheritance: java.lang.Object
All Implemented Interfaces: com.aspose.zip.IArchiveFileEntry
public class TarEntry implements IArchiveFileEntry
Represents single file within tar archive.
Methods
| Method | Description |
|---|---|
| extract(OutputStream destination) | Extracts the entry to the stream provided. |
| extract(String path) | Extracts the entry to the filesystem by the path provided. |
| getLength() | Gets the length of the entry in bytes. |
| getModificationTime() | Gets the modification time of the file or directory. |
| getName() | Gets the name of the entry within the archive. |
| getUncompressedSize() | Gets the size of an original file. |
| isDirectory() | Gets a value indicating whether the entry represents a directory. |
| open() | Opens the entry for extraction and provides a stream with entry content. |
| setName(String value) | Sets the name of the entry within the archive. |
extract(OutputStream destination)
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);
}
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| destination | java.io.OutputStream | Destination stream. Must be writable. |
### extract(String path) {#extract-java.lang.String-}
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");
}
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| path | java.lang.String | the path to destination file. If the file already exists, it will be overwritten |
**Returns:**
java.io.File - the file info of the extracted file
### getLength() {#getLength--}
```
public final Long getLength()
```
Gets the length of the entry in bytes.
**Returns:**
java.lang.Long - the length of the entry in bytes
### getModificationTime() {#getModificationTime--}
```
public final Date getModificationTime()
```
Gets the modification time of the file or directory.
**Returns:**
java.util.Date - the modification time of the file or directory.
### getName() {#getName--}
```
public final String getName()
```
Gets the name of the entry within the archive.
**Returns:**
java.lang.String - the name of the entry within the archive
### getUncompressedSize() {#getUncompressedSize--}
```
public final long getUncompressedSize()
```
Gets the size of an original file.
Has the same value as `Length`([getLength](../../com.aspose.zip/tarentry\#getLength--))
**Returns:**
long - the size of an original file.
### isDirectory() {#isDirectory--}
```
public final boolean isDirectory()
```
Gets a value indicating whether the entry represents a directory.
**Returns:**
boolean - a value indicating whether the entry represents a directory
### open() {#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:**
java.io.InputStream - the stream that represents the contents of the entry
### setName(String value) {#setName-java.lang.String-}
public final void setName(String value)
Sets the name of the entry within the archive.
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| value | java.lang.String | the name of the entry within the archive |