Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6772681

Byte array based Scanner has no constructor that takes a Charset

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 7
    • core-libs

      A DESCRIPTION OF THE REQUEST :
      There is no constructor of java.util.Scanner that takes a java.nio.charset.Charset
      intead of a String to specify a charset for byte stream.

      I propose to add 3 constructors:
      - Scanner(File source, Charset charset)
      - Scanner(InputStream source, Charset charset)
      - Scanner(ReadableByteChannel source, Charset charset)


      JUSTIFICATION :
      charset specified as a String has 3 problems :
      - it's error prone to use a String because it's easy to malform it
      - sometimes you have a Charset in that case, you have to
        transform it to a String and the Scanner implementation
        will retransform it to a Charset.
      - the implementation use a thread local cache which is
        not necessary if you know the Charset


      CUSTOMER SUBMITTED WORKAROUND :
      Use String based constructors.

            sherman Xueming Shen
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: