com.softicar.platform.common.core.java.jar.JarFileEntryIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.core.java.jar;
import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class JarFileEntryIterator implements Iterator, AutoCloseable {
private final ZipFile zipFile;
private Enumeration enumeration;
public JarFileEntryIterator(File file) {
try {
this.zipFile = new ZipFile(file);
this.enumeration = zipFile.entries();
} catch (IOException exception) {
throw new RuntimeException(exception);
}
}
@Override
public void close() {
try {
zipFile.close();
} catch (IOException exception) {
throw new RuntimeException(exception);
}
}
@Override
public boolean hasNext() {
boolean hasMoreElements = enumeration.hasMoreElements();
if (hasMoreElements) {
return true;
} else {
close();
return false;
}
}
@Override
public JarFileEntry next() {
return new JarFileEntry(zipFile, enumeration.nextElement());
}
}