SnappyArchive

Inheritance: java.lang.Object

All Implemented Interfaces: com.aspose.zip.IArchive, com.aspose.zip.IArchiveFileEntry, java.lang.AutoCloseable

public class SnappyArchive implements IArchive, IArchiveFileEntry, AutoCloseable

This class represents snappy archive file. Use it to compose or extract snappy archives.

Constructors

ConstructorDescription
SnappyArchive()Initializes a new instance of the SnappyArchive class prepared for compressing.
SnappyArchive(InputStream source)Initializes a new instance of the SnappyArchive class prepared for decompressing.
SnappyArchive(String path)Initializes a new instance of the SnappyArchive class prepared for decompressing.

Methods

MethodDescription
close(){@inheritDoc}
extract(File file)Extracts snappy archive to a file.
extract(OutputStream destination)Extracts snappy archive to a stream.
extract(String path)Extracts snappy archive to a file by path.
extractToDirectory(String destinationDirectory)Extracts content of the archive to the directory provided.
getFileEntries()Gets entries of IArchiveFileEntry type constituting the snappy archive.
getLength()Gets length.
getName()The name of original file.
save(File destination)Saves snappy archive to destination file provided.
save(OutputStream output)Saves snappy archive to the stream provided.
save(String destinationFileName)Saves snappy 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 sourcePath)Sets the content to be compressed within the archive.

SnappyArchive()

public SnappyArchive()

Initializes a new instance of the SnappyArchive class prepared for compressing.

The following example shows how to compress a file.


     try (SnappyArchive archive = new SnappyArchive()) {
         archive.setSource("data.bin");
         archive.save("archive.snappy");
     }
 

SnappyArchive(InputStream source)

public SnappyArchive(InputStream source)

Initializes a new instance of the SnappyArchive class prepared for decompressing.

This constructor does not decompress. See extract(java.io.OutputStream) method for decompressing.

Parameters:

ParameterTypeDescription
sourcejava.io.InputStreamThe source of the archive.

SnappyArchive(String path)

public SnappyArchive(String path)

Initializes a new instance of the SnappyArchive class prepared for decompressing.


      try (FileInputStream sourceSnappyFile = new FileInputStream("sourceFileName")) {
          try (FileOutputStream extractedFile = new FileOutputStream("extractedFileName")) {
              try (SnappyArchive archive = new SnappyArchive(sourceSnappyFile)) {
                  archive.extract(extractedFile);
              }
          }
      } catch (IOException ex) {
      }
 

This constructor does not decompress. See extract(java.io.OutputStream) method for decompressing.

Parameters:

ParameterTypeDescription
pathjava.lang.Stringthe path to the source of the archive

close()

public void close()

extract(File file)

public final void extract(File file)

Extracts snappy archive to a file.


     try (FileInputStream snappyFile = new FileInputStream("sourceFileName")) {
         try (SnappyArchive archive = new SnappyArchive(snappyFile)) {
             archive.extract(new File("extracted.bin"));
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
filejava.io.Filethe file for storing decompressed data

extract(OutputStream destination)

public final void extract(OutputStream destination)

Extracts snappy archive to a stream.


     try (FileInputStream sourceSnappyFile = new FileInputStream("sourceFileName")) {
         try (FileOutputStream extractedFile = new FileOutputStream("extractedFileName")) {
             try (SnappyArchive archive = new SnappyArchive(sourceSnappyFile)) {
                 archive.extract(extractedFile);
             }
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
destinationjava.io.OutputStreamthe stream for storing decompressed data

extract(String path)

public final File extract(String path)

Extracts snappy archive to a file by path.


     try (FileInputStream snappyFile = new FileInputStream("sourceFileName")) {
         try (SnappyArchive archive = new SnappyArchive(snappyFile)) {
             archive.extract("extracted.bin");
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
pathjava.lang.Stringthe path to the file which will store decompressed data

Returns: java.io.File - java.io.File instance containing extracted data

extractToDirectory(String destinationDirectory)

public final void extractToDirectory(String destinationDirectory)

Extracts content of the archive to the directory provided.

Parameters:

ParameterTypeDescription
destinationDirectoryjava.lang.Stringthe 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 snappy archive.

Returns: java.lang.Iterable<com.aspose.zip.IArchiveFileEntry> - entries of IArchiveFileEntry type constituting the snappy archive

getLength()

public final Long getLength()

Gets length.

Returns: java.lang.Long - length.

getName()

public final String getName()

The name of original file.

Returns: java.lang.String - the name of the original file

save(File destination)

public final void save(File destination)

Saves snappy archive to destination file provided.


     try (SnappyArchive archive = new SnappyArchive()) {
         archive.setSource(new File("data.bin"));
         archive.save(new File("archive.snappy"));
     }
 

Parameters:

ParameterTypeDescription
destinationjava.io.Filethe file which will be opened as a destination stream

save(OutputStream output)

public final void save(OutputStream output)

Saves snappy archive to the stream provided.


     try (FileOutputStream snappyFile = new FileOutputStream("archive.snappy")) {
         try (SnappyArchive archive = new SnappyArchive()) {
             archive.setSource("data.bin");
             archive.save(snappyFile);
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
outputjava.io.OutputStreamthe destination stream

save(String destinationFileName)

public final void save(String destinationFileName)

Saves snappy archive to destination file provided.


     try (SnappyArchive archive = new SnappyArchive()) {
         archive.setSource(new File("data.bin"));
         archive.save("result.snappy");
     }
 

Parameters:

ParameterTypeDescription
destinationFileNamejava.lang.Stringthe path of the archive to be created. If the specified file name points to an existing file, it will be overwritten

setSource(File file)

public final void setSource(File file)

Sets the content to be compressed within the archive.


     try (SnappyArchive archive = new SnappyArchive()) {
         archive.setSource(new File("data.bin"));
         archive.save("archive.snappy");
     }
 

Parameters:

ParameterTypeDescription
filejava.io.Filethe file which will be opened as an input stream

setSource(InputStream source)

public final void setSource(InputStream source)

Sets the content to be compressed within the archive.


     try (SnappyArchive archive = new SnappyArchive()) {
         archive.setSource(new ByteArrayInputStream(new byte[] {
                 0x00,
                 (byte) 0xFF
         }));
         archive.save("archive.snappy");
     }
 

Parameters:

ParameterTypeDescription
sourcejava.io.InputStreamthe input stream for the archive

setSource(String sourcePath)

public final void setSource(String sourcePath)

Sets the content to be compressed within the archive.


     try (SnappyArchive archive = new SnappyArchive()) {
         archive.setSource("data.bin");
         archive.save("archive.snappy");
     }
 

Parameters:

ParameterTypeDescription
sourcePathjava.lang.Stringthe path to the file which will be opened as an input stream