--- /dev/null
+// JpegCommentHandler.java\r
+// $Id: JpegCommentHandler.java,v 1.1 2010/06/15 12:29:18 smhuang Exp $\r
+// (c) COPYRIGHT MIT, INRIA and Keio, 1999.\r
+// Please first read the full copyright statement in file COPYRIGHT.html\r
+\r
+package org.w3c.tools.jpeg;\r
+\r
+import java.io.BufferedInputStream;\r
+import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.FileNotFoundException;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.io.OutputStream;\r
+import java.io.Reader;\r
+import java.io.StringReader;\r
+import java.io.UnsupportedEncodingException;\r
+import java.io.Writer;\r
+\r
+import java.util.Vector;\r
+\r
+public class JpegCommentHandler {\r
+\r
+ protected File jpegfile;\r
+ protected InputStream in;\r
+\r
+ /**\r
+ * Get this image reader\r
+ */\r
+ public Reader getReader() throws IOException,JpegException {\r
+ return new StringReader(getComment());\r
+ }\r
+\r
+ public String getComment() throws IOException,JpegException {\r
+ JpegHeaders jpeghead = new JpegHeaders(in);\r
+ StringBuffer sb = new StringBuffer();\r
+ // get the comments out of the jpeg file\r
+ String comms[] = jpeghead.getComments();\r
+ // and dump them in one big string\r
+ for (int i=0; i< comms.length; i++) {\r
+ sb.append(comms[i]);\r
+ }\r
+ return sb.toString();\r
+ }\r
+\r
+ /**\r
+ * Get this image writer\r
+ */\r
+ public Writer getOutputStreamWriter(OutputStream out, String enc) \r
+ throws UnsupportedEncodingException\r
+ {\r
+ return new JpegCommentWriter(out, in, enc);\r
+ }\r
+\r
+ /**\r
+ * Get this image writer\r
+ */\r
+ public Writer getOutputStreamWriter(OutputStream out) {\r
+ return new JpegCommentWriter(out, in);\r
+ }\r
+\r
+ /**\r
+ * create it out of a File\r
+ */\r
+ public JpegCommentHandler(File jpegfile) \r
+ throws FileNotFoundException\r
+ {\r
+ this.in = \r
+ new BufferedInputStream( new FileInputStream(jpegfile));\r
+ this.jpegfile = jpegfile;\r
+ }\r
+\r
+ /**\r
+ * create it from an input stream\r
+ */\r
+ public JpegCommentHandler(InputStream in) {\r
+ this.in = in;\r
+ }\r
+}\r
+\r
+\r