diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/io/CharArrayWriter.java | 35 | ||||
-rw-r--r-- | java/io/PrintStream.java | 5 | ||||
-rw-r--r-- | java/io/PrintWriter.java | 51 | ||||
-rw-r--r-- | java/io/RandomAccessFile.java | 2 | ||||
-rw-r--r-- | java/io/Reader.java | 19 | ||||
-rw-r--r-- | java/io/StringWriter.java | 21 |
6 files changed, 126 insertions, 7 deletions
diff --git a/java/io/CharArrayWriter.java b/java/io/CharArrayWriter.java index 4593f15c7..46995f4a2 100644 --- a/java/io/CharArrayWriter.java +++ b/java/io/CharArrayWriter.java @@ -242,6 +242,41 @@ public class CharArrayWriter extends Writer } } + /** @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 diff --git a/java/io/PrintStream.java b/java/io/PrintStream.java index 83cfdab62..83dd02724 100644 --- a/java/io/PrintStream.java +++ b/java/io/PrintStream.java @@ -580,14 +580,14 @@ public class PrintStream extends FilterOutputStream implements Appendable } /** @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 @@ public class PrintStream extends FilterOutputStream implements Appendable /** @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; diff --git a/java/io/PrintWriter.java b/java/io/PrintWriter.java index e03f2f85a..bdb1090bd 100644 --- a/java/io/PrintWriter.java +++ b/java/io/PrintWriter.java @@ -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 @@ public class PrintWriter extends Writer 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 @@ public class PrintWriter extends Writer { 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; + } } diff --git a/java/io/RandomAccessFile.java b/java/io/RandomAccessFile.java index c23ca3adf..8adcdec20 100644 --- a/java/io/RandomAccessFile.java +++ b/java/io/RandomAccessFile.java @@ -58,7 +58,7 @@ import java.nio.channels.FileChannel; * @author Aaron M. Renn (arenn@urbanophile.com) * @author Tom Tromey (tromey@cygnus.com) */ -public class RandomAccessFile implements DataOutput, DataInput +public class RandomAccessFile implements DataOutput, DataInput, Closeable { // The underlying file. diff --git a/java/io/Reader.java b/java/io/Reader.java index ba1532bbf..dbe886d8a 100644 --- a/java/io/Reader.java +++ b/java/io/Reader.java @@ -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 @@ exception statement from your version. */ 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 @@ package java.io; * @date April 21, 1998. * @author Aaron M. Renn (arenn@urbanophile.com) */ -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 @@ public abstract class Reader implements Closeable 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>. diff --git a/java/io/StringWriter.java b/java/io/StringWriter.java index 7b6e14193..103baca31 100644 --- a/java/io/StringWriter.java +++ b/java/io/StringWriter.java @@ -183,6 +183,27 @@ public class StringWriter extends Writer 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. |