< prev index next >

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

Print this page
@@ -26,13 +26,13 @@
  package java.io;
  
  import java.nio.CharBuffer;
  import java.nio.charset.Charset;
  import java.nio.charset.CharsetDecoder;
+ import java.util.Objects;
  import sun.nio.cs.StreamDecoder;
  
- 
  /**
   * An InputStreamReader is a bridge from byte streams to character streams: It
   * reads bytes and decodes them into characters using a specified {@link
   * Charset charset}.  The charset that it uses
   * may be specified by name or may be given explicitly, or the

@@ -59,11 +59,10 @@
   * @author      Mark Reinhold
   * @since       1.1
   */
  
  public class InputStreamReader extends Reader {
- 
      private final StreamDecoder sd;
  
      /**
       * Creates an InputStreamReader that uses the
       * {@link Charset#defaultCharset() default charset}.

@@ -71,13 +70,12 @@
       * @param  in   An InputStream
       *
       * @see Charset#defaultCharset()
       */
      public InputStreamReader(InputStream in) {
-         super(in);
-         sd = StreamDecoder.forInputStreamReader(in, this,
-                 Charset.defaultCharset()); // ## check lock object
+         Objects.requireNonNull(in);
+         sd = StreamDecoder.forInputStreamReader(in, lock, Charset.defaultCharset());
      }
  
      /**
       * Creates an InputStreamReader that uses the named charset.
       *

@@ -91,14 +89,13 @@
       *             If the named charset is not supported
       */
      public InputStreamReader(InputStream in, String charsetName)
          throws UnsupportedEncodingException
      {
-         super(in);
-         if (charsetName == null)
-             throw new NullPointerException("charsetName");
-         sd = StreamDecoder.forInputStreamReader(in, this, charsetName);
+         Objects.requireNonNull(in);
+         Objects.requireNonNull(charsetName, "charsetName");
+         sd = StreamDecoder.forInputStreamReader(in, lock, charsetName);
      }
  
      /**
       * Creates an InputStreamReader that uses the given charset.
       *

@@ -106,14 +103,13 @@
       * @param  cs       A charset
       *
       * @since 1.4
       */
      public InputStreamReader(InputStream in, Charset cs) {
-         super(in);
-         if (cs == null)
-             throw new NullPointerException("charset");
-         sd = StreamDecoder.forInputStreamReader(in, this, cs);
+         Objects.requireNonNull(in);
+         Objects.requireNonNull(cs, "charset");
+         sd = StreamDecoder.forInputStreamReader(in, lock, cs);
      }
  
      /**
       * Creates an InputStreamReader that uses the given charset decoder.
       *

@@ -121,14 +117,12 @@
       * @param  dec      A charset decoder
       *
       * @since 1.4
       */
      public InputStreamReader(InputStream in, CharsetDecoder dec) {
-         super(in);
-         if (dec == null)
-             throw new NullPointerException("charset decoder");
-         sd = StreamDecoder.forInputStreamReader(in, this, dec);
+         Objects.requireNonNull(dec, "charset decoder");
+         sd = StreamDecoder.forInputStreamReader(in, lock, dec);
      }
  
      /**
       * Returns the name of the character encoding being used by this stream.
       *
< prev index next >