diff options
Diffstat (limited to 'libjava/java/io')
-rw-r--r-- | libjava/java/io/InputStreamReader.java | 21 | ||||
-rw-r--r-- | libjava/java/io/OutputStreamWriter.java | 28 |
2 files changed, 49 insertions, 0 deletions
diff --git a/libjava/java/io/InputStreamReader.java b/libjava/java/io/InputStreamReader.java index e55f135..91568c5 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 8b7beeb..90ecd9f 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 @@ -129,6 +132,31 @@ public class OutputStreamWriter extends Writer } /** + * This method initializes a new instance of <code>OutputStreamWriter</code> + * to write to the specified stream using a given <code>Charset</code>. + * + * @param out The <code>OutputStream</code> to write to + * @param cs The <code>Charset</code> of the encoding to use + */ + public OutputStreamWriter(OutputStream out, Charset cs) + { + this(out, new CharsetToBytesAdaptor(cs)); + } + + /** + * This method initializes a new instance of <code>OutputStreamWriter</code> + * to write to the specified stream using a given + * <code>CharsetEncoder</code>. + * + * @param out The <code>OutputStream</code> to write to + * @param enc The <code>CharsetEncoder</code> to encode the output with + */ + public OutputStreamWriter(OutputStream out, CharsetEncoder enc) + { + this(out, new CharsetToBytesAdaptor(enc)); + } + + /** * This method closes this stream, and the underlying * <code>OutputStream</code> * |