com.caucho.vfs.i18n
Class EncodingReader

java.lang.Object
  extended by java.io.Reader
      extended by com.caucho.vfs.i18n.EncodingReader
All Implemented Interfaces:
java.io.Closeable, java.lang.Readable
Direct Known Subclasses:
ISO8859_1Reader, JAVAReader, JDKReader, UTF16_REVReader, UTF16Reader, UTF8Reader, WindowsHackReader

public abstract class EncodingReader
extends java.io.Reader

Abstract class for a byte-to-character encoding reader and its associated factory.

Implementations need to implement create and read() at minimum. Efficient implementations will also implement the read into a buffer.

Implementations should not buffer the bytes.


Field Summary
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
EncodingReader()
           
 
Method Summary
 void close()
          Closes the reader, possibly returning it to a pool.
 java.io.Reader create(java.io.InputStream is)
          Returns a new encoding reader for the given stream and javaEncoding.
abstract  java.io.Reader create(java.io.InputStream is, java.lang.String javaEncoding)
          Returns a new encoding reader for the given stream and javaEncoding.
 java.lang.String getJavaEncoding()
           
abstract  int read()
          Returns the next character using the correct encoding.
 int read(char[] cbuf, int off, int len)
          Reads into a character buffer using the correct encoding.
 void setJavaEncoding(java.lang.String encoding)
           
 
Methods inherited from class java.io.Reader
mark, markSupported, read, read, ready, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EncodingReader

public EncodingReader()
Method Detail

getJavaEncoding

public java.lang.String getJavaEncoding()

setJavaEncoding

public void setJavaEncoding(java.lang.String encoding)

create

public abstract java.io.Reader create(java.io.InputStream is,
                                      java.lang.String javaEncoding)
                               throws java.io.UnsupportedEncodingException
Returns a new encoding reader for the given stream and javaEncoding.

Parameters:
is - the input stream providing the bytes.
javaEncoding - the JDK name for the encoding.
Returns:
an encoding reader or null for ISO-8859-1.
Throws:
java.io.UnsupportedEncodingException

create

public java.io.Reader create(java.io.InputStream is)
                      throws java.io.UnsupportedEncodingException
Returns a new encoding reader for the given stream and javaEncoding.

Parameters:
is - the input stream providing the bytes.
javaEncoding - the JDK name for the encoding.
Returns:
an encoding reader or null for ISO-8859-1.
Throws:
java.io.UnsupportedEncodingException

read

public abstract int read()
                  throws java.io.IOException
Returns the next character using the correct encoding.

Overrides:
read in class java.io.Reader
Returns:
the next character or -1 on end of file.
Throws:
java.io.IOException

read

public int read(char[] cbuf,
                int off,
                int len)
         throws java.io.IOException
Reads into a character buffer using the correct encoding.

Specified by:
read in class java.io.Reader
Parameters:
cbuf - character buffer receiving the data.
off - starting offset into the buffer.
len - number of characters to read.
Returns:
the number of characters read or -1 on end of file.
Throws:
java.io.IOException

close

public void close()
Closes the reader, possibly returning it to a pool.

Specified by:
close in interface java.io.Closeable
Specified by:
close in class java.io.Reader