From 8a0383655d7d869ef9d344202c78ce3659927052 Mon Sep 17 00:00:00 2001 From: tromey Date: Tue, 3 Jan 2006 22:58:31 +0000 Subject: PR libgcj/9715, PR libgcj/19132: * java/nio/charset/Charset.java (charsetForName): Try default provider first. (availableCharsets): Re-merged. (providers2): Likewise. (defaultCharset): Likewise. * sources.am, Makefile.in: Rebuilt. * gnu/java/nio/charset/Provider.java: Removed. * java/io/OutputStreamWriter.java (OutputStreamWriter(OutputStream,Charset)): New constructor. (OutputStreamWriter(OutputStream,CharsetEncoder)): Likewise. * java/io/InputStreamReader.java (InputStreamReader(InputStream,CharsetDecoder)): New constructor. (InputStreamReader(InputStream,Charset)): Likewise. * gnu/gcj/convert/BytesToUnicode.java (getDecoder): Try a BytesToCharsetAdaptor. * gnu/gcj/convert/UnicodeToBytes.java (getEncoder): Try a CharsetToBytesAdaptor. * gnu/gcj/convert/CharsetToBytesAdaptor.java: New file. * gnu/gcj/convert/BytesToCharsetAdaptor.java: New file. * mauve-libgcj: Remove getEncoding exclusion. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@109294 138bc75d-0d04-0410-961f-82ee72b054a4 --- libjava/java/io/InputStreamReader.java | 21 +++++++++++++++++++++ libjava/java/io/OutputStreamWriter.java | 28 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) (limited to 'libjava/java/io') diff --git a/libjava/java/io/InputStreamReader.java b/libjava/java/io/InputStreamReader.java index e55f1352caa..91568c5cc50 100644 --- a/libjava/java/io/InputStreamReader.java +++ b/libjava/java/io/InputStreamReader.java @@ -39,6 +39,8 @@ exception statement from your version. */ package java.io; import gnu.gcj.convert.*; +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; /** * This class reads characters from a byte input stream. The characters @@ -131,6 +133,25 @@ public class InputStreamReader extends Reader this(in, BytesToUnicode.getDecoder(encoding_name)); } + /** + * Creates an InputStreamReader that uses a decoder of the given + * charset to decode the bytes in the InputStream into + * characters. + */ + public InputStreamReader(InputStream in, Charset charset) + { + this(in, new BytesToCharsetAdaptor(charset)); + } + + /** + * Creates an InputStreamReader that uses the given charset decoder + * to decode the bytes in the InputStream into characters. + */ + public InputStreamReader(InputStream in, CharsetDecoder decoder) + { + this(in, new BytesToCharsetAdaptor(decoder)); + } + private InputStreamReader(InputStream in, BytesToUnicode decoder) { // FIXME: someone could pass in a BufferedInputStream whose buffer diff --git a/libjava/java/io/OutputStreamWriter.java b/libjava/java/io/OutputStreamWriter.java index 8b7beeb497b..90ecd9f0bc3 100644 --- a/libjava/java/io/OutputStreamWriter.java +++ b/libjava/java/io/OutputStreamWriter.java @@ -39,6 +39,9 @@ exception statement from your version. */ package java.io; import gnu.gcj.convert.UnicodeToBytes; +import gnu.gcj.convert.CharsetToBytesAdaptor; +import java.nio.charset.Charset; +import java.nio.charset.CharsetEncoder; /** * This class writes characters to an output stream that is byte oriented @@ -128,6 +131,31 @@ public class OutputStreamWriter extends Writer this(out, UnicodeToBytes.getDefaultEncoder()); } + /** + * This method initializes a new instance of OutputStreamWriter + * to write to the specified stream using a given Charset. + * + * @param out The OutputStream to write to + * @param cs The Charset of the encoding to use + */ + public OutputStreamWriter(OutputStream out, Charset cs) + { + this(out, new CharsetToBytesAdaptor(cs)); + } + + /** + * This method initializes a new instance of OutputStreamWriter + * to write to the specified stream using a given + * CharsetEncoder. + * + * @param out The OutputStream to write to + * @param enc The CharsetEncoder to encode the output with + */ + public OutputStreamWriter(OutputStream out, CharsetEncoder enc) + { + this(out, new CharsetToBytesAdaptor(enc)); + } + /** * This method closes this stream, and the underlying * OutputStream -- cgit v1.2.3