I have some existing code for creating zip files in Epub 2 format that works correctly.
When trying to update my code to support the Epub 3 format, I thought that I would try to use the Java NIO Zip file system instead of java.util.zip.ZipFile . I'm almost there, except for one tiny thing.
There is a 20-byte mimetype file required in the Epub format, which must be placed in a ZIP file in uncompressed form. java.util.zip.ZipEntry api provides setMethod(ZipEntry.STORED) to achieve this.
I cannot find references to this in the Java NIO FileSystem API document. Is there an equivalent to ZipEntry.setMethod() ?
EDIT 1
OK, so I see how to display attributes, and thanks for this example, but I cannot find any document on how to create an attribute such as (zip: method, 0), even on Oracle oracle. Java NIO enhancements to Java seem only about 20% documented to me. The api doc attributes are very scarce, especially how to create attributes.
The feeling I'm starting to get is that the NIO Zip file system may not be improved on java.util.zip and requires more code to achieve the same result.
EDIT 2
I tried the following:
String contents = "application/epub+zip"; Map<String, String> map = new HashMap<>(); map.put("create", "true"); Path zipPath = Paths.get("zipfstest.zip"); Files.deleteIfExists(zipPath); URI fileUri = zipPath.toUri();
The ZipFileAttribute class is a minimal implementation of the attribute interface. I can publish it, but it's just a key-value pair (name, value)
This code successfully created the zipFile, but when I open the zipFile with 7zip, I see that the mimetype file was stored in the zip as DEFLATED (8), and not the one I need, which is stored (0). So the question is how to properly encode an attribute so that it is stored as STORED.
java compression zip nio
casgage
source share