codec
Class UTF8InputStreamReader

java.lang.Object
  |
  +--java.io.Reader
        |
        +--codec.UTF8InputStreamReader

public class UTF8InputStreamReader
extends Reader

This class provides efficient UTF8 reading capability as a sub-class of java.io.Reader. It is able to buffer, and translate from an UTF8 input stream to Unicode characters. Method readLine() can return a single line of material as a Java string. For best performance, call new UTF8InputStreamReader(in, 2048) instead of new BufferedReader(new InputStreamReader(new BufferedInputStream(in, 2048), "UTF8" ), 1)


Field Summary
protected  byte[] bytebuf_
           
protected  int byteptr_
           
protected  char extraCh_
           
protected  int hasExtra_
           
protected  InputStream ins_
           
protected  int numbytes_
           
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
UTF8InputStreamReader(InputStream i, int bufsize)
          This constructor initializes an UTF8InputStreamReader.
 
Method Summary
protected  void characterDecodingException()
           
protected  void checkOpen()
          Checks whether the InputStream, with which this object is initialized, is initialized.
 void close()
           
 String getEncoding()
           
 int read()
           
 int read(char[] cbuf, int off, int len)
           
 String readLine()
          Read from UTF8 stream until end of line, and return the content as a Java String.
 boolean ready()
           
 
Methods inherited from class java.io.Reader
mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

numbytes_

protected int numbytes_

hasExtra_

protected int hasExtra_

extraCh_

protected char extraCh_

byteptr_

protected int byteptr_

ins_

protected InputStream ins_

bytebuf_

protected byte[] bytebuf_
Constructor Detail

UTF8InputStreamReader

public UTF8InputStreamReader(InputStream i,
                             int bufsize)
This constructor initializes an UTF8InputStreamReader.
Parameters:
i - the InputStream object from which the input will be read.
bufsize - the size which must be buffered.
Method Detail

getEncoding

public String getEncoding()

checkOpen

protected void checkOpen()
                  throws IOException
Checks whether the InputStream, with which this object is initialized, is initialized.
Throws:
IOException - if the InputStream is null

read

public int read()
         throws IOException
Overrides:
read in class Reader
See Also:
Reader.read()

read

public int read(char[] cbuf,
                int off,
                int len)
         throws IOException
Overrides:
read in class Reader
See Also:
Reader.read(char[], int, int)

readLine

public String readLine()
                throws IOException
Read from UTF8 stream until end of line, and return the content as a Java String. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed by a linefeed.
Returns:
A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached.
Throws:
IOException - if an I/O error occurs.

ready

public boolean ready()
              throws IOException
Overrides:
ready in class Reader
See Also:
Reader.ready()

close

public void close()
           throws IOException
Overrides:
close in class Reader

characterDecodingException

protected void characterDecodingException()
                                   throws IOException


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.