JDK-6772681 : Byte array based Scanner has no constructor that takes a Charset
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 7
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2008-11-18
  • Updated: 2017-03-09
  • Resolved: 2017-03-09
Related Reports
Duplicate :  
Description
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.

Comments
Re-closing as duplicate of JDK-8134807.
09-03-2017