java.io

Class InputStreamReader

Implemented Interfaces:
Closeable, Readable
Known Direct Subclasses:
FileReader

public class InputStreamReader
extends Reader

An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset. The charset that it uses may be specified by name or may be given explicitly, or the platform's default charset may be accepted.

Each invocation of one of an InputStreamReader's read() methods may cause one or more bytes to be read from the underlying byte-input stream. To enable the efficient conversion of bytes to characters, more bytes may be read ahead from the underlying stream than are necessary to satisfy the current read operation.

For top efficiency, consider wrapping an InputStreamReader within a BufferedReader. For example:

 BufferedReader in
   = new BufferedReader(new InputStreamReader(System.in));
 
Since:
JDK1.1
See Also:
BufferedReader, InputStream, Charset

Field Summary

Fields inherited from class java.io.Reader

lock

Constructor Summary

InputStreamReader(InputStream in)
Create an InputStreamReader that uses the default charset.
InputStreamReader(InputStream in, String charsetName)
Create an InputStreamReader that uses the named charset.
InputStreamReader(InputStream in, Charset cs)
Create an InputStreamReader that uses the given charset.
InputStreamReader(InputStream in, CharsetDecoder dec)
Create an InputStreamReader that uses the given charset decoder.

Method Summary

void
close()
Close the stream.
String
getEncoding()
Return the name of the character encoding being used by this stream.
int
read()
Read a single character.
int
read(cbuf[] , int offset, int length)
Read characters into a portion of an array.
boolean
ready()
Tell whether this stream is ready to be read.

Methods inherited from class java.io.Reader

close, mark, markSupported, read, read, read, read, ready, reset, skip

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

InputStreamReader

public InputStreamReader(InputStream in)
Create an InputStreamReader that uses the default charset.
Parameters:
in - An InputStream
Usages and Demos :

