1 /* Copyright (C) 1998, 1999 Cygnus Solutions
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
10 import gnu
.gcj
.convert
.*;
13 * @author Per Bothner <bothner@cygnus.com>
14 * @date April 22, 1998.
16 /* Written using "Java Class Libraries", 2nd edition, plus online
17 * API docs for JDK 1.2 beta from http://www.javasoft.com.
18 * Status: Believed complete and correct, but only supports 8859_1.
21 public class InputStreamReader
extends Reader
23 BufferedInputStream in
;
25 // Buffer of chars read from in and converted but not consumed.
27 // Next available character (in work buffer) to read.
29 // Last available character (in work buffer) to read.
32 BytesToUnicode converter
;
34 public InputStreamReader(InputStream in
)
36 this(in
, BytesToUnicode
.getDefaultDecoder());
39 public InputStreamReader(InputStream in
, String enc
)
40 throws UnsupportedEncodingException
42 this(in
, BytesToUnicode
.getDecoder(enc
));
45 private InputStreamReader(InputStream in
, BytesToUnicode decoder
)
47 super((this.in
= (in
instanceof BufferedInputStream
48 ?
(BufferedInputStream
) in
49 : new BufferedInputStream(in
, 250))));
51 converter
.setInput(this.in
.buf
, 0, 0);
54 public void close() throws IOException
66 public String
getEncoding() { return converter
.getName(); }
68 public boolean ready() throws IOException
82 if (in
.available() <= 0)
89 converter
.setInput(in
.buf
, in
.pos
, in
.count
);
91 wcount
= converter
.read(work
, 0, work
.length
);
92 in
.skip(converter
.inpos
- in
.pos
);
99 public int read(char buf
[], int offset
, int length
) throws IOException
103 int wavail
= wcount
- wpos
;
108 System
.arraycopy(work
, wpos
, buf
, offset
, length
);
123 converter
.setInput(in
.buf
, in
.pos
, in
.count
);
124 int count
= converter
.read (buf
, offset
, length
);
125 in
.skip(converter
.inpos
- in
.pos
);
133 public int read() throws IOException
137 int wavail
= wcount
- wpos
;
142 work
= new char[100];
146 else if (wavail
== 0)
151 int count
= read(work
, wpos
, work
.length
-wpos
);
154 wcount
= wpos
+ count
;