1 |
/* Reader.java -- base class of classes that read input as a stream of chars |
/* Reader.java -- base class of classes that read input as a stream of chars |
2 |
Copyright (C) 1998, 1999, 2000, 2003, 2004 Free Software Foundation |
Copyright (C) 1998, 1999, 2000, 2003, 2004, 2005 Free Software Foundation |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
37 |
|
|
38 |
package java.io; |
package java.io; |
39 |
|
|
40 |
|
import java.nio.CharBuffer; |
41 |
|
|
42 |
/* Written using "Java Class Libraries", 2nd edition, plus online |
/* Written using "Java Class Libraries", 2nd edition, plus online |
43 |
* API docs for JDK 1.2 beta from http://www.javasoft.com. |
* API docs for JDK 1.2 beta from http://www.javasoft.com. |
44 |
* Status: Believed complete and correct. |
* Status: Believed complete and correct. |
55 |
* @date April 21, 1998. |
* @date April 21, 1998. |
56 |
* @author Aaron M. Renn (arenn@urbanophile.com) |
* @author Aaron M. Renn (arenn@urbanophile.com) |
57 |
*/ |
*/ |
58 |
public abstract class Reader implements Closeable |
public abstract class Reader implements Closeable, Readable |
59 |
{ |
{ |
60 |
/** |
/** |
61 |
* This is the <code>Object</code> used for synchronizing critical code |
* This is the <code>Object</code> used for synchronizing critical code |
154 |
return count > 0 ? buf[0] : -1; |
return count > 0 ? buf[0] : -1; |
155 |
} |
} |
156 |
|
|
157 |
|
/** @since 1.5 */ |
158 |
|
public int read(CharBuffer buffer) throws IOException |
159 |
|
{ |
160 |
|
// We want to call put(), so we don't manipulate the CharBuffer |
161 |
|
// directly. |
162 |
|
int rem = buffer.remaining(); |
163 |
|
char[] buf = new char[rem]; |
164 |
|
int result = read(buf, 0, rem); |
165 |
|
if (result != -1) |
166 |
|
buffer.put(buf, 0, result); |
167 |
|
return result; |
168 |
|
} |
169 |
|
|
170 |
/** |
/** |
171 |
* Closes the stream. Any futher attempts to read from the |
* Closes the stream. Any futher attempts to read from the |
172 |
* stream may generate an <code>IOException</code>. |
* stream may generate an <code>IOException</code>. |