View More Examples of InputStreamReader(InputStream in)
   1:                 } else {
   2:                     return new BufferedReader(new InputStreamReader(((URL)input).openStream(), encoding));
   3:                 }
   4:             } else {
   5:                 throw new IllegalArgumentException(String.valueOf(input));

View Full Code Here
   1:         if (obj instanceof InputStream) {
   2:             return new InputStreamReader((InputStream)obj);
   3:         } else if (obj instanceof Reader) {
   4:             return (Reader)obj;
   5:         } else if (obj instanceof String) {

View Full Code Here
   1:       InputStream is = new FileInputStream(file);
   2:       Reader reader = new InputStreamReader((decompress != null)?decompress.decompress(is):is);
   3: 
   4:       for (TXDocument topic = parser.nextDocument(reader); topic != null; topic = parser.nextDocument(reader))
   5:       {

View Full Code Here
   1:           InputStream is = new FileInputStream(file);
   2:           Reader reader = new InputStreamReader((decompress != null)?decompress.decompress(is):is);
   3:           int reg = tblLocations.append();
   4:           tblLocations.writeField("location",file);
   5:           tblLocations.submit();

View Full Code Here
   1: 
   2:         StreamTokenizer st = new StreamTokenizer(new InputStreamReader((InputStream)is));
   3: 
   4:         ...
   5:     FileInputStream fis = new FileInputStream(file);
   6:     LineNumberReader lnr = new LineNumberReader(new InputStreamReader(fis));
   7: 
   8:     lnr.skip(fis.available());

View Full Code Here

InputStreamReader

public InputStreamReader(InputStream in,
                         String charsetName)
            throws UnsupportedEncodingException
Create an InputStreamReader that uses the named charset.
Parameters:
in - An InputStream
charsetName - The name of a supported charset
Throws:
UnsupportedEncodingException - If the named charset is not supported
Usages and Demos :

View More Examples of InputStreamReader(InputStream in,String charsetName)
   1:   {
   2:     InputStreamReader reader = new InputStreamReader(Jext.getLanguageStream(fileName, file));
   3:     XBarHandler xmh = new XBarHandler(parent);
   4:     XmlParser parser = new XmlParser();
   5:     parser.setHandler(xmh);

View Full Code Here
   1:   {
   2:     InputStreamReader reader = new InputStreamReader(Jext.getLanguageStream(fileName, file));
   3: 
   4:     XMenuHandler xmh = new XMenuHandler(parent);
   5:     XmlParser parser = new XmlParser();

View Full Code Here
   1:   {
   2:     InputStreamReader reader = new InputStreamReader(Jext.getLanguageStream(fileName, file));
   3: 
   4:     XPopupHandler xmh = new XPopupHandler();
   5:     XmlParser parser = new XmlParser();

View Full Code Here
   1:     DammedInputStream dais = new DammedInputStream(dis, n);
   2:     InputStreamReader reader = new InputStreamReader(dais, "UTF-8");
   3:     StringBuilder q = new StringBuilder();
   4:     int n2;
   5:     while ((n2 = reader.read(wad, 0, wad.length)) > -1) q.append(wad, 0, n2);

View Full Code Here
   1:   {
   2:      this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
   3:   }
   4:         ...
   5:   {
   6:      ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
   7:   }
   8: 
   9:   public void ReInit(java.io.InputStream dstream, int startline,

View Full Code Here

InputStreamReader

public InputStreamReader(InputStream in,
                         Charset cs)
Create an InputStreamReader that uses the given charset.
Parameters:
in - An InputStream
cs - A charset
Since:
1.4
Usages and Demos :

View More Examples of InputStreamReader(InputStream in,Charset cs)
   1:   {
   2:     InputStreamReader reader = new InputStreamReader(Jext.getLanguageStream(fileName, file));
   3:     XBarHandler xmh = new XBarHandler(parent);
   4:     XmlParser parser = new XmlParser();
   5:     parser.setHandler(xmh);

View Full Code Here
   1:   {
   2:     InputStreamReader reader = new InputStreamReader(Jext.getLanguageStream(fileName, file));
   3: 
   4:     XMenuHandler xmh = new XMenuHandler(parent);
   5:     XmlParser parser = new XmlParser();

View Full Code Here
   1:   {
   2:     InputStreamReader reader = new InputStreamReader(Jext.getLanguageStream(fileName, file));
   3: 
   4:     XPopupHandler xmh = new XPopupHandler();
   5:     XmlParser parser = new XmlParser();

View Full Code Here
   1:     DammedInputStream dais = new DammedInputStream(dis, n);
   2:     InputStreamReader reader = new InputStreamReader(dais, "UTF-8");
   3:     StringBuilder q = new StringBuilder();
   4:     int n2;
   5:     while ((n2 = reader.read(wad, 0, wad.length)) > -1) q.append(wad, 0, n2);

View Full Code Here
   1:   {
   2:      this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
   3:   }
   4:         ...
   5:   {
   6:      ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
   7:   }
   8: 
   9:   public void ReInit(java.io.InputStream dstream, int startline,

View Full Code Here

InputStreamReader

public InputStreamReader(InputStream in,
                         CharsetDecoder dec)
Create an InputStreamReader that uses the given charset decoder.
Parameters:
in - An InputStream
dec - A charset decoder
Since:
1.4
Usages and Demos :

View More Examples of InputStreamReader(InputStream in,CharsetDecoder dec)
   1:   {
   2:     InputStreamReader reader = new InputStreamReader(Jext.getLanguageStream(fileName, file));
   3:     XBarHandler xmh = new XBarHandler(parent);
   4:     XmlParser parser = new XmlParser();
   5:     parser.setHandler(xmh);

View Full Code Here
   1:   {
   2:     InputStreamReader reader = new InputStreamReader(Jext.getLanguageStream(fileName, file));
   3: 
   4:     XMenuHandler xmh = new XMenuHandler(parent);
   5:     XmlParser parser = new XmlParser();

View Full Code Here
   1:   {
   2:     InputStreamReader reader = new InputStreamReader(Jext.getLanguageStream(fileName, file));
   3: 
   4:     XPopupHandler xmh = new XPopupHandler();
   5:     XmlParser parser = new XmlParser();

View Full Code Here
   1:     DammedInputStream dais = new DammedInputStream(dis, n);
   2:     InputStreamReader reader = new InputStreamReader(dais, "UTF-8");
   3:     StringBuilder q = new StringBuilder();
   4:     int n2;
   5:     while ((n2 = reader.read(wad, 0, wad.length)) > -1) q.append(wad, 0, n2);

View Full Code Here
   1:   {
   2:      this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
   3:   }
   4:         ...
   5:   {
   6:      ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
   7:   }
   8: 
   9:   public void ReInit(java.io.InputStream dstream, int startline,

View Full Code Here

Method Details

close

public void close()
            throws IOException
Close the stream.
Specified by:
close in interface Closeable
Overrides:
close in interface Reader
Throws:
IOException - If an I/O error occurs
Usages and Demos :

View More Examples of close()
   1: 
   2:       InputStreamReader isr = 
   3:         ...
   4:         new InputStreamReader(System.in);
   5: 
   6:         ...
   7: 
   8:       isr.close();
   9:     }

View Full Code Here
   1:              FileInputStream fis = new FileInputStream("file1.txt");
   2:              InputStreamReader dis = new InputStreamReader(fis);
   3:              BufferedReader reader = new BufferedReader(dis);
   4:         ...
   5:              }
   6:              dis.close();
   7:          }catch(IOException e)
   8:          {
   9:              System.out.println(e);

View Full Code Here
   1: 
   2:       InputStreamReader isr = new InputStreamReader(System.in);
   3: 
   4:         ...
   5: 
   6:       isr.close();
   7:     }
   8:     catch(Exception e) {
   9:       System.out.println("Exception: " + e);

View Full Code Here
   1:   {
   2:     InputStreamReader reader = new InputStreamReader(Jext.getLanguageStream(fileName, file));
   3:     XBarHandler xmh = new XBarHandler(parent);
   4:         ...
   5:     {
   6:       fileName.close();
   7:         ...
   8:       reader.close();
   9:     } catch (IOException ioe) { }

View Full Code Here
   1:   {
   2:     InputStreamReader reader = new InputStreamReader(Jext.getLanguageStream(fileName, file));
   3: 
   4:         ...
   5:     {
   6:       fileName.close();
   7:         ...
   8:       reader.close();
   9:     } catch (IOException ioe) { }

View Full Code Here

getEncoding

public String getEncoding()
Return the name of the character encoding being used by this stream.

If the encoding has an historical name then that name is returned; otherwise the encoding's canonical name is returned.

If this instance was created with the InputStreamReader(InputStream,String) constructor then the returned name, being unique for the encoding, may differ from the name passed to the constructor. This method may return null if the stream has been closed.

Returns:
The historical name of this encoding, or possibly null if the stream has been closed
See Also:
Charset
Usages and Demos :

View More Examples of getEncoding()
   1: {
   2:   private InputStreamReader delegate_;
   3: 
   4:         ...
   5:     try
   6:       { delegate_=new InputStreamReader(_file.delegate_.getInputStream()); }
   7:     catch(IOException ex2)
   8:         ...
   9:   {
  10:     return delegate_.getEncoding();
  11:   }

View Full Code Here
   1: import java.io.InputStream;
   2: import java.io.InputStreamReader;
   3: import java.io.PushbackInputStream;
   4:         ...
   5: 
   6:   private final InputStreamReader internalInputStreamReader;
   7:   private final String defaultEnc;
   8:         ...
   9:     if (encoding == null) {
  10:       internalInputStreamReader = new InputStreamReader(pushbackStream);
  11:     } else {
  12:         ...
  13:   public String getEncoding() {
  14:     return internalInputStreamReader.getEncoding();

View Full Code Here
   1:     static {
   2:         InputStreamReader reader = new InputStreamReader(new ByteArrayInputStream(new byte[2])); 
   3:         ...
   4:         defaultEncoding = reader.getEncoding();
   5:         try {
   6:             reader.close();
   7:         }

View Full Code Here
   1: import java.io.InputStream;
   2: import java.io.InputStreamReader;
   3: import java.io.OutputStream;
   4:         ...
   5: 
   6:     public static Charset determineCharset(final InputStreamReader reader) {
   7:         ...
   8:         return Charset.forName(reader.getEncoding());
   9:     }
  10:         ...
  11: 
  12:     public static String determineCharsetName(final InputStreamReader reader) {

View Full Code Here
   1: import java.io.InputStream;
   2: import java.io.InputStreamReader;
   3: import java.io.Reader;
   4:         ...
   5:     public String getDefaultEncoding() {
   6:         InputStreamReader is = new InputStreamReader(
   7:             new InputStream() {
   8:         ...
   9:         try {
  10:             return is.getEncoding();
  11:         } finally {

View Full Code Here

read

public int read()
            throws IOException
Read a single character.
Overrides:
read in interface Reader
Returns:
The character read, or -1 if the end of the stream has been reached
Throws:
IOException - If an I/O error occurs
Usages and Demos :

View More Examples of read()
   1:       InputStream in = new BufferedInputStream(u.openStream());
   2:       InputStreamReader theHTML = new InputStreamReader(in);
   3:       int c;
   4:         ...
   5:       while ((c = theHTML.read()) != -1) {
   6:         System.out.print((char) c);
   7:       } 
   8:     }

View Full Code Here
   1: import java.io.IOException;
   2: import java.io.InputStreamReader;
   3: 
   4:         ...
   5:     
   6:     private final InputStreamReader _reader;
   7:     
   8:         ...
   9:     public ReaderAnnotationScanner(final InputStreamReader reader) {
  10:         _reader = reader;
  11:         ...
  12:     protected int getNext() throws IOException {
  13:         return _reader.read();

View Full Code Here
   1:       BufferedInputStream buffer = new BufferedInputStream(raw);
   2:       InputStreamReader in = new InputStreamReader(buffer, "8859_1");
   3:       int c; 
   4:         ...
   5:       while ((c = in.read()) != -1) {
   6:         if ((c >= 32 && c < 127) || c == '\t' || c == '\r' || c == '\n') { 
   7:           System.out.write(c);
   8:         }

View Full Code Here
   1: {
   2:   private InputStreamReader delegate_;
   3: 
   4:         ...
   5:     try
   6:       { delegate_=new InputStreamReader(_file.delegate_.getInputStream()); }
   7:     catch(IOException ex2)
   8:         ...
   9:   {
  10:     return delegate_.read();
  11:   }

View Full Code Here
   1:     
   2:       InputStreamReader r = new InputStreamReader(in);
   3:       int c;
   4:         ...
   5:       while((c = r.read()) != -1) {
   6:         System.out.print((char) c);
   7:       }
   8:       System.out.println();

View Full Code Here

read

public int read(cbuf[] ,
                int offset,
                int length)
            throws IOException
Read characters into a portion of an array.
Overrides:
read in interface Reader
Parameters:
offset - Offset at which to start storing characters
length - Maximum number of characters to read
Returns:
The number of characters read, or -1 if the end of the stream has been reached
Throws:
IOException - If an I/O error occurs
Usages and Demos :

View More Examples of read(cbuf[] ,int offset,int length)
   1: {
   2:   private InputStreamReader delegate_;
   3: 
   4:         ...
   5:     try
   6:       { delegate_=new InputStreamReader(_file.delegate_.getInputStream()); }
   7:     catch(IOException ex2)
   8:         ...
   9:   {
  10:     return delegate_.read(_b,_off,_len);
  11:   }

View Full Code Here
   1: import java.io.InputStream;
   2: import java.io.InputStreamReader;
   3: import java.io.PushbackInputStream;
   4:         ...
   5: 
   6:   private final InputStreamReader internalInputStreamReader;
   7:   private final String defaultEnc;
   8:         ...
   9:     PushbackInputStream pushbackStream = new PushbackInputStream(in, BOM_SIZE);
  10:     n = pushbackStream.read(bom, 0, bom.length);
  11: 
  12:         ...
  13:     if (encoding == null) {
  14:       internalInputStreamReader = new InputStreamReader(pushbackStream);

View Full Code Here
   1: import java.io.InputStream;
   2: import java.io.InputStreamReader;
   3: import java.io.UnsupportedEncodingException;
   4:         ...
   5:     {
   6:         InputStreamReader isr = null;
   7:         try
   8:         ...
   9:         {
  10:              isr = new InputStreamReader(in, jEdit.getProperty("console.encoding") );
  11:         }
  12:         ...
  13:             {
  14:                 int read = isr.read(input, 0, input.length);

View Full Code Here
   1:     String enc = null;
   2:     InputStreamReader is = null;
   3:     
   4:         ...
   5:         enc = getCharset(ds.getContentType());
   6:         is = new InputStreamReader(ds.getInputStream(), enc);
   7:     } catch (IllegalArgumentException iex) {
   8:         ...
   9: 
  10:     while ((count = is.read(buf, pos, buf.length - pos)) != -1) {
  11:         pos += count;

View Full Code Here
   1:     String enc = null;
   2:     InputStreamReader is = null;
   3:     
   4:         ...
   5:         enc = getCharset(ds.getContentType());
   6:         is = new InputStreamReader(ds.getInputStream(), enc);
   7:     } catch (IllegalArgumentException iex) {
   8:         ...
   9: 
  10:     while ((count = is.read(buf, pos, buf.length - pos)) != -1) {
  11:         pos += count;

View Full Code Here

ready

public boolean ready()
            throws IOException
Tell whether this stream is ready to be read. An InputStreamReader is ready if its input buffer is not empty, or if bytes are available to be read from the underlying byte stream.
Overrides:
ready in interface Reader
Throws:
IOException - If an I/O error occurs
Usages and Demos :

View More Examples of ready()
   1: {
   2:   private InputStreamReader delegate_;
   3: 
   4:         ...
   5:     try
   6:       { delegate_=new InputStreamReader(_file.delegate_.getInputStream()); }
   7:     catch(IOException ex2)
   8:         ...
   9:   {
  10:     return delegate_.ready();
  11:   }

View Full Code Here
   1: public class CapaEngine {
   2:     private InputStreamReader reader;
   3:     private PrintStream writer;
   4:         ...
   5:         this.player = player;
   6:         this.reader = new InputStreamReader(System.in);
   7:         this.writer = System.out;
   8:         ...
   9:     
  10:     private static char readChar(InputStreamReader reader) throws IOException {
  11:         ...
  12:         while(!reader.ready()) {

View Full Code Here
   1:    OutputStreamWriter outWrite ;
   2:    InputStreamReader erRead ;
   3:         ...
   4:    InputStreamReader ipRead ;
   5:    JTextArea jtf ;
   6:         ...
   7:       InputStream inputStr = process.getInputStream() ;
   8:       ipRead = new InputStreamReader( inputStr ) ;
   9:       erRead = new InputStreamReader( errorStr ) ;
  10:         ...
  11:                   {
  12:                      if ( erRead.ready() )

View Full Code Here
   1:     private OutputStreamWriter netOut;
   2:     private InputStreamReader netInReader;
   3:     private String address;
   4:         ...
   5:                         ServerModule.DEFAULT_ENCODING);
   6:         netInReader = new InputStreamReader(socket.getInputStream());
   7:         
   8:         ...
   9:         synchronized(this) {
  10:             while(reconnect || !netInReader.ready()) {
  11:             if(reconnect) {

View Full Code Here
   1:     private boolean        closed;
   2:     private InputStreamReader    in;
   3: 
   4:         ...
   5: 
   6:     return new InputStreamReader (in, encoding);
   7:     }
   8:         ...
   9:     if (in != null)
  10:         return in.ready();
  11:     return (length > offset) || raw.available () != 0;

View Full Code Here