OSDN Git Service

Use tempfile.
authorTakeyuki NAGAO <nagaotakeyuki@gmail.com>
Fri, 30 Mar 2012 06:54:38 +0000 (15:54 +0900)
committerTakeyuki NAGAO <nagaotakeyuki@gmail.com>
Fri, 30 Mar 2012 06:54:38 +0000 (15:54 +0900)
src/jp/sourceforge/dvibrowser/dvi2epub/Dvi2EpubCmd.java

index cde4ab1..a4a7795 100644 (file)
@@ -112,8 +112,8 @@ public class Dvi2EpubCmd extends AnnotatedCommand {
                                bbox = bbox.addPadding(getPaddingSize());
                                BufferedImage img = toolkit.renderToBufferedImage(page, bbox, viewSpec);
                                String imageFile = String.format("images/page%04d.%s", pn, formatExt);
-                               String filename = String.format("sample/page%06d.%s", pn, formatExt);
-                               File png = new File(filename);
+                               File png = File.createTempFile("dvi2epub", "." + formatExt);
+                               png.deleteOnExit();
                                ImageIO.write(img, formatName, png);
                                epubWriter.writeFile(imageFile, formatMime, png, false, false, false);
                                String docType = "<?xml version='1.0' encoding='UTF-8'?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n";
@@ -121,6 +121,7 @@ public class Dvi2EpubCmd extends AnnotatedCommand {
                                epubWriter.writeFile(String.format("page%04d.html", pn), "application/x-html",
                                                String.format("%s<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='ja' lang='ja'><body>%s<img src='images/page%04d.%s' /></body></html>", docType, body, pn, formatExt)
                                                , true, true, true);
+                               png.delete();
                        }
                        epubWriter.close();
                        System.out.println();