Class LhaArchive

  • All Implemented Interfaces:
    IArchive, AutoCloseable

    public class LhaArchive
    extends Object
    implements IArchive, AutoCloseable

    This class represents a LHA (.lzh) archive file.

    Only the following compression methods are supported:

    Method Explanation
    lh0 Uncompressed
    lh4 8 KiB sliding dictionary and static Huffman
    lh5 16 KiB sliding dictionary and static Huffman
    lh6 64 KiB sliding dictionary and static Huffman
    lh7 128 KiB sliding dictionary and static Huffman
    lhx 1 Mib sliding dictionary and static Huffman
    lhd Directory

    • Constructor Detail

      • LhaArchive

        public LhaArchive​(InputStream sourceStream)

        Initializes a new instance of the LhaArchive class and composes an entry list can be extracted from the archive.

        This constructor does not decompress any entry. See LhaArchiveEntry.extract(OutputStream) method for decompressing.

        Parameters:
        sourceStream - the source of the archive
        Throws:
        com.aspose.ms.System.ArgumentNullException - sourceStream is null
        com.aspose.ms.System.IO.InvalidDataException - Inappropriate data found.
      • LhaArchive

        public LhaArchive​(InputStream sourceStream,
                          LhaLoadOptions loadOptions)

        Initializes a new instance of the LhaArchive class and composes an entry list can be extracted from the archive.

        This constructor does not decompress any entry. See LhaArchiveEntry.extract(OutputStream) method for decompressing.

        Parameters:
        sourceStream - the source of the archive
        loadOptions - Options to load existing archive with.
        Throws:
        com.aspose.ms.System.ArgumentNullException - sourceStream is null
        com.aspose.ms.System.IO.InvalidDataException - Inappropriate data found.
      • LhaArchive

        public LhaArchive​(String path)

        Initializes a new instance of the LhaArchive class and composes an entry list can be extracted from the archive.

        The following example extracts an archive, then decompress first entry to a MemoryStream.

        
             ByteArrayOutputStream extracted = new ByteArrayOutputStream();
             try (LhaArchive archive = new LhaArchive("sample.lzh")) {
                 archive.getEntries().get(0).extract(extracted);
             }
         

        This constructor does not decompress any entry. See ArchiveEntry.extract(OutputStream) method for decompressing.

        Parameters:
        path - the fully qualified or the relative path to the archive file
        Throws:
        com.aspose.ms.System.ArgumentNullException - path is null.
        com.aspose.ms.System.SecurityException - The caller does not have the required permission to access.
        com.aspose.ms.System.ArgumentException - The path is empty, contains only white spaces, or contains invalid characters.
        com.aspose.ms.System.IO.PathTooLongException - The specified path, 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 at path contains a colon (:) in the middle of the string.
        com.aspose.ms.System.IO.FileNotFoundException - The file is not found.
        com.aspose.ms.System.IO.DirectoryNotFoundException - The specified path is invalid, such as being on an unmapped drive.
        com.aspose.ms.System.IO.IOException - The file is already open.
        com.aspose.ms.System.IO.InvalidDataException - The file is corrupted.
      • LhaArchive

        public LhaArchive​(String path,
                          LhaLoadOptions loadOptions)

        Initializes a new instance of the LhaArchive class and composes an entry list can be extracted from the archive.

        The following example extracts an archive, then decompress first entry to a MemoryStream.

        
             ByteArrayOutputStream extracted = new ByteArrayOutputStream();
             try (LhaArchive archive = new LhaArchive("sample.lzh")) {
                 archive.getEntries().get(0).extract(extracted);
             }
         

        This constructor does not decompress any entry. See ArchiveEntry.extract(OutputStream) method for decompressing.

        Parameters:
        path - the fully qualified or the relative path to the archive file
        loadOptions - Options to load existing archive with.
        Throws:
        com.aspose.ms.System.ArgumentNullException - path is null.
        com.aspose.ms.System.SecurityException - The caller does not have the required permission to access.
        com.aspose.ms.System.ArgumentException - The path is empty, contains only white spaces, or contains invalid characters.
        com.aspose.ms.System.IO.PathTooLongException - The specified path, 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 at path contains a colon (:) in the middle of the string.
        com.aspose.ms.System.IO.FileNotFoundException - The file is not found.
        com.aspose.ms.System.IO.DirectoryNotFoundException - The specified path is invalid, such as being on an unmapped drive.
        com.aspose.ms.System.IO.IOException - The file is already open.
        com.aspose.ms.System.IO.InvalidDataException - The file is corrupted.
    • Method Detail

      • getFormat

        public final ArchiveFormat getFormat()

        Gets the archive format.

        Specified by:
        getFormat in interface IArchive
        Returns:
        the archive format
      • extractToDirectory

        public final void extractToDirectory​(String destinationDirectory)

        Extracts all the files and directories in the archive to the directory provided.

        
             try (LhaArchive archive = new LhaArchive("archive.lzh")) {
                 archive.extractToDirectory("C:/extracted");
             }
         
        Specified by:
        extractToDirectory in interface IArchive
        Parameters:
        destinationDirectory - the path to the directory to place the extracted files in.

        If the directory does not exist, it will be created

        Throws:
        com.aspose.ms.System.ArgumentNullException - destinationDirectory is null.
        com.aspose.ms.System.IO.PathTooLongException - The specified path, 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.SecurityException - The caller does not have the required permission to access the existing directory.
        com.aspose.ms.System.NotSupportedException - If the directory does not exist, the path contains a colon character (:) that is not part of a drive label ("C:\").
        com.aspose.ms.System.ArgumentException - destinationDirectory is a zero-length string, contains only white space, or contains one or more invalid characters.
        com.aspose.ms.System.IO.IOException - The directory specified by path is a file or the network name is not known.
        com.aspose.ms.System.IO.InvalidDataException - Wrong password has been supplied or archive is corrupted.