[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] [generics] Patch: FYI: java.io fixes
From: |
Tom Tromey |
Subject: |
[cp-patches] [generics] Patch: FYI: java.io fixes |
Date: |
20 Apr 2005 14:25:34 -0600 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 |
I'm checking this in on the generics branch.
This fixes a few problems in java.io that were found by japi.
Tom
2005-04-20 Tom Tromey <address@hidden>
* java/io/PrintStream.java (append): Don't throw IOException.
* java/io/StringWriter.java (append): New overloads.
* java/io/PrintWriter.java (append): New overloads.
(PrintWriter): New constructors.
* java/io/CharArrayWriter.java (append): New overloads.
* java/io/RandomAccessFile.java (RandomAccessFile): Implements
Closeable.
* java/io/Reader.java (Reader): Implements Readable.
(read): New method.
Index: java/io/CharArrayWriter.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/CharArrayWriter.java,v
retrieving revision 1.9.2.2
diff -u -r1.9.2.2 CharArrayWriter.java
--- java/io/CharArrayWriter.java 19 Feb 2005 10:50:35 -0000 1.9.2.2
+++ java/io/CharArrayWriter.java 20 Apr 2005 20:15:28 -0000
@@ -242,6 +242,41 @@
}
}
+ /** @since 1.5 */
+ public CharArrayWriter append(char c)
+ {
+ write(c);
+ return this;
+ }
+
+ /** @since 1.5 */
+ public CharArrayWriter append(CharSequence cs)
+ {
+ try
+ {
+ write(cs == null ? "null" : cs.toString());
+ }
+ catch (IOException _)
+ {
+ // Can't happen.
+ }
+ return this;
+ }
+
+ /** @since 1.5 */
+ public CharArrayWriter append(CharSequence cs, int start, int end)
+ {
+ try
+ {
+ write(cs == null ? "null" : cs.subSequence(start, end).toString());
+ }
+ catch (IOException _)
+ {
+ // Can't happen.
+ }
+ return this;
+ }
+
/**
* This private method makes the buffer bigger when we run out of room
* by allocating a larger buffer and copying the valid chars from the
Index: java/io/PrintStream.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/PrintStream.java,v
retrieving revision 1.19.2.5
diff -u -r1.19.2.5 PrintStream.java
--- java/io/PrintStream.java 18 Apr 2005 01:37:37 -0000 1.19.2.5
+++ java/io/PrintStream.java 20 Apr 2005 20:15:28 -0000
@@ -580,14 +580,14 @@
}
/** @since 1.5 */
- public PrintStream append(char c) throws IOException
+ public PrintStream append(char c)
{
print(c);
return this;
}
/** @since 1.5 */
- public PrintStream append(CharSequence cs) throws IOException
+ public PrintStream append(CharSequence cs)
{
print(cs == null ? "null" : cs.toString());
return this;
@@ -595,7 +595,6 @@
/** @since 1.5 */
public PrintStream append(CharSequence cs, int start, int end)
- throws IOException
{
print(cs == null ? "null" : cs.subSequence(start, end).toString());
return this;
Index: java/io/PrintWriter.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/PrintWriter.java,v
retrieving revision 1.13.2.1
diff -u -r1.13.2.1 PrintWriter.java
--- java/io/PrintWriter.java 19 Feb 2005 10:50:35 -0000 1.13.2.1
+++ java/io/PrintWriter.java 20 Apr 2005 20:15:28 -0000
@@ -1,5 +1,5 @@
/* PrintWriter.java -- prints primitive values and objects to a stream as text
- Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
+ Copyright (C) 1998, 1999, 2000, 2001, 2005 Free Software Foundation
This file is part of GNU Classpath.
@@ -138,6 +138,34 @@
this.autoflush = autoflush;
}
+ /** @since 1.5 */
+ public PrintWriter(String path)
+ throws FileNotFoundException
+ {
+ this(new OutputStreamWriter(new FileOutputStream(path)));
+ }
+
+ /** @since 1.5 */
+ public PrintWriter(String path, String encoding)
+ throws FileNotFoundException, UnsupportedEncodingException
+ {
+ this(new OutputStreamWriter(new FileOutputStream(path), encoding));
+ }
+
+ /** @since 1.5 */
+ public PrintWriter(File path)
+ throws FileNotFoundException
+ {
+ this(new OutputStreamWriter(new FileOutputStream(path)));
+ }
+
+ /** @since 1.5 */
+ public PrintWriter(File path, String encoding)
+ throws FileNotFoundException, UnsupportedEncodingException
+ {
+ this(new OutputStreamWriter(new FileOutputStream(path), encoding));
+ }
+
/**
* This method can be called by subclasses to indicate that an error
* has occurred and should be reported by <code>checkError</code>.
@@ -567,5 +595,26 @@
{
write(str, 0, str.length());
}
+
+ /** @since 1.5 */
+ public PrintWriter append(char c)
+ {
+ write(c);
+ return this;
+ }
+
+ /** @since 1.5 */
+ public PrintWriter append(CharSequence cs)
+ {
+ write(cs == null ? "null" : cs.toString());
+ return this;
+ }
+
+ /** @since 1.5 */
+ public PrintWriter append(CharSequence cs, int start, int end)
+ {
+ write(cs == null ? "null" : cs.subSequence(start, end).toString());
+ return this;
+ }
}
Index: java/io/RandomAccessFile.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/RandomAccessFile.java,v
retrieving revision 1.41.2.3
diff -u -r1.41.2.3 RandomAccessFile.java
--- java/io/RandomAccessFile.java 19 Feb 2005 10:50:35 -0000 1.41.2.3
+++ java/io/RandomAccessFile.java 20 Apr 2005 20:15:29 -0000
@@ -58,7 +58,7 @@
* @author Aaron M. Renn (address@hidden)
* @author Tom Tromey (address@hidden)
*/
-public class RandomAccessFile implements DataOutput, DataInput
+public class RandomAccessFile implements DataOutput, DataInput, Closeable
{
// The underlying file.
Index: java/io/Reader.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/Reader.java,v
retrieving revision 1.9.2.3
diff -u -r1.9.2.3 Reader.java
--- java/io/Reader.java 19 Feb 2005 10:50:35 -0000 1.9.2.3
+++ java/io/Reader.java 20 Apr 2005 20:15:29 -0000
@@ -1,5 +1,5 @@
/* Reader.java -- base class of classes that read input as a stream of chars
- Copyright (C) 1998, 1999, 2000, 2003, 2004 Free Software Foundation
+ Copyright (C) 1998, 1999, 2000, 2003, 2004, 2005 Free Software Foundation
This file is part of GNU Classpath.
@@ -37,6 +37,8 @@
package java.io;
+import java.nio.CharBuffer;
+
/* Written using "Java Class Libraries", 2nd edition, plus online
* API docs for JDK 1.2 beta from http://www.javasoft.com.
* Status: Believed complete and correct.
@@ -53,7 +55,7 @@
* @date April 21, 1998.
* @author Aaron M. Renn (address@hidden)
*/
-public abstract class Reader implements Closeable
+public abstract class Reader implements Closeable, Readable
{
/**
* This is the <code>Object</code> used for synchronizing critical code
@@ -152,6 +154,19 @@
return count > 0 ? buf[0] : -1;
}
+ /** @since 1.5 */
+ public int read(CharBuffer buffer) throws IOException
+ {
+ // We want to call put(), so we don't manipulate the CharBuffer
+ // directly.
+ int rem = buffer.remaining();
+ char[] buf = new char[rem];
+ int result = read(buf, 0, rem);
+ if (result != -1)
+ buffer.put(buf, 0, result);
+ return result;
+ }
+
/**
* Closes the stream. Any futher attempts to read from the
* stream may generate an <code>IOException</code>.
Index: java/io/StringWriter.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/StringWriter.java,v
retrieving revision 1.7.2.1
diff -u -r1.7.2.1 StringWriter.java
--- java/io/StringWriter.java 19 Feb 2005 10:50:35 -0000 1.7.2.1
+++ java/io/StringWriter.java 20 Apr 2005 20:15:29 -0000
@@ -183,6 +183,27 @@
buffer.append(str.substring(offset, offset + len));
}
+ /** @since 1.5 */
+ public StringWriter append(char c)
+ {
+ write(c);
+ return this;
+ }
+
+ /** @since 1.5 */
+ public StringWriter append(CharSequence cs)
+ {
+ write(cs == null ? "null" : cs.toString());
+ return this;
+ }
+
+ /** @since 1.5 */
+ public StringWriter append(CharSequence cs, int start, int end)
+ {
+ write(cs == null ? "null" : cs.subSequence(start, end).toString());
+ return this;
+ }
+
/**
* This is the <code>StringBuffer</code> that we use to store bytes that
* are written.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] [generics] Patch: FYI: java.io fixes,
Tom Tromey <=