01: // JpegCommentHandler.java
02: // $Id: JpegCommentHandler.java,v 1.5 2000/08/16 21:37:50 ylafon Exp $
03: // (c) COPYRIGHT MIT, INRIA and Keio, 1999.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.tools.jpeg;
07:
08: import java.io.BufferedInputStream;
09: import java.io.File;
10: import java.io.FileInputStream;
11: import java.io.FileNotFoundException;
12: import java.io.IOException;
13: import java.io.InputStream;
14: import java.io.OutputStream;
15: import java.io.Reader;
16: import java.io.StringReader;
17: import java.io.UnsupportedEncodingException;
18: import java.io.Writer;
19:
20: import java.util.Vector;
21:
22: public class JpegCommentHandler {
23:
24: protected File jpegfile;
25: protected InputStream in;
26:
27: /**
28: * Get this image reader
29: */
30: public Reader getReader() throws IOException, JpegException {
31: return new StringReader(getComment());
32: }
33:
34: public String getComment() throws IOException, JpegException {
35: JpegHeaders jpeghead = new JpegHeaders(in);
36: StringBuffer sb = new StringBuffer();
37: // get the comments out of the jpeg file
38: String comms[] = jpeghead.getComments();
39: // and dump them in one big string
40: for (int i = 0; i < comms.length; i++) {
41: sb.append(comms[i]);
42: }
43: return sb.toString();
44: }
45:
46: /**
47: * Get this image writer
48: */
49: public Writer getOutputStreamWriter(OutputStream out, String enc)
50: throws UnsupportedEncodingException {
51: return new JpegCommentWriter(out, in, enc);
52: }
53:
54: /**
55: * Get this image writer
56: */
57: public Writer getOutputStreamWriter(OutputStream out) {
58: return new JpegCommentWriter(out, in);
59: }
60:
61: /**
62: * create it out of a File
63: */
64: public JpegCommentHandler(File jpegfile)
65: throws FileNotFoundException {
66: this .in = new BufferedInputStream(new FileInputStream(jpegfile));
67: this .jpegfile = jpegfile;
68: }
69:
70: /**
71: * create it from an input stream
72: */
73: public JpegCommentHandler(InputStream in) {
74: this.in = in;
75: }
76: }
|