com.caucho.vfs
Class AbstractByteToChar

java.lang.Object
  extended by java.io.InputStream
      extended by com.caucho.vfs.AbstractByteToChar
All Implemented Interfaces:
java.io.Closeable
Direct Known Subclasses:
ByteToChar, ByteToCharWriter

public abstract class AbstractByteToChar
extends java.io.InputStream

Utility class for converting a byte stream to a character stream.

 ByteToChar converter = new ByteToChar();
 converter.setEncoding("utf-8");
 converter.clear();

 converter.addChar('H');
 converter.addByte(0xc0);
 converter.addByte(0xb8);

 String value = converter.getConvertedString();
 


Method Summary
 void addByte(int b)
          Adds the next byte.
 void addChar(char nextCh)
          Adds the next character.
 void clear()
          Clears the converted
 void flush()
          Flushes the buffer.
protected abstract  void outputChar(int ch)
           
 int read()
          For internal use only.
 void setEncoding(java.lang.String encoding)
          Sets the encoding for the converter.
 
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setEncoding

public void setEncoding(java.lang.String encoding)
                 throws java.io.UnsupportedEncodingException
Sets the encoding for the converter.

Throws:
java.io.UnsupportedEncodingException

clear

public void clear()
Clears the converted


addByte

public void addByte(int b)
             throws java.io.IOException
Adds the next byte.

Parameters:
b - the byte to write
Throws:
java.io.IOException

addChar

public void addChar(char nextCh)
             throws java.io.IOException
Adds the next character.

Parameters:
nextCh - the character to write
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Flushes the buffer.

Throws:
java.io.IOException

read

public int read()
         throws java.io.IOException
For internal use only. Reads the next byte from the byte buffer.

Specified by:
read in class java.io.InputStream
Returns:
the next byte
Throws:
java.io.IOException

outputChar

protected abstract void outputChar(int ch)
                            throws java.io.IOException
Throws:
java.io.IOException