Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/classes/java/util/Scanner.java
          +++ new/src/share/classes/java/util/Scanner.java
↓ open down ↓ 661 lines elided ↑ open up ↑
 662  662       * @param  source A file to be scanned
 663  663       * @param charsetName The encoding type used to convert bytes from the file
 664  664       *        into characters to be scanned
 665  665       * @throws FileNotFoundException if source is not found
 666  666       * @throws IllegalArgumentException if the specified encoding is
 667  667       *         not found
 668  668       */
 669  669      public Scanner(File source, String charsetName)
 670  670          throws FileNotFoundException
 671  671      {
 672      -        this((ReadableByteChannel)(new FileInputStream(source).getChannel()),
      672 +        this(verifyCharsetName(charsetName),
      673 +             (ReadableByteChannel)(new FileInputStream(source).getChannel()),
 673  674               charsetName);
 674  675      }
      676 +    
      677 +    /**
      678 +     * Private constructor used so that invokers can verify the charsetName
      679 +     * before creating the FileInputStream.
      680 +     */
      681 +    private Scanner(Void unused, ReadableByteChannel source, String charsetName) {
      682 +        this(source, charsetName);
      683 +    }
 675  684  
      685 +    private static Void verifyCharsetName(String charsetName) {
      686 +        if (!Charset.isSupported(charsetName))
      687 +            throw new IllegalArgumentException(charsetName);
      688 +        return null;
      689 +    }
      690 +
 676  691      /**
 677  692       * Constructs a new <code>Scanner</code> that produces values scanned
 678  693       * from the specified file. Bytes from the file are converted into
 679  694       * characters using the underlying platform's
 680  695       * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}.
 681  696       *
 682  697       * @param   source
 683  698       *          A file to be scanned
 684  699       * @throws  IOException
 685  700       *          if an I/O error occurs opening source
↓ open down ↓ 1965 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX