Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active September 9, 2021 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GroupDocsGists/6ac7a940cd05a19520d18e7648756c6f to your computer and use it in GitHub Desktop.
Save GroupDocsGists/6ac7a940cd05a19520d18e7648756c6f to your computer and use it in GitHub Desktop.
Extract ZIP Archives Data in Java
// 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.");
}
}
// 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