Java Utililty Methods ZipEntry Read

List of utility methods to do ZipEntry Read

Description

The list of methods to do ZipEntry Read are organized into topic(s).

Method

StringgetZipEntryAsString(File archive, String name)
get Zip Entry As String
FileInputStream fileIn = null;
try {
    fileIn = new FileInputStream(archive);
    BufferedInputStream buffered = new BufferedInputStream(fileIn);
    ZipInputStream zip = new ZipInputStream(buffered);
    ArrayList<String> entries = new ArrayList<String>();
    ZipEntry next = zip.getNextEntry();
    while (next != null) {
...
StringgetZipEntryAsString(InputStream is)
get Zip Entry As String
StringBuffer sb = new StringBuffer();
byte[] buf = new byte[1024];
int len;
while (is.available() >= 1 && (len = is.read(buf)) > 0)
    sb.append(new String(buf, 0, len));
return sb.toString();
byte[]getZipEntryByteContent(ZipEntry ze, ZipFile zip)
Returns the contents of the given zip entry as a byte array.
InputStream stream = null;
try {
    stream = new BufferedInputStream(zip.getInputStream(ze));
    return getInputStreamAsByteArray(stream, (int) ze.getSize());
} finally {
    if (stream != null) {
        try {
            stream.close();
...
StringgetZipEntryContent(final File zip, final String entry)
Get the content of a zip entry.
try (ZipFile f = new ZipFile(zip)) {
    final ZipEntry e = f.getEntry(entry);
    final InputStream is = f.getInputStream(e);
    final BufferedReader br = new BufferedReader(new InputStreamReader(is));
    String line = null;
    final StringBuilder sb = new StringBuilder();
    while ((line = br.readLine()) != null) {
        if (Thread.currentThread().isInterrupted()) {
...
StringgetZipEntryFileName(final ZipEntry zipEntry)
Returns file name for the specified zip entry.
final String name = zipEntry.getName();
return name.substring(name.lastIndexOf("/") + 1);
StringgetZipEntryName(int pathOffset, String absolutePath)
get Zip Entry Name
return absolutePath.substring(pathOffset).replace(File.separatorChar, '/');
String[]getZipEntryNames(File zipFile)
get Zip Entry Names
ArrayList<String> zipEntryNames = new ArrayList<String>();
ZipFile zip = new ZipFile(zipFile);
Enumeration<? extends ZipEntry> zipEntries = zip.entries();
while (zipEntries.hasMoreElements())
    zipEntryNames.add(zipEntries.nextElement().getName());
return zipEntryNames.toArray(new String[zipEntryNames.size()]);
StringgetZipEntryPath(File f, String archiveSourceDir)
get Zip Entry Path
String entryPath = f.getPath();
entryPath = entryPath.substring(archiveSourceDir.length() + 1);
if (File.separatorChar == '\\') {
    entryPath = entryPath.replace(File.separatorChar, '/');
if (f.isDirectory()) {
    entryPath += "/";
return entryPath;
InputStreamgetZipEntryStream(File zipFile, String entryName)
get Zip Entry Stream
ZipEntry zipEntry;
ZipInputStream zIn;
BufferedInputStream in = new BufferedInputStream(new FileInputStream(zipFile));
zIn = new ZipInputStream(in);
while ((zipEntry = zIn.getNextEntry()) != null) {
    String zipEntryName = zipEntry.getName();
    if (zipEntryName.equalsIgnoreCase(entryName)) {
        break;
...
InputStreamgetZipEntryStreamOrThrow(File file, String filenamePart)
get Zip Entry Stream Or Throw
ZipFile zipFile = new ZipFile(file);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
    ZipEntry entry = entries.nextElement();
    if (entry.getName().contains(filenamePart)) {
        return zipFile.getInputStream(entry);
throw new FileNotFoundException("No zip file entry found matching filename part '" + filenamePart + "'");