Team LiB
Previous Section Next Section

Java 1.1readable closeable

This class is a character input stream that uses a byte input stream as its data source. It reads bytes from a specified InputStream and translates them into Unicode characters according to a particular platform- and locale-dependent character encoding. This is an important internationalization feature in Java 1.1 and later. InputStreamReader supports the standard Reader methods. It also has a getEncoding( ) method that returns the name of the encoding being used to convert bytes to characters.

When you create an InputStreamReader, you specify an InputStream from which the InputStreamReader is to read bytes and, optionally, the name of the character encoding used by those bytes. If you do not specify an encoding name, the InputStreamReader uses the default encoding for the default locale, which is usually the correct thing to do. In Java 1.4 and later, this class uses the charset conversion facilities of the java.nio.charset package and allows you to explicitly specify the Charset or CharsetDecoder to be used. Prior to Java 1.4, the class allows you to specify only the name of the desired charset encoding.

Figure 9-26.

public class InputStreamReader extends Reader {
// Public Constructors
     public InputStreamReader(InputStream in);  
     public InputStreamReader(InputStream in, String charsetName) throws 
1.4  public InputStreamReader(InputStream in, java.nio.charset.Charset cs);  
1.4  public InputStreamReader(InputStream in, java.nio.charset.CharsetDecoder dec);  
// Public Instance Methods
     public String getEncoding( );  
// Public Methods Overriding Reader
     public void close( ) throws IOException;  
     public int read( ) throws IOException;  
     public int read(char[ ] cbuf, int offset, int length) throws IOException;  
     public boolean ready( ) throws IOException;  



    Team LiB
    Previous Section Next Section