com.groupdocs.parser

Interfaces

Classes

Exceptions

com.groupdocs.parser

Class ZipContainer

  • All Implemented Interfaces:
    IContainer, AutoCloseable


    public final class ZipContainer
    extends Container

    Provides a container for zip archives.

    Enumerate all files in the archive:

     // Create a container for Zip
     IContainer container = new ZipContainer(stream);
     // Iterate items
     for (int i = 0; i < container.getEntities().size(); i++) {
         System.out.println("Name: " + container.getEntities().get(i).getName()); // name of the file
         System.out.println("Path: " + container.getEntities().get(i).getPath().toString()); // path of the file
         System.out.println("MediaType :" + container.getEntities().get(i).getMediaType()); // media type of the file
         System.out.println("Date: " + container.getEntities().get(i).getDate().toString()); // date when the file was added to the archive
         System.out.println("Size: " + container.getEntities().get(i).getSize()); // uncompressed size of the file
     }
      

    Read the concrete file:

     // Create a container for ZIP
     IContainer container = new ZipContainer(stream);
     // Create an extractor for the file
     TextExtractor extractor = extractorFactory.createTextExtractor(container.getEntities().get(index).OpenStream());
     // Extract a text from the email
     System.out.println(extractor == null ? "document isn't supported" : extractor.extractAll());
      
    • Constructor Detail

      • ZipContainer

        public ZipContainer(String fileName)

        Initializes a new instance of the ZipContainer class.

        Parameters:
        fileName - The path to the file.
      • ZipContainer

        public ZipContainer(String fileName,
                    LoadOptions loadOptions)

        Initializes a new instance of the ZipContainer class.

        Parameters:
        fileName - The path to the file.
        loadOptions - The options of loading the file.
      • ZipContainer

        public ZipContainer(InputStream stream)

        Initializes a new instance of the ZipContainer class.

        Parameters:
        stream - The stream of the document.
      • ZipContainer

        public ZipContainer(InputStream stream,
                    LoadOptions loadOptions)

        Initializes a new instance of the ZipContainer class.

        Parameters:
        stream - The stream of the document.
        loadOptions - The options of loading the file.
    • Method Detail

      • getEntity

        public Container.Entity getEntity(String name)

        Gets an entity by the full entity name.

        Parameters:
        name - The entity name.
        Returns:
        The entity with "name" or null if the entity with "name" isn't contained in the container.
      • dispose

        protected void dispose(boolean disposing)

        Releases the unmanaged resources used by the container.

        Overrides:
        dispose in class Container
        Parameters:
        disposing - A boolean true if invoked from Dispose; otherwise, false.
      • loadEntities

        protected List<Container.Entity> loadEntities()

        Returns a collection of the container's entities.

        Specified by:
        loadEntities in class Container
        Returns:
        A collection of the container's entities.
      • openStream

        protected InputStream openStream(Container.Entity entity)
        Description copied from class: Container

        Returns the stream with the content of the entity.

        Specified by:
        openStream in class Container
        Parameters:
        entity - The entity.
        Returns:
        An instance of the java.io.InputStream with the content of the entity.