ZstandardArchive
Inheritance: java.lang.Object
All Implemented Interfaces: com.aspose.zip.IArchiveFileEntry, com.aspose.zip.IArchive, java.lang.AutoCloseable
public class ZstandardArchive implements IArchiveFileEntry, IArchive, AutoCloseable
This class represents Zstandard archive file. Use it to compose Zstandard archives.
Constructors
Constructor | Description |
---|---|
ZstandardArchive() | Initializes a new instance of the ZstandardArchive class prepared for compressing. |
ZstandardArchive(InputStream sourceStream) | Initializes a new instance of the ZstandardArchive class prepared for decompressing. |
ZstandardArchive(InputStream sourceStream, ZstandardLoadOptions options) | Initializes a new instance of the ZstandardArchive class prepared for decompressing. |
ZstandardArchive(String path) | Initializes a new instance of the ZstandardArchive class. |
ZstandardArchive(String path, ZstandardLoadOptions options) | Initializes a new instance of the ZstandardArchive class. |
Methods
Method | Description |
---|---|
close() | {@inheritDoc} |
extract(OutputStream destination) | Extracts the archive to the stream provided. |
extract(String path) | Extracts the archive to the file by path. |
extractToDirectory(String destinationDirectory) | Extracts content of the archive to the directory provided. |
getFileEntries() | Gets entries of IArchiveFileEntry type constituting the zstandard archive. |
getLength() | Gets the length of the entry in bytes. |
getName() | Gets the name of the entry within archive. |
open() | Opens the archive for extraction and provides a stream with archive content. |
save(File destination) | Saves archive to destination file provided. |
save(File destination, ZstandardSaveOptions settings) | Saves archive to destination file provided. |
save(OutputStream outputStream) | Saves archive to the stream provided. |
save(OutputStream outputStream, ZstandardSaveOptions settings) | Saves archive to the stream provided. |
save(String destinationFileName) | Saves archive to destination file provided. |
save(String destinationFileName, ZstandardSaveOptions settings) | Saves archive to destination file provided. |
setSource(File file) | Sets the content to be compressed within the archive. |
setSource(InputStream source) | Sets the content to be compressed within the archive. |
setSource(String path) | Sets the content to be compressed within the archive. |
ZstandardArchive()
public ZstandardArchive()
Initializes a new instance of the ZstandardArchive class prepared for compressing.
The following example shows how to compress a file.
try (ZstandardArchive archive = new ZstandardArchive()) {
archive.setSource("data.bin");
archive.save("archive.zst");
}
ZstandardArchive(InputStream sourceStream)
public ZstandardArchive(InputStream sourceStream)
Initializes a new instance of the ZstandardArchive class prepared for decompressing.
Open an archive from a stream and extract it to a ByteArrayOutputStream
ByteArrayOutputStream ms = new ByteArrayOutputStream();
try (ZstandardArchive archive = new ZstandardArchive(new FileInputStream("archive.zst"))) {
InputStream decompressed = archive.open();
byte[] b = new byte[8192];
int bytesRead;
while (0 < (bytesRead = decompressed.read(b, 0, b.length))) {
ms.write(b, 0, bytesRead);
}
} catch (IOException ex) {
System.out.println(ex);
}
This constructor does not decompress. See open() method for decompressing.
Parameters:
Parameter | Type | Description |
---|---|---|
sourceStream | java.io.InputStream | the source of the archive |
ZstandardArchive(InputStream sourceStream, ZstandardLoadOptions options)
public ZstandardArchive(InputStream sourceStream, ZstandardLoadOptions options)
Initializes a new instance of the ZstandardArchive class prepared for decompressing.
Open an archive from a stream and extract it to a ByteArrayOutputStream
ByteArrayOutputStream ms = new ByteArrayOutputStream();
try (ZstandardArchive archive = new ZstandardArchive(new FileInputStream("archive.zst"))) {
InputStream decompressed = archive.open();
byte[] b = new byte[8192];
int bytesRead;
while (0 < (bytesRead = decompressed.read(b, 0, b.length))) {
ms.write(b, 0, bytesRead);
}
} catch (IOException ex) {
System.out.println(ex);
}
This constructor does not decompress. See open() method for decompressing.
Parameters:
Parameter | Type | Description |
---|---|---|
sourceStream | java.io.InputStream | the source of the archive |
options | ZstandardLoadOptions | the options to load archive with |
ZstandardArchive(String path)
public ZstandardArchive(String path)
Initializes a new instance of the ZstandardArchive class.
Open an archive from file by path and extract it to a ByteArrayOutputStream
ByteArrayOutputStream ms = new ByteArrayOutputStream();
try (ZstandardArchive archive = new ZstandardArchive("archive.zst")) {
InputStream decompressed = archive.open();
byte[] b = new byte[8192];
int bytesRead;
while (0 < (bytesRead = decompressed.read(b, 0, b.length))) {
ms.write(b, 0, bytesRead);
}
} catch (IOException ex) {
System.out.println(ex);
}
This constructor does not decompress. See open() method for decompressing.
Parameters:
Parameter | Type | Description |
---|---|---|
path | java.lang.String | the path to the archive file |
ZstandardArchive(String path, ZstandardLoadOptions options)
public ZstandardArchive(String path, ZstandardLoadOptions options)
Initializes a new instance of the ZstandardArchive class.
Open an archive from file by path and extract it to a ByteArrayOutputStream
ByteArrayOutputStream ms = new ByteArrayOutputStream();
try (ZstandardArchive archive = new ZstandardArchive("archive.zst")) {
InputStream decompressed = archive.open();
byte[] b = new byte[8192];
int bytesRead;
while (0 < (bytesRead = decompressed.read(b, 0, b.length))) {
ms.write(b, 0, bytesRead);
}
} catch (IOException ex) {
System.out.println(ex);
}
This constructor does not decompress. See open() method for decompressing.
Parameters:
Parameter | Type | Description |
---|---|---|
path | java.lang.String | the path to the archive file |
options | ZstandardLoadOptions | the options to load archive with |
close()
public void close()
extract(OutputStream destination)
public final void extract(OutputStream destination)
Extracts the archive to the stream provided.
try (ZstandardArchive archive = new ZstandardArchive("archive.zst")) {
archive.extract(httpResponseStream);
}
Parameters:
Parameter | Type | Description |
---|---|---|
destination | java.io.OutputStream | destination stream. Must be writable |
extract(String path)
public final File extract(String path)
Extracts the archive to the file by path.
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
extractToDirectory(String destinationDirectory)
public final void extractToDirectory(String destinationDirectory)
Extracts content of the archive to the directory provided.
Parameters:
Parameter | Type | Description |
---|---|---|
destinationDirectory | java.lang.String | the path to the directory to place the extracted files in. |
If the directory does not exist, it will be created |
getFileEntries()
public final Iterable<IArchiveFileEntry> getFileEntries()
Gets entries of IArchiveFileEntry type constituting the zstandard archive.
Returns: java.lang.Iterable<com.aspose.zip.IArchiveFileEntry> - entries of IArchiveFileEntry type constituting the zstandard archive
getLength()
public final Long getLength()
Gets the length of the entry in bytes.
Returns: java.lang.Long - the length of the entry in bytes
getName()
public final String getName()
Gets the name of the entry within archive.
Returns: java.lang.String - the name of the entry within archive
open()
public final InputStream open()
Opens the archive for extraction and provides a stream with archive content.
Extracts the archive and copies extracted content to file stream.
try (ZstandardArchive archive = new ZstandardArchive("archive.zst")) {
try (FileOutputStream extracted = new FileOutputStream("data.bin")) {
InputStream unpacked = archive.open();
byte[] b = new byte[8192];
int bytesRead;
while (0 < (bytesRead = unpacked.read(b, 0, b.length))) {
extracted.write(b, 0, bytesRead);
}
}
} catch (IOException ex) {
System.out.println(ex);
}
Read from the stream to get original content of file. See examples section.
Returns: java.io.InputStream - the stream that represents the contents of the archive
save(File destination)
public final void save(File destination)
Saves archive to destination file provided.
try (ZstandardArchive archive = new ZstandardArchive()) {
archive.setSource(new File("data.bin"));
archive.save(new File("archive.zst"));
}
Parameters:
Parameter | Type | Description |
---|---|---|
destination | java.io.File | the file which will be opened as destination stream |
save(File destination, ZstandardSaveOptions settings)
public final void save(File destination, ZstandardSaveOptions settings)
Saves archive to destination file provided.
try (ZstandardArchive archive = new ZstandardArchive()) {
archive.setSource(new File("data.bin"));
archive.save(new File("archive.zst"));
}
Parameters:
Parameter | Type | Description |
---|---|---|
destination | java.io.File | the file which will be opened as destination stream |
settings | ZstandardSaveOptions | the settings for archive composition |
save(OutputStream outputStream)
public final void save(OutputStream outputStream)
Saves archive to the stream provided.
Writes compressed data to http response stream.
try (ZstandardArchive archive = new ZstandardArchive()) {
archive.setSource(new File("data.bin"));
archive.save(outputStream);
}
Parameters:
Parameter | Type | Description |
---|---|---|
outputStream | java.io.OutputStream | the destination stream |
save(OutputStream outputStream, ZstandardSaveOptions settings)
public final void save(OutputStream outputStream, ZstandardSaveOptions settings)
Saves archive to the stream provided.
Writes compressed data to http response stream.
try (ZstandardArchive archive = new ZstandardArchive()) {
archive.setSource(new File("data.bin"));
archive.save(outputStream);
}
Parameters:
Parameter | Type | Description |
---|---|---|
outputStream | java.io.OutputStream | the destination stream |
settings | ZstandardSaveOptions | the settings for archive composition |
save(String destinationFileName)
public final void save(String destinationFileName)
Saves archive to destination file provided.
try (ZstandardArchive archive = new ZstandardArchive()) {
archive.setSource(new File("data.bin"));
archive.save("result.zst");
}
Parameters:
Parameter | Type | Description |
---|---|---|
destinationFileName | java.lang.String | the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten |
save(String destinationFileName, ZstandardSaveOptions settings)
public final void save(String destinationFileName, ZstandardSaveOptions settings)
Saves archive to destination file provided.
try (ZstandardArchive archive = new ZstandardArchive()) {
archive.setSource(new File("data.bin"));
archive.save("result.zst");
}
Parameters:
Parameter | Type | Description |
---|---|---|
destinationFileName | java.lang.String | the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten |
settings | ZstandardSaveOptions | the settings for archive composition |
setSource(File file)
public final void setSource(File file)
Sets the content to be compressed within the archive.
try (ZstandardArchive archive = new ZstandardArchive()) {
archive.setSource(new File("data.bin"));
archive.save("archive.zst");
}
Parameters:
Parameter | Type | Description |
---|---|---|
file | java.io.File | the reference to a file to be compressed |
setSource(InputStream source)
public final void setSource(InputStream source)
Sets the content to be compressed within the archive.
try (ZstandardArchive archive = new ZstandardArchive()) {
archive.setSource(new ByteArrayInputStream(new byte[] {
0x00,
(byte) 0xFF
}));
archive.save("archive.zst");
}
Parameters:
Parameter | Type | Description |
---|---|---|
source | java.io.InputStream | the input stream for the archive |
setSource(String path)
public final void setSource(String path)
Sets the content to be compressed within the archive.
try (ZstandardArchive archive = new ZstandardArchive()) {
archive.setSource("data.bin");
archive.save("archive.zst");
}
Parameters:
Parameter | Type | Description |
---|---|---|
path | java.lang.String | path to file to be compressed |