From d8048dc2f71b8daa7ff9641134e489101cbc220c Mon Sep 17 00:00:00 2001 From: Michael Koch Date: Fri, 9 May 2003 07:10:58 +0000 Subject: 2003-05-09 Michael Koch * java/io/DataOutputStream.java (writeShort): Made it synchronized. (writeChar): Likewise. (writeInt): Likewise. (writeLong): Liekwise. (writeUTF): Made it synchronized, renamed argument to match classpath. * java/io/InputStreamReader.java (converter): Added documentation. (read): Merged documentation from classpath. * java/io/OutputStreamWriter.java (OutputStreamWriter): Merged documentation from classpath. (close): Reformatted. (getEncoding): Likewise. (flush): Likewise. (write): Merged documentation from classpath, reformatted. From-SVN: r66624 --- libjava/java/io/OutputStreamWriter.java | 101 ++++++++++++++++++++++++++------ 1 file changed, 84 insertions(+), 17 deletions(-) (limited to 'libjava/java/io/OutputStreamWriter.java') diff --git a/libjava/java/io/OutputStreamWriter.java b/libjava/java/io/OutputStreamWriter.java index 1d63d5650d1..e4ecbdbab8f 100644 --- a/libjava/java/io/OutputStreamWriter.java +++ b/libjava/java/io/OutputStreamWriter.java @@ -37,20 +37,51 @@ exception statement from your version. */ package java.io; + import gnu.gcj.convert.UnicodeToBytes; /** + * This class writes characters to an output stream that is byte oriented + * It converts the chars that are written to bytes using an encoding layer, + * which is specific to a particular encoding standard. The desired + * encoding can either be specified by name, or if no encoding is specified, + * the system default encoding will be used. The system default encoding + * name is determined from the system property file.encoding. + * The only encodings that are guaranteed to be available are "8859_1" + * (the Latin-1 character set) and "UTF8". Unfortunately, Java does not + * provide a mechanism for listing the encodings that are supported in + * a given implementation. + *

+ * Here is a list of standard encoding names that may be available: + *

+ *

+ * + * @author Aaron M. Renn (arenn@urbanophile.com) * @author Per Bothner * @date April 17, 1998. */ -/* 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, but only supports 8859_1. - */ public class OutputStreamWriter extends Writer { BufferedOutputStream out; + /** + * This is the byte-character encoder class that does the writing and + * translation of characters to bytes before writing to the underlying + * class. + */ UnicodeToBytes converter; /* Temporary buffer. */ @@ -67,8 +98,21 @@ public class OutputStreamWriter extends Writer this.converter = encoder; } - public OutputStreamWriter(OutputStream out, String encoding_scheme) - throws UnsupportedEncodingException + /** + * This method initializes a new instance of OutputStreamWriter + * to write to the specified stream using a caller supplied character + * encoding scheme. Note that due to a deficiency in the Java language + * design, there is no way to determine which encodings are supported. + * + * @param out The OutputStream to write to + * @param encoding_scheme The name of the encoding scheme to use for + * character to byte translation + * + * @exception UnsupportedEncodingException If the named encoding is + * not available. + */ + public OutputStreamWriter (OutputStream out, String encoding_scheme) + throws UnsupportedEncodingException { this(out, UnicodeToBytes.getEncoder(encoding_scheme)); } @@ -79,7 +123,7 @@ public class OutputStreamWriter extends Writer * * @param out The OutputStream to write to */ - public OutputStreamWriter(OutputStream out) + public OutputStreamWriter (OutputStream out) { this(out, UnicodeToBytes.getDefaultEncoder()); } @@ -90,7 +134,7 @@ public class OutputStreamWriter extends Writer * * @exception IOException If an error occurs */ - public void close() throws IOException + public void close () throws IOException { synchronized (lock) { @@ -111,7 +155,7 @@ public class OutputStreamWriter extends Writer * * @return The encoding scheme name */ - public String getEncoding() + public String getEncoding () { return out != null ? converter.getName() : null; } @@ -121,7 +165,7 @@ public class OutputStreamWriter extends Writer * * @exception IOException If an error occurs */ - public void flush() throws IOException + public void flush () throws IOException { synchronized (lock) { @@ -137,8 +181,18 @@ public class OutputStreamWriter extends Writer } } - public void write(char[] buf, int offset, int count) - throws IOException + /** + * This method writes count characters from the specified + * array to the output stream starting at position offset + * into the array. + * + * @param buf The array of character to write from + * @param offset The offset into the array to start writing chars from + * @param count The number of chars to write. + * + * @exception IOException If an error occurs + */ + public void write (char[] buf, int offset, int count) throws IOException { synchronized (lock) { @@ -154,8 +208,10 @@ public class OutputStreamWriter extends Writer } } - /** Writes characters through to the inferior BufferedOutputStream. - * Ignores wcount and the work buffer. */ + /* + * Writes characters through to the inferior BufferedOutputStream. + * Ignores wcount and the work buffer. + */ private void writeChars(char[] buf, int offset, int count) throws IOException { @@ -178,8 +234,19 @@ public class OutputStreamWriter extends Writer } } - public void write(String str, int offset, int count) - throws IOException + /** + * This method writes count bytes from the specified + * String starting at position offset into the + * String. + * + * @param str The String to write chars from + * @param offset The position in the String to start + * writing chars from + * @param count The number of chars to write + * + * @exception IOException If an error occurs + */ + public void write (String str, int offset, int count) throws IOException { synchronized (lock) { @@ -217,7 +284,7 @@ public class OutputStreamWriter extends Writer * * @exception IOException If an error occurs */ - public void write(int ch) throws IOException + public void write (int ch) throws IOException { synchronized (lock) { -- cgit v1.2.3