Last active
September 9, 2021 12:56
-
-
Save GroupDocsGists/6ac7a940cd05a19520d18e7648756c6f to your computer and use it in GitHub Desktop.
Extract ZIP Archives Data in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Extract ZIP Archives Data in Java | |
Parser parser = new Parser("path/archive.zip"); | |
// Extract attachments from the container | |
Iterable<ContainerItem> attachments = parser.getContainer(); | |
// Iterate over collection of ZIP entities | |
for (ContainerItem item : attachments) { | |
// Print the FILE INFO | |
System.out.println("-----------------------------------"); | |
System.out.println("Name: " + item.getName()); | |
System.out.println("File Size: " + item.getSize() + " Bytes"); | |
System.out.println("-----------------------------------"); | |
try { | |
Parser attachmentParser = item.openParser(); | |
TextReader reader = attachmentParser.getText(); | |
System.out.println(reader == null ? "No text" : reader.readToEnd()); | |
} | |
catch (UnsupportedDocumentFormatException ex) { | |
System.out.println("Isn't supported."); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Extract Images info from file within the ZIP archive in Java | |
Parser parser = new Parser("path/archive.zip"); | |
// Extract attachments from the container | |
Iterable<ContainerItem> attachments = parser.getContainer(); | |
// Iterate over collection of ZIP entities | |
for (ContainerItem item : attachments) { | |
try { | |
Parser attachmentParser = item.openParser(); | |
Iterable<PageImageArea> images = attachmentParser.getImages(); | |
if (images != null) { | |
int imageCount = 1; | |
for (PageImageArea image : images) { | |
// Print a page index, rectangle and image type: | |
System.out.println(String.format("Image# %d \nPage: %d\nFile Type: %s", imageCount, image.getPage().getIndex()+1, image.getFileType())); | |
imageCount++; | |
} | |
} | |
} | |
catch (UnsupportedDocumentFormatException ex) { | |
System.out.println("Isn't supported."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment