Lz4Archive
Inheritance: java.lang.Object
All Implemented Interfaces: com.aspose.zip.IArchive, com.aspose.zip.IArchiveFileEntry, java.lang.AutoCloseable
public class Lz4Archive implements IArchive, IArchiveFileEntry, AutoCloseable
This class represents LZ4 archive file. Use it to extract or compose LZ4 archives.
Constructors
Constructor | Description |
---|---|
Lz4Archive(InputStream sourceStream) | Initializes a new instance of the Lz4Archive class prepared for decompressing. |
Lz4Archive(InputStream sourceStream, Lz4LoadOptions loadOptions) | Initializes a new instance of the Lz4Archive class prepared for decompressing. |
Lz4Archive(String path) | Initializes a new instance of the Lz4Archive class. |
Lz4Archive(String path, Lz4LoadOptions loadOptions) | Initializes a new instance of the Lz4Archive class. |
Lz4Archive() | Initializes a new instance of the Lz4Archive class prepared for compressing. |
Lz4Archive(Lz4ArchiveSetting settings) | Initializes a new instance of the Lz4Archive class prepared for compressing. |
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 archive. |
getFormat() | Gets the archive format. |
getLength() | Gets length. |
getName() | Gets the original name. |
open() | Opens the archive for extraction and provides a stream with archive content. |
save(File destination) | Saves lz4 archive to destination file provided. |
save(OutputStream output) | Saves lz4 archive to the stream provided. |
save(String destinationFileName) | Saves archive to the destination file provided. |
setSource(TarArchive tarArchive) | Sets the content to be compressed within the archive. |
setSource(TarArchive tarArchive, TarFormat format) | Sets the content to be compressed within the archive. |
setSource(File fileInfo) | 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. |
Lz4Archive(InputStream sourceStream)
public Lz4Archive(InputStream sourceStream)
Initializes a new instance of the Lz4Archive class prepared for decompressing.
Open an archive from a stream and extract it to a MemoryStream
ByteArrayOutputStream ms = new ByteArrayOutputStream();
try (Lz4Archive archive = new Lz4Archive(new FileInputStream("archive.lz4"))) {
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) {
}
This constructor does not decompress. See open() method for decompressing.
Parameters:
Parameter | Type | Description |
---|---|---|
sourceStream | java.io.InputStream | the source of the archive |
Lz4Archive(InputStream sourceStream, Lz4LoadOptions loadOptions)
public Lz4Archive(InputStream sourceStream, Lz4LoadOptions loadOptions)
Initializes a new instance of the Lz4Archive class prepared for decompressing.
Open an archive from a stream and extract it to a MemoryStream
ByteArrayOutputStream ms = new ByteArrayOutputStream();
try (Lz4Archive archive = new Lz4Archive(new FileInputStream("archive.lz4"))) {
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) {
}
This constructor does not decompress. See open() method for decompressing.
Parameters:
Parameter | Type | Description |
---|---|---|
sourceStream | java.io.InputStream | the source of the archive |
loadOptions | Lz4LoadOptions | The options to load archive with. |
Lz4Archive(String path)
public Lz4Archive(String path)
Initializes a new instance of the Lz4Archive class.
Open an archive from file by path and extract it to a MemoryStream
ByteArrayOutputStream ms = new ByteArrayOutputStream();
try (Lz4Archive archive = new Lz4Archive("archive.lz4")) {
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) {
}
This constructor does not decompress. See open() method for decompressing.
Parameters:
Parameter | Type | Description |
---|---|---|
path | java.lang.String | the path to the archive file |
Lz4Archive(String path, Lz4LoadOptions loadOptions)
public Lz4Archive(String path, Lz4LoadOptions loadOptions)
Initializes a new instance of the Lz4Archive class.
Open an archive from file by path and extract it to a MemoryStream
ByteArrayOutputStream ms = new ByteArrayOutputStream();
try (Lz4Archive archive = new Lz4Archive("archive.lz4")) {
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) {
}
This constructor does not decompress. See open() method for decompressing.
Parameters:
Parameter | Type | Description |
---|---|---|
path | java.lang.String | the path to the archive file |
loadOptions | Lz4LoadOptions | The options to load archive with. |
Lz4Archive()
public Lz4Archive()
Initializes a new instance of the Lz4Archive class prepared for compressing.
Lz4Archive(Lz4ArchiveSetting settings)
public Lz4Archive(Lz4ArchiveSetting settings)
Initializes a new instance of the Lz4Archive class prepared for compressing.
Parameters:
Parameter | Type | Description |
---|---|---|
settings | Lz4ArchiveSetting | The setting of the composed archive. |
close()
public void close()
extract(OutputStream destination)
public final void extract(OutputStream destination)
Extracts the archive to the stream provided.
OutputStream httpResponseStream = null;
try (Lz4Archive archive = new Lz4Archive("archive.lz4")) {
archive.extract(httpResponseStream);
}
Parameters:
Parameter | Type | Description |
---|---|---|
destination | java.io.OutputStream | destination stream |
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 - info of an 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 archive.
Returns: java.lang.Iterable<com.aspose.zip.IArchiveFileEntry> - entries of IArchiveFileEntry type constituting the archive
getFormat()
public final ArchiveFormat getFormat()
Gets the archive format.
Returns: ArchiveFormat - the archive format
getLength()
public final Long getLength()
Gets length.
Returns: java.lang.Long - length
getName()
public final String getName()
Gets the original name.
Returns: java.lang.String - the original name
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 (Lz4Archive archive = new Lz4Archive("archive.lz4")) {
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) {
}
Read from the stream to get the original content of a 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 lz4 archive to destination file provided.
try (Lz4Archive archive = new Lz4Archive()) {
archive.setSource(new File("data.bin"));
archive.save(new File("archive.lz4"));
}
Parameters:
Parameter | Type | Description |
---|---|---|
destination | java.io.File | File, which will be opened as destination stream. |
save(OutputStream output)
public final void save(OutputStream output)
Saves lz4 archive to the stream provided.
try (FileOutputStream lz4File = new FileOutputStream("archive.lz4")) {
try (Lz4Archive archive = new Lz4Archive()) {
archive.setSource("data.bin");
archive.save(lz4File);
}
} catch (IOException ex) {
}
Parameters:
Parameter | Type | Description |
---|---|---|
output | java.io.OutputStream | Destination stream. |
save(String destinationFileName)
public final void save(String destinationFileName)
Saves archive to the destination file provided.
try (Lz4Archive archive = new Lz4Archive()) {
archive.setSource("data.bin");
archive.save("archive.lz4");
}
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. |
setSource(TarArchive tarArchive)
public final void setSource(TarArchive tarArchive)
Sets the content to be compressed within the archive.
try (TarArchive tarArchive = new TarArchive()) {
tarArchive.createEntry("first.bin", "data1.bin");
tarArchive.createEntry("second.bin", "data2.bin");
try (Lz4Archive lz4Archive = new Lz4Archive()) {
lz4Archive.setSource(tarArchive);
lz4Archive.save("archive.tar.lz4");
}
}
Use this method to compose joint tar.lz4 archive.
Parameters:
Parameter | Type | Description |
---|---|---|
tarArchive | TarArchive | Tar archive to be compressed. |
setSource(TarArchive tarArchive, TarFormat format)
public final void setSource(TarArchive tarArchive, TarFormat format)
Sets the content to be compressed within the archive.
try (TarArchive tarArchive = new TarArchive()) {
tarArchive.createEntry("first.bin", "data1.bin");
tarArchive.createEntry("second.bin", "data2.bin");
try (Lz4Archive lz4Archive = new Lz4Archive()) {
lz4Archive.setSource(tarArchive);
lz4Archive.save("archive.tar.lz4");
}
}
Use this method to compose joint tar.lz4 archive.
Parameters:
Parameter | Type | Description |
---|---|---|
tarArchive | TarArchive | Tar archive to be compressed. |
format | TarFormat | Defines tar header format. |
setSource(File fileInfo)
public final void setSource(File fileInfo)
Sets the content to be compressed within the archive.
Open an archive from a stream and extract it to a MemoryStream
try (Lz4Archive archive = new Lz4Archive()) {
archive.setSource(new File("data.bin"));
archive.save("archive.lz4");
}
Parameters:
Parameter | Type | Description |
---|---|---|
fileInfo | 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 (Lz4Archive archive = new Lz4Archive()) {
archive.setSource(new ByteArrayInputStream(new byte[] {
0x00,
(byte) 0xFF
}));
archive.save("archive.lz4");
}
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.
Open an archive from file by path and extract it to a MemoryStream
try (Lz4Archive archive = new Lz4Archive()) {
archive.setSource("data.bin");
archive.save("archive.lz4");
}
Parameters:
Parameter | Type | Description |
---|---|---|
path | java.lang.String | Path to file to be compressed. |