de.hedenus.mobilexml
Class CharReader

java.lang.Object
  extended by de.hedenus.mobilexml.CharReader

public class CharReader
extends java.lang.Object

A buffered character encoder.

Author:
Michael Hedenus

Field Summary
static java.lang.String ENCODING_ASCII
           
static java.lang.String ENCODING_UNKNOWN
           
static java.lang.String ENCODING_UTF16
           
static java.lang.String ENCODING_UTF16_BE
           
static java.lang.String ENCODING_UTF16_LE
           
static java.lang.String ENCODING_UTF8
           
static java.lang.String ENCODING_UTF8Y
           
static char EOF_CHAR
           
 
Constructor Summary
CharReader(int initialStreamBufferSize)
           
 
Method Summary
 char getChar(int i)
          Returns the ith char from the buffer.
 java.lang.String getEncoding()
          Returns the currently set encoding.
 java.io.InputStream getInputStream()
           
 int getLineNumber()
           
 java.lang.String getUsedEncoding()
          Returns the actually used encoding.
 boolean hasNextChar()
          Returns true if there are more chars to read.
 char nextChar()
          Reads and returns the next char.
 void setEncoding(java.lang.String encoding)
          Sets the character encoding.
 void setInputStream(java.io.InputStream inputStream, java.lang.String encoding)
          Sets the stream.
 void skipChars(int count)
          Skips n chars.
 void skipWhitespace()
          Moves the reader before the next non-whitespace char.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EOF_CHAR

public static final char EOF_CHAR
See Also:
Constant Field Values

ENCODING_UNKNOWN

public static final java.lang.String ENCODING_UNKNOWN
See Also:
Constant Field Values

ENCODING_ASCII

public static final java.lang.String ENCODING_ASCII
See Also:
Constant Field Values

ENCODING_UTF8

public static final java.lang.String ENCODING_UTF8
See Also:
Constant Field Values

ENCODING_UTF8Y

public static final java.lang.String ENCODING_UTF8Y
See Also:
Constant Field Values

ENCODING_UTF16_BE

public static final java.lang.String ENCODING_UTF16_BE
See Also:
Constant Field Values

ENCODING_UTF16_LE

public static final java.lang.String ENCODING_UTF16_LE
See Also:
Constant Field Values

ENCODING_UTF16

public static final java.lang.String ENCODING_UTF16
See Also:
Constant Field Values
Constructor Detail

CharReader

public CharReader(int initialStreamBufferSize)
Method Detail

setInputStream

public void setInputStream(java.io.InputStream inputStream,
                           java.lang.String encoding)
                    throws java.io.IOException
Sets the stream. If the encoding is null the reader will try to autodetect the encoding.

Parameters:
inputStream - the input stream
encoding - the encoding or null of the encoding is unknown.
Throws:
java.io.IOException

getInputStream

public java.io.InputStream getInputStream()

getEncoding

public java.lang.String getEncoding()
Returns the currently set encoding. To know which encoding us actually used, see getUsedEncoding.


getUsedEncoding

public java.lang.String getUsedEncoding()
Returns the actually used encoding.


setEncoding

public void setEncoding(java.lang.String encoding)
Sets the character encoding. Any unsupported encoding will be treated as UNKNOWN-8BIT. If the value is null, the reader tries to auto-detect the encoding.

Parameters:
encoding - the encoding

skipWhitespace

public void skipWhitespace()
                    throws java.io.IOException
Moves the reader before the next non-whitespace char.

Throws:
java.io.IOException

skipChars

public void skipChars(int count)
               throws java.io.IOException
Skips n chars.

Throws:
java.io.IOException

nextChar

public char nextChar()
              throws java.io.IOException
Reads and returns the next char.

Throws:
java.io.IOException

hasNextChar

public boolean hasNextChar()
Returns true if there are more chars to read.


getChar

public char getChar(int i)
Returns the ith char from the buffer.

Returns:
the ith char from the buffer or EOF_CHAR

getLineNumber

public int getLineNumber()