org.w3c.tools.jpeg
Class JpegCommentWriter

java.lang.Object
  extended by java.io.Writer
      extended by org.w3c.tools.jpeg.JpegCommentWriter
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.lang.Appendable

public class JpegCommentWriter
extends java.io.Writer

Allow you to write text comments to jpeg stream Some code has been adapted from wrjpgcom.c from The Independent JPEG Group


Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
JpegCommentWriter(java.io.OutputStream out, java.io.InputStream in)
          Create a JpegCommentWriter, using an Input stream as the jpeg binary source, and writing in the output stream
JpegCommentWriter(java.io.OutputStream out, java.io.InputStream in, java.lang.String enc)
          Create a JpegCommentWriter, using an Input stream as the jpeg binary source, and writing in the output stream
 
Method Summary
 void close()
           
protected  void dupFirstHeaders()
          the the first headers until a SOF parker is found
protected  int dupFirstMarker()
          copy the marker and return it
protected  void dupHeader(int marker)
          dup the marker and the body
 void flush()
           
 java.lang.String getEncoding()
          gets the encoding used by the comment writer
static void main(java.lang.String[] args)
          The usual debugging tool
protected  int nextMarker()
          get the next marker, and eat extra bytes
protected  int read2bytes()
          read 2 bytes and create an integer out of it
protected  void skipVariable()
          skip the body after a marker
 void write(char[] buffer)
          write an array of characters
 void write(char[] buffer, int off, int len)
          write a portion of an array of characters
 void write(int ch)
          write one character
 void write(java.lang.String s)
          Write a String
 void write(java.lang.String s, int off, int len)
          Write a portion of a String
protected  void writeMarker(int marker)
           
protected  void writeMarkerLength(int len)
           
 
Methods inherited from class java.io.Writer
append, append, append
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JpegCommentWriter

public JpegCommentWriter(java.io.OutputStream out,
                         java.io.InputStream in)
Create a JpegCommentWriter, using an Input stream as the jpeg binary source, and writing in the output stream

Parameters:
out, - the output stream where the image will be written
in, - the input stream of the jpeg file, it MUST point to the beginning of the jpeg to avoid problems

JpegCommentWriter

public JpegCommentWriter(java.io.OutputStream out,
                         java.io.InputStream in,
                         java.lang.String enc)
                  throws java.io.UnsupportedEncodingException
Create a JpegCommentWriter, using an Input stream as the jpeg binary source, and writing in the output stream

Parameters:
out, - the output stream where the image will be written
in, - the input stream of the jpeg file, it MUST point to the beginning of the jpeg to avoid problems
enc, - the encoding name used when you write comments
Throws:
java.io.UnsupportedEncodingException
Method Detail

getEncoding

public java.lang.String getEncoding()
gets the encoding used by the comment writer


write

public void write(int ch)
           throws java.io.IOException
write one character

Overrides:
write in class java.io.Writer
Throws:
java.io.IOException

write

public void write(char[] buffer)
           throws java.io.IOException
write an array of characters

Overrides:
write in class java.io.Writer
Throws:
java.io.IOException

write

public void write(char[] buffer,
                  int off,
                  int len)
           throws java.io.IOException
write a portion of an array of characters

Specified by:
write in class java.io.Writer
Throws:
java.io.IOException

write

public void write(java.lang.String s)
           throws java.io.IOException
Write a String

Overrides:
write in class java.io.Writer
Throws:
java.io.IOException

write

public void write(java.lang.String s,
                  int off,
                  int len)
           throws java.io.IOException
Write a portion of a String

Overrides:
write in class java.io.Writer
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Specified by:
flush in interface java.io.Flushable
Specified by:
flush in class java.io.Writer
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Specified by:
close in class java.io.Writer
Throws:
java.io.IOException

dupFirstMarker

protected int dupFirstMarker()
                      throws java.io.IOException,
                             JpegException
copy the marker and return it

Throws:
java.io.IOException
JpegException

read2bytes

protected int read2bytes()
                  throws java.io.IOException,
                         JpegException
read 2 bytes and create an integer out of it

Throws:
java.io.IOException
JpegException

nextMarker

protected int nextMarker()
                  throws java.io.IOException
get the next marker, and eat extra bytes

Throws:
java.io.IOException

skipVariable

protected void skipVariable()
                     throws java.io.IOException,
                            JpegException
skip the body after a marker

Throws:
java.io.IOException
JpegException

dupHeader

protected void dupHeader(int marker)
                  throws java.io.IOException,
                         JpegException
dup the marker and the body

Throws:
java.io.IOException
JpegException

writeMarker

protected void writeMarker(int marker)
                    throws java.io.IOException
Throws:
java.io.IOException

writeMarkerLength

protected void writeMarkerLength(int len)
                          throws java.io.IOException
Throws:
java.io.IOException

dupFirstHeaders

protected void dupFirstHeaders()
                        throws java.io.IOException
the the first headers until a SOF parker is found

Throws:
java.io.IOException

main

public static void main(java.lang.String[] args)
The usual debugging tool