1 7 8 package java.io; 9 10 import java.nio.charset.Charset ; 11 import java.nio.charset.CharsetDecoder ; 12 import sun.nio.cs.StreamDecoder; 13 14 15 44 45 public class InputStreamReader extends Reader { 46 47 private final StreamDecoder sd; 48 49 54 public InputStreamReader(InputStream in) { 55 super(in); 56 try { 57 sd = StreamDecoder.forInputStreamReader(in, this, (String )null); } catch (UnsupportedEncodingException e) { 59 throw new Error (e); 61 } 62 } 63 64 77 public InputStreamReader(InputStream in, String charsetName) 78 throws UnsupportedEncodingException 79 { 80 super(in); 81 if (charsetName == null) 82 throw new NullPointerException ("charsetName"); 83 sd = StreamDecoder.forInputStreamReader(in, this, charsetName); 84 } 85 86 95 public InputStreamReader(InputStream in, Charset cs) { 96 super(in); 97 if (cs == null) 98 throw new NullPointerException ("charset"); 99 sd = StreamDecoder.forInputStreamReader(in, this, cs); 100 } 101 102 111 public InputStreamReader(InputStream in, CharsetDecoder dec) { 112 super(in); 113 if (dec == null) 114 throw new NullPointerException ("charset decoder"); 115 sd = StreamDecoder.forInputStreamReader(in, this, dec); 116 } 117 118 138 public String getEncoding() { 139 return sd.getEncoding(); 140 } 141 142 150 public int read() throws IOException { 151 return sd.read(); 152 } 153 154 166 public int read(char cbuf[], int offset, int length) throws IOException { 167 return sd.read(cbuf, offset, length); 168 } 169 170 177 public boolean ready() throws IOException { 178 return sd.ready(); 179 } 180 181 186 public void close() throws IOException { 187 sd.close(); 188 } 189 190 } 191 | Popular Tags |