Comments (1)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Lisa L
Level 47 , Nuremberg, Germany
13 May, 22:46
That's the code I validated with
public List<FileProperties> getFileList() throws Exception {
    if (!Files.isRegularFile(zipFile))
        throw new NoSuchZipFileException();

    List<FileProperties> fileProperties = new ArrayList<>();

    try (ZipInputStream zipInputStream = new ZipInputStream(Files.newInputStream(zipFile))) {
        ZipEntry zipEntry;
        while((zipEntry = zipInputStream.getNextEntry()) != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            copyData(zipInputStream, baos);

            String name = zipEntry.getName();
            long size = baos.size();
            long compressedSize = zipEntry.getCompressedSize();
            int compressionMethod = zipEntry.getMethod();
            fileProperties.add(new FileProperties(name, size, compressedSize, compressionMethod));
        }
    }

    return fileProperties;
}