I built a method that recursively adds the contents of a folder to a zip document with the file extension "epub," which is basically what an epub is except for one thing:
the first document in the archive must be named "mimetype," the type must be specified application/epub+zip, and must start with a byte offset of 38. Is there a way to add the mimetype to the archive with offset 38?
The method I built nearly works. It constructs an epub which can be read by most e-readers, but it doesn't validate. EpubCheck gives this error:
mimetype contains wrong type (application/epub+zip expected)
This is an issue that does not exist in the original test epub, but shows up in the reconstructed epub. And I double checked that the contents of the unzipped/rezipped mimetype file are correct.
The method is too much to post here. But this is what I'm using to add the mimetype file to the archive:
out = new ZipOutputStream(new FileOutputStream(outFilename));
FileInputStream in = new FileInputStream(mimeTypePath);
out.putNextEntry(new ZipEntry("mimetype"));
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.closeEntry();
in.close();
out.close();