Index: /src/main/java/java/io/Reader.java
===================================================================
--- /src/main/java/java/io/Reader.java (revision 388015)
+++ /src/main/java/java/io/Reader.java (working copy)
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
package java.io;
+import java.nio.CharBuffer;
/**
* Reader is an Abstract class for reading Character Streams. Subclasses of
@@ -23,7 +24,7 @@
*
* @see Writer
*/
-public abstract class Reader {
+public abstract class Reader implements Readable, Closeable {
/**
* The object used to syncronize access to the reader.
*/
@@ -227,4 +228,33 @@
}
throw new IllegalArgumentException();
}
+
+ /**
+ * Read chars from the Reader and then put them to the target
+ * CharBuffer. Only put method is called on the target.
+ *
+ * @param target
+ * the destination CharBuffer
+ * @return the actual number of chars put to the target. -1
+ * when the Reader has reached the end before the method is called.
+ * @throws IOException
+ * if any I/O error raises in the procedure
+ * @throws NullPointerException
+ * if the target CharBuffer is null
+ * @throws ReadOnlyBufferException
+ * if the target CharBuffer is readonly
+ *
+ */
+ public int read(CharBuffer target) throws IOException {
+ if (null == target) {
+ throw new NullPointerException();
+ }
+ int length = target.length();
+ char[] buf = new char[length];
+ length = Math.min(length, read(buf));
+ if (length > 0) {
+ target.put(buf, 0, length);
+ }
+ return length;
+ }
}
Index: /src/main/java/java/io/Closeable.java
===================================================================
--- /src/main/java/java/io/Closeable.java (revision 388015)
+++ /src/main/java/java/io/Closeable.java (working copy)
@@ -15,6 +15,18 @@
package java.io;
+/**
+ * Closeable represents the source or destination of some data which can be
+ * called its close method to release resources it holds.
+ */
public interface Closeable {
- public void close() throws IOException;
+
+ /**
+ * Close the object and release any system resources it holds. If the object
+ * has been close, then invoke this method has no effect.
+ *
+ * @throws IOException
+ * if any error raises when closing the object.
+ */
+ public void close() throws IOException;
}
\ No newline at end of file
Index: /src/main/java/java/io/InputStream.java
===================================================================
--- /src/main/java/java/io/InputStream.java (revision 388015)
+++ /src/main/java/java/io/InputStream.java (working copy)
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@
*
* @see OutputStream
*/
-public abstract class InputStream extends Object {
+public abstract class InputStream extends Object implements Closeable {
private static byte[] skipBuf;
Index: /src/main/java/java/io/OutputStream.java
===================================================================
--- /src/main/java/java/io/OutputStream.java (revision 388015)
+++ /src/main/java/java/io/OutputStream.java (working copy)
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@
* @see InputStream
*/
-public abstract class OutputStream {
+public abstract class OutputStream implements Closeable,Flushable{
/**
* This constructor does nothing interesting. Provided for signature
* compatibility.