mimetype
META-INF/
container.xml
OEBPS/
content.opf
toc.ncx
xhtml file
できた。が自前のJavaアプリで圧縮する必要があった。こんな感じです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.util.zip.ZipEntry; | |
import java.util.zip.ZipException; | |
import java.util.zip.ZipOutputStream; | |
public class Zip | |
{ | |
static boolean debug = true; | |
public static void main(String args[]) | |
{ | |
String sourceDir = "d:/ebook/mybook/"; | |
String zipFile = "d:/ebook/mybook.epub"; | |
try | |
{ | |
FileOutputStream fout = new FileOutputStream(zipFile); | |
ZipOutputStream zout = new ZipOutputStream(fout); | |
File fileSource = new File(sourceDir); | |
mimeType(zout, sourceDir); | |
addDirectory(zout, fileSource); | |
zout.close(); | |
} catch (IOException ioe) | |
{ | |
System.out.println("IOException :" + ioe); | |
} | |
} | |
static void mimeType(ZipOutputStream zout, String sourceDir) | |
{ | |
try | |
{ | |
byte[] buffer = new byte[1024]; | |
FileInputStream fin = new FileInputStream(sourceDir + "/mimetype"); | |
zout.putNextEntry(new ZipEntry("mimetype")); | |
zout.setLevel(ZipOutputStream.STORED); | |
int length; | |
while ((length = fin.read(buffer)) > 0) | |
{ | |
zout.write(buffer, 0, length); | |
} | |
} catch (Exception e) | |
{ | |
e.printStackTrace(); | |
} | |
} | |
private static void addDirectory(ZipOutputStream zout, File fileSource) | |
{ | |
File[] files = fileSource.listFiles(); | |
if (debug) | |
System.out.println("Adding directory " + fileSource.getName()); | |
zout.setLevel(ZipOutputStream.DEFLATED); | |
for (int i = 0; i < files.length; i++) | |
{ | |
if (files[i].isDirectory()) | |
{ | |
addDirectory(zout, files[i]); | |
continue; | |
} | |
try | |
{ | |
if (!files[i].getName().equals("mimetype")) | |
{ | |
if (debug) | |
System.out.println("Adding file " + files[i].getName()); | |
byte[] buffer = new byte[1024]; | |
FileInputStream fin = new FileInputStream(files[i]); | |
zout.putNextEntry(new ZipEntry(files[i].getName())); | |
int length; | |
while ((length = fin.read(buffer)) > 0) | |
{ | |
zout.write(buffer, 0, length); | |
} | |
zout.closeEntry(); | |
fin.close(); | |
} | |
} catch (IOException ioe) | |
{ | |
System.out.println("IOException :" + ioe); | |
} | |
} | |
} | |
} |