diff options
author | Mark Wielaard <mark@gcc.gnu.org> | 2005-11-15 23:20:01 +0000 |
---|---|---|
committer | Mark Wielaard <mark@gcc.gnu.org> | 2005-11-15 23:20:01 +0000 |
commit | 8f523f3a1047919d3563daf1ef47ba87336ebe89 (patch) | |
tree | a5eb7cf42a51869cc8aa1fad7ad6a90cca47fdd8 /libjava/classpath/java/io/PrintWriter.java | |
parent | 02e549bfaaec38f68307e7f34e46ea57ea1809af (diff) | |
download | gcc-8f523f3a1047919d3563daf1ef47ba87336ebe89.tar.gz |
Imported GNU Classpath 0.19 + gcj-import-20051115.
* sources.am: Regenerated.
* Makefile.in: Likewise.
* scripts/makemake.tcl: Use glob -nocomplain.
From-SVN: r107049
Diffstat (limited to 'libjava/classpath/java/io/PrintWriter.java')
-rw-r--r-- | libjava/classpath/java/io/PrintWriter.java | 75 |
1 files changed, 72 insertions, 3 deletions
diff --git a/libjava/classpath/java/io/PrintWriter.java b/libjava/classpath/java/io/PrintWriter.java index 5fd0b162f31..5667e705004 100644 --- a/libjava/classpath/java/io/PrintWriter.java +++ b/libjava/classpath/java/io/PrintWriter.java @@ -70,6 +70,11 @@ public class PrintWriter extends Writer * on this stream. */ private boolean error; + + /** + * Indicates whether or not the stream has been closed. + */ + private boolean closed; /** * This is the underlying <code>Writer</code> we are sending output @@ -139,6 +144,68 @@ public class PrintWriter extends Writer } /** + * This initializes a new PrintWriter object to write to the specified + * file. It creates a FileOutputStream object and wraps it in an + * OutputStreamWriter using the default encoding. + * @param file name of the file to write to + * @throws FileNotFoundException if the file cannot be written or created + * + * @since 1.5 + */ + public PrintWriter(String file) throws FileNotFoundException + { + this(new FileOutputStream(file)); + } + + /** + * This initializes a new PrintWriter object to write to the specified + * file. It creates a FileOutputStream object and wraps it in an + * OutputStreamWriter using the specified encoding. + * @param file name of the file to write to + * @param enc the encoding to use + * @throws FileNotFoundException if the file cannot be written or created + * @throws UnsupportedEncodingException if the encoding is not supported + * + * @since 1.5 + */ + public PrintWriter(String file, String enc) + throws FileNotFoundException, UnsupportedEncodingException + { + this(new OutputStreamWriter(new FileOutputStream(file), enc)); + } + + /** + * This initializes a new PrintWriter object to write to the specified + * file. It creates a FileOutputStream object and wraps it in an + * OutputStreamWriter using the default encoding. + * @param file the file to write to + * @throws FileNotFoundException if the file cannot be written or created + * + * @since 1.5 + */ + public PrintWriter(File file) throws FileNotFoundException + { + this(new FileOutputStream(file)); + } + + /** + * This initializes a new PrintWriter object to write to the specified + * file. It creates a FileOutputStream object and wraps it in an + * OutputStreamWriter using the specified encoding. + * @param file the file to write to + * @param enc the encoding to use + * @throws FileNotFoundException if the file cannot be written or created + * @throws UnsupportedEncodingException if the encoding is not supported + * + * @since 1.5 + */ + public PrintWriter(File file, String enc) + throws FileNotFoundException, UnsupportedEncodingException + { + this(new OutputStreamWriter(new FileOutputStream(file), enc)); + } + + /** * This method can be called by subclasses to indicate that an error * has occurred and should be reported by <code>checkError</code>. */ @@ -158,7 +225,8 @@ public class PrintWriter extends Writer */ public boolean checkError() { - flush(); + if (! closed) + flush(); return error; } @@ -185,7 +253,8 @@ public class PrintWriter extends Writer { try { - out.close(); + out.close(); + closed = true; } catch (IOException ex) { @@ -310,7 +379,7 @@ public class PrintWriter extends Writer * This is the system dependent line separator */ private static final char[] line_separator - = System.getProperty("line.separator").toCharArray(); + = System.getProperty("line.separator", "\n").toCharArray(); /** * This method prints a line separator sequence to the stream. The value |