https://bz.apache.org/bugzilla/show_bug.cgi?id=65865

--- Comment #4 from PJ Fanning <[email protected]> ---
I took your code and rewrote some of it (successfully) to read the zip file
using commons-compress.

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;

    protected String readEntry2(File xlsxFile, String entryName) throws
IOException, FileNotFoundException {
        assertNotNull(xlsxFile);
        assertNotNull(entryName);

        String entryContent = null;

        try (ZipFile zf = new ZipFile(xlsxFile)) {
            Enumeration<ZipArchiveEntry> entryEnum = zf.getEntries();
            while (entryContent == null && entryEnum.hasMoreElements()) {
                ZipArchiveEntry ze = entryEnum.nextElement();
                String fileName = ze.getName();

                if (fileName.equals(entryName)) {
                    byte[] buf = new byte[4096];
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();

                    int len;
                    try (InputStream zis = zf.getInputStream(ze)) {
                        while ((len = zis.read(buf, 0, buf.length)) != -1) {
                            bos.write(buf, 0, len);
                        }
                    }

                    entryContent = new String(bos.toByteArray(),
StandardCharsets.UTF_8);
                    assertNotNull(entryContent);
                    assertTrue(entryContent.length() > 0);
                }
            }
        }

        return entryContent;
    }

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to