< prev index next >

src/java.base/share/classes/java/io/OutputStreamWriter.java

Print this page
*** 26,13 ***
  package java.io;
  
  import java.nio.CharBuffer;
  import java.nio.charset.Charset;
  import java.nio.charset.CharsetEncoder;
  import sun.nio.cs.StreamEncoder;
  
- 
  /**
   * An OutputStreamWriter is a bridge from character streams to byte streams:
   * Characters written to it are encoded into bytes using a specified {@link
   * Charset charset}.  The charset that it uses
   * may be specified by name or may be given explicitly, or the
--- 26,13 ---
  package java.io;
  
  import java.nio.CharBuffer;
  import java.nio.charset.Charset;
  import java.nio.charset.CharsetEncoder;
+ import java.util.Objects;
  import sun.nio.cs.StreamEncoder;
  
  /**
   * An OutputStreamWriter is a bridge from character streams to byte streams:
   * Characters written to it are encoded into bytes using a specified {@link
   * Charset charset}.  The charset that it uses
   * may be specified by name or may be given explicitly, or the

*** 72,11 ***
   * @author      Mark Reinhold
   * @since       1.1
   */
  
  public class OutputStreamWriter extends Writer {
- 
      private final StreamEncoder se;
  
      /**
       * Creates an OutputStreamWriter that uses the named charset.
       *
--- 72,10 ---

*** 90,26 ***
       *             If the named encoding is not supported
       */
      public OutputStreamWriter(OutputStream out, String charsetName)
          throws UnsupportedEncodingException
      {
!         super(out);
!         if (charsetName == null)
!             throw new NullPointerException("charsetName");
-         se = StreamEncoder.forOutputStreamWriter(out, this, charsetName);
      }
  
      /**
       * Creates an OutputStreamWriter that uses the default character encoding.
       *
       * @param  out  An OutputStream
       * @see Charset#defaultCharset()
       */
      public OutputStreamWriter(OutputStream out) {
!         super(out);
!         se = StreamEncoder.forOutputStreamWriter(out, this,
-                 Charset.defaultCharset());
      }
  
      /**
       * Creates an OutputStreamWriter that uses the given charset.
       *
--- 89,24 ---
       *             If the named encoding is not supported
       */
      public OutputStreamWriter(OutputStream out, String charsetName)
          throws UnsupportedEncodingException
      {
!         Objects.requireNonNull(out);
!         Objects.requireNonNull(charsetName, "charsetName");
!         se = StreamEncoder.forOutputStreamWriter(out, lock, charsetName);
      }
  
      /**
       * Creates an OutputStreamWriter that uses the default character encoding.
       *
       * @param  out  An OutputStream
       * @see Charset#defaultCharset()
       */
      public OutputStreamWriter(OutputStream out) {
!         Objects.requireNonNull(out);
!         se = StreamEncoder.forOutputStreamWriter(out, lock, Charset.defaultCharset());
      }
  
      /**
       * Creates an OutputStreamWriter that uses the given charset.
       *

*** 120,14 ***
       *         A charset
       *
       * @since 1.4
       */
      public OutputStreamWriter(OutputStream out, Charset cs) {
!         super(out);
!         if (cs == null)
!             throw new NullPointerException("charset");
-         se = StreamEncoder.forOutputStreamWriter(out, this, cs);
      }
  
      /**
       * Creates an OutputStreamWriter that uses the given charset encoder.
       *
--- 117,13 ---
       *         A charset
       *
       * @since 1.4
       */
      public OutputStreamWriter(OutputStream out, Charset cs) {
!         Objects.requireNonNull(out);
!         Objects.requireNonNull(cs, "charset");
!         se = StreamEncoder.forOutputStreamWriter(out, lock, cs);
      }
  
      /**
       * Creates an OutputStreamWriter that uses the given charset encoder.
       *

*** 138,14 ***
       *         A charset encoder
       *
       * @since 1.4
       */
      public OutputStreamWriter(OutputStream out, CharsetEncoder enc) {
!         super(out);
!         if (enc == null)
!             throw new NullPointerException("charset encoder");
-         se = StreamEncoder.forOutputStreamWriter(out, this, enc);
      }
  
      /**
       * Returns the name of the character encoding being used by this stream.
       *
--- 134,13 ---
       *         A charset encoder
       *
       * @since 1.4
       */
      public OutputStreamWriter(OutputStream out, CharsetEncoder enc) {
!         Objects.requireNonNull(out);
!         Objects.requireNonNull(enc, "charset encoder");
!         se = StreamEncoder.forOutputStreamWriter(out, lock, enc);
      }
  
      /**
       * Returns the name of the character encoding being used by this stream.
       *
< prev index next >