8234147: Avoid looking up standard charsets in core libraries

Reviewed-by: alanb
This commit is contained in:
Ivan Gerasimov 2019-12-01 15:29:37 -08:00
parent 4e64af81a2
commit cd589d8469
36 changed files with 200 additions and 237 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,8 @@
package com.sun.java.util.jar.pack; package com.sun.java.util.jar.pack;
import sun.nio.cs.UTF_8;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
@ -443,7 +445,7 @@ class Driver {
// Skip sig4, disks4, entries4, clen4, coff4, cmt2 // Skip sig4, disks4, entries4, clen4, coff4, cmt2
i += 4+4+4+4+4+2; i += 4+4+4+4+4+2;
if (i < tail.length) if (i < tail.length)
return new String(tail, i, tail.length-i, "UTF8"); return new String(tail, i, tail.length-i, UTF_8.INSTANCE);
return ""; return "";
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -29,7 +29,7 @@ import sun.security.action.GetBooleanAction;
import static com.sun.security.ntlm.Version.*; import static com.sun.security.ntlm.Version.*;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
@ -182,13 +182,9 @@ class NTLM {
String readSecurityBuffer(int offset, boolean unicode) String readSecurityBuffer(int offset, boolean unicode)
throws NTLMException { throws NTLMException {
byte[] raw = readSecurityBuffer(offset); byte[] raw = readSecurityBuffer(offset);
try {
return raw == null ? null : new String( return raw == null ? null : new String(
raw, unicode ? "UnicodeLittleUnmarked" : "ISO8859_1"); raw, unicode ? StandardCharsets.UTF_16LE
} catch (UnsupportedEncodingException ex) { : StandardCharsets.ISO_8859_1);
throw new NTLMException(NTLMException.PACKET_READ_ERROR,
"Invalid input encoding");
}
} }
} }
@ -247,12 +243,9 @@ class NTLM {
} }
void writeSecurityBuffer(int offset, String str, boolean unicode) { void writeSecurityBuffer(int offset, String str, boolean unicode) {
try {
writeSecurityBuffer(offset, str == null ? null : str.getBytes( writeSecurityBuffer(offset, str == null ? null : str.getBytes(
unicode ? "UnicodeLittleUnmarked" : "ISO8859_1")); unicode ? StandardCharsets.UTF_16LE
} catch (UnsupportedEncodingException ex) { : StandardCharsets.ISO_8859_1));
assert false;
}
} }
byte[] getBytes() { byte[] getBytes() {
@ -380,9 +373,7 @@ class NTLM {
} }
byte[] calcV2(byte[] nthash, String text, byte[] blob, byte[] challenge) { byte[] calcV2(byte[] nthash, String text, byte[] blob, byte[] challenge) {
try { byte[] ntlmv2hash = hmacMD5(nthash, text.getBytes(StandardCharsets.UTF_16LE));
byte[] ntlmv2hash = hmacMD5(nthash,
text.getBytes("UnicodeLittleUnmarked"));
byte[] cn = new byte[blob.length+8]; byte[] cn = new byte[blob.length+8];
System.arraycopy(challenge, 0, cn, 0, 8); System.arraycopy(challenge, 0, cn, 0, 8);
System.arraycopy(blob, 0, cn, 8, blob.length); System.arraycopy(blob, 0, cn, 8, blob.length);
@ -390,10 +381,6 @@ class NTLM {
System.arraycopy(hmacMD5(ntlmv2hash, cn), 0, result, 0, 16); System.arraycopy(hmacMD5(ntlmv2hash, cn), 0, result, 0, 16);
System.arraycopy(blob, 0, result, 16, blob.length); System.arraycopy(blob, 0, result, 16, blob.length);
return result; return result;
} catch (UnsupportedEncodingException ex) {
assert false;
}
return null;
} }
// NTLM2 LM/NTLM // NTLM2 LM/NTLM
@ -412,19 +399,11 @@ class NTLM {
// Password in ASCII and UNICODE // Password in ASCII and UNICODE
static byte[] getP1(char[] password) { static byte[] getP1(char[] password) {
try { return new String(password).toUpperCase(Locale.ENGLISH)
return new String(password).toUpperCase( .getBytes(StandardCharsets.ISO_8859_1);
Locale.ENGLISH).getBytes("ISO8859_1");
} catch (UnsupportedEncodingException ex) {
return null;
}
} }
static byte[] getP2(char[] password) { static byte[] getP2(char[] password) {
try { return new String(password).getBytes(StandardCharsets.UTF_16LE);
return new String(password).getBytes("UnicodeLittleUnmarked");
} catch (UnsupportedEncodingException ex) {
return null;
}
} }
} }

View file

@ -70,12 +70,8 @@ public class InputStreamReader extends Reader {
*/ */
public InputStreamReader(InputStream in) { public InputStreamReader(InputStream in) {
super(in); super(in);
try { sd = StreamDecoder.forInputStreamReader(in, this,
sd = StreamDecoder.forInputStreamReader(in, this, (String)null); // ## check lock object Charset.defaultCharset()); // ## check lock object
} catch (UnsupportedEncodingException e) {
// The default encoding should always be available
throw new Error(e);
}
} }
/** /**

View file

@ -106,11 +106,8 @@ public class OutputStreamWriter extends Writer {
*/ */
public OutputStreamWriter(OutputStream out) { public OutputStreamWriter(OutputStream out) {
super(out); super(out);
try { se = StreamEncoder.forOutputStreamWriter(out, this,
se = StreamEncoder.forOutputStreamWriter(out, this, (String)null); Charset.defaultCharset());
} catch (UnsupportedEncodingException e) {
throw new Error(e);
}
} }
/** /**

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -151,7 +151,7 @@ class CharacterName {
} }
public int getCodePoint(String name) { public int getCodePoint(String name) {
byte[] bname = name.getBytes(java.nio.charset.StandardCharsets.ISO_8859_1); byte[] bname = name.getBytes(sun.nio.cs.ISO_8859_1.INSTANCE);
int hsh = hashN(bname, 0, bname.length); int hsh = hashN(bname, 0, bname.length);
int idx = hsIndices[(hsh & 0x7fffffff) % hsIndices.length]; int idx = hsIndices[(hsh & 0x7fffffff) % hsIndices.length];
while (idx != -1) { while (idx != -1) {

View file

@ -31,7 +31,6 @@ import java.util.Objects;
import java.util.Scanner; import java.util.Scanner;
import java.security.AccessController; import java.security.AccessController;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.ObjectStreamException; import java.io.ObjectStreamException;
import java.io.ObjectStreamField; import java.io.ObjectStreamField;
import java.io.IOException; import java.io.IOException;
@ -52,6 +51,7 @@ import jdk.internal.access.SharedSecrets;
import sun.security.action.*; import sun.security.action.*;
import sun.net.InetAddressCachePolicy; import sun.net.InetAddressCachePolicy;
import sun.net.util.IPAddressUtil; import sun.net.util.IPAddressUtil;
import sun.nio.cs.UTF_8;
/** /**
* This class represents an Internet Protocol (IP) address. * This class represents an Internet Protocol (IP) address.
@ -984,7 +984,9 @@ public class InetAddress implements java.io.Serializable {
String hostEntry; String hostEntry;
String host = null; String host = null;
try (Scanner hostsFileScanner = new Scanner(new File(hostsFile), "UTF-8")) { try (Scanner hostsFileScanner = new Scanner(new File(hostsFile),
UTF_8.INSTANCE))
{
while (hostsFileScanner.hasNextLine()) { while (hostsFileScanner.hasNextLine()) {
hostEntry = hostsFileScanner.nextLine(); hostEntry = hostsFileScanner.nextLine();
if (!hostEntry.startsWith("#")) { if (!hostEntry.startsWith("#")) {
@ -997,7 +999,7 @@ public class InetAddress implements java.io.Serializable {
} }
} }
} }
} catch (FileNotFoundException e) { } catch (IOException e) {
throw new UnknownHostException("Unable to resolve address " throw new UnknownHostException("Unable to resolve address "
+ Arrays.toString(addr) + " as hosts file " + hostsFile + Arrays.toString(addr) + " as hosts file " + hostsFile
+ " not found "); + " not found ");
@ -1033,7 +1035,9 @@ public class InetAddress implements java.io.Serializable {
ArrayList<InetAddress> inetAddresses = null; ArrayList<InetAddress> inetAddresses = null;
// lookup the file and create a list InetAddress for the specified host // lookup the file and create a list InetAddress for the specified host
try (Scanner hostsFileScanner = new Scanner(new File(hostsFile), "UTF-8")) { try (Scanner hostsFileScanner = new Scanner(new File(hostsFile),
UTF_8.INSTANCE))
{
while (hostsFileScanner.hasNextLine()) { while (hostsFileScanner.hasNextLine()) {
hostEntry = hostsFileScanner.nextLine(); hostEntry = hostsFileScanner.nextLine();
if (!hostEntry.startsWith("#")) { if (!hostEntry.startsWith("#")) {
@ -1052,7 +1056,7 @@ public class InetAddress implements java.io.Serializable {
} }
} }
} }
} catch (FileNotFoundException e) { } catch (IOException e) {
throw new UnknownHostException("Unable to resolve host " + host throw new UnknownHostException("Unable to resolve host " + host
+ " as hosts file " + hostsFile + " not found "); + " as hosts file " + hostsFile + " not found ");
} }

View file

@ -28,6 +28,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.nio.charset.StandardCharsets;
import java.security.AccessController; import java.security.AccessController;
import java.util.Iterator; import java.util.Iterator;
@ -166,18 +167,10 @@ class SocksSocketImpl extends DelegatingSocketImpl implements SocksConsts {
return false; return false;
out.write(1); out.write(1);
out.write(userName.length()); out.write(userName.length());
try { out.write(userName.getBytes(StandardCharsets.ISO_8859_1));
out.write(userName.getBytes("ISO-8859-1"));
} catch (java.io.UnsupportedEncodingException uee) {
assert false;
}
if (password != null) { if (password != null) {
out.write(password.length()); out.write(password.length());
try { out.write(password.getBytes(StandardCharsets.ISO_8859_1));
out.write(password.getBytes("ISO-8859-1"));
} catch (java.io.UnsupportedEncodingException uee) {
assert false;
}
} else } else
out.write(0); out.write(0);
out.flush(); out.flush();
@ -208,11 +201,7 @@ class SocksSocketImpl extends DelegatingSocketImpl implements SocksConsts {
out.write((endpoint.getPort() >> 0) & 0xff); out.write((endpoint.getPort() >> 0) & 0xff);
out.write(endpoint.getAddress().getAddress()); out.write(endpoint.getAddress().getAddress());
String userName = getUserName(); String userName = getUserName();
try { out.write(userName.getBytes(StandardCharsets.ISO_8859_1));
out.write(userName.getBytes("ISO-8859-1"));
} catch (java.io.UnsupportedEncodingException uee) {
assert false;
}
out.write(0); out.write(0);
out.flush(); out.flush();
byte[] data = new byte[8]; byte[] data = new byte[8];
@ -427,11 +416,7 @@ class SocksSocketImpl extends DelegatingSocketImpl implements SocksConsts {
if (epoint.isUnresolved()) { if (epoint.isUnresolved()) {
out.write(DOMAIN_NAME); out.write(DOMAIN_NAME);
out.write(epoint.getHostName().length()); out.write(epoint.getHostName().length());
try { out.write(epoint.getHostName().getBytes(StandardCharsets.ISO_8859_1));
out.write(epoint.getHostName().getBytes("ISO-8859-1"));
} catch (java.io.UnsupportedEncodingException uee) {
assert false;
}
out.write((epoint.getPort() >> 8) & 0xff); out.write((epoint.getPort() >> 8) & 0xff);
out.write((epoint.getPort() >> 0) & 0xff); out.write((epoint.getPort() >> 0) & 0xff);
} else if (epoint.getAddress() instanceof Inet6Address) { } else if (epoint.getAddress() instanceof Inet6Address) {

View file

@ -42,11 +42,11 @@ import java.text.Normalizer;
import jdk.internal.access.JavaNetUriAccess; import jdk.internal.access.JavaNetUriAccess;
import jdk.internal.access.SharedSecrets; import jdk.internal.access.SharedSecrets;
import sun.nio.cs.ThreadLocalCoders; import sun.nio.cs.ThreadLocalCoders;
import sun.nio.cs.UTF_8;
import java.lang.Character; // for javadoc import java.lang.Character; // for javadoc
import java.lang.NullPointerException; // for javadoc import java.lang.NullPointerException; // for javadoc
/** /**
* Represents a Uniform Resource Identifier (URI) reference. * Represents a Uniform Resource Identifier (URI) reference.
* *
@ -2739,7 +2739,7 @@ public final class URI
private static void appendEncoded(StringBuilder sb, char c) { private static void appendEncoded(StringBuilder sb, char c) {
ByteBuffer bb = null; ByteBuffer bb = null;
try { try {
bb = ThreadLocalCoders.encoderFor("UTF-8") bb = ThreadLocalCoders.encoderFor(UTF_8.INSTANCE)
.encode(CharBuffer.wrap("" + c)); .encode(CharBuffer.wrap("" + c));
} catch (CharacterCodingException x) { } catch (CharacterCodingException x) {
assert false; assert false;
@ -2807,7 +2807,7 @@ public final class URI
String ns = Normalizer.normalize(s, Normalizer.Form.NFC); String ns = Normalizer.normalize(s, Normalizer.Form.NFC);
ByteBuffer bb = null; ByteBuffer bb = null;
try { try {
bb = ThreadLocalCoders.encoderFor("UTF-8") bb = ThreadLocalCoders.encoderFor(UTF_8.INSTANCE)
.encode(CharBuffer.wrap(ns)); .encode(CharBuffer.wrap(ns));
} catch (CharacterCodingException x) { } catch (CharacterCodingException x) {
assert false; assert false;
@ -2865,7 +2865,7 @@ public final class URI
StringBuilder sb = new StringBuilder(n); StringBuilder sb = new StringBuilder(n);
ByteBuffer bb = ByteBuffer.allocate(n); ByteBuffer bb = ByteBuffer.allocate(n);
CharBuffer cb = CharBuffer.allocate(n); CharBuffer cb = CharBuffer.allocate(n);
CharsetDecoder dec = ThreadLocalCoders.decoderFor("UTF-8") CharsetDecoder dec = ThreadLocalCoders.decoderFor(UTF_8.INSTANCE)
.onMalformedInput(CodingErrorAction.REPLACE) .onMalformedInput(CodingErrorAction.REPLACE)
.onUnmappableCharacter(CodingErrorAction.REPLACE); .onUnmappableCharacter(CodingErrorAction.REPLACE);

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -24,6 +24,10 @@
*/ */
package java.nio.file; package java.nio.file;
import sun.nio.cs.ISO_8859_1;
import sun.nio.cs.UTF_8;
import sun.nio.cs.US_ASCII;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
@ -32,7 +36,6 @@ import java.nio.channels.Channels;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel; import java.nio.channels.ReadableByteChannel;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.Spliterator; import java.util.Spliterator;
@ -66,9 +69,9 @@ final class FileChannelLinesSpliterator implements Spliterator<String> {
static final Set<String> SUPPORTED_CHARSET_NAMES; static final Set<String> SUPPORTED_CHARSET_NAMES;
static { static {
SUPPORTED_CHARSET_NAMES = new HashSet<>(); SUPPORTED_CHARSET_NAMES = new HashSet<>();
SUPPORTED_CHARSET_NAMES.add(StandardCharsets.UTF_8.name()); SUPPORTED_CHARSET_NAMES.add(UTF_8.INSTANCE.name());
SUPPORTED_CHARSET_NAMES.add(StandardCharsets.ISO_8859_1.name()); SUPPORTED_CHARSET_NAMES.add(ISO_8859_1.INSTANCE.name());
SUPPORTED_CHARSET_NAMES.add(StandardCharsets.US_ASCII.name()); SUPPORTED_CHARSET_NAMES.add(US_ASCII.INSTANCE.name());
} }
private final FileChannel fc; private final FileChannel fc;

View file

@ -79,6 +79,7 @@ import java.util.stream.StreamSupport;
import jdk.internal.util.ArraysSupport; import jdk.internal.util.ArraysSupport;
import sun.nio.ch.FileChannelImpl; import sun.nio.ch.FileChannelImpl;
import sun.nio.cs.UTF_8;
import sun.nio.fs.AbstractFileSystemProvider; import sun.nio.fs.AbstractFileSystemProvider;
/** /**
@ -2944,7 +2945,7 @@ public final class Files {
* @since 1.8 * @since 1.8
*/ */
public static BufferedReader newBufferedReader(Path path) throws IOException { public static BufferedReader newBufferedReader(Path path) throws IOException {
return newBufferedReader(path, StandardCharsets.UTF_8); return newBufferedReader(path, UTF_8.INSTANCE);
} }
/** /**
@ -3036,7 +3037,7 @@ public final class Files {
public static BufferedWriter newBufferedWriter(Path path, OpenOption... options) public static BufferedWriter newBufferedWriter(Path path, OpenOption... options)
throws IOException throws IOException
{ {
return newBufferedWriter(path, StandardCharsets.UTF_8, options); return newBufferedWriter(path, UTF_8.INSTANCE, options);
} }
/** /**
@ -3305,7 +3306,7 @@ public final class Files {
* @since 11 * @since 11
*/ */
public static String readString(Path path) throws IOException { public static String readString(Path path) throws IOException {
return readString(path, StandardCharsets.UTF_8); return readString(path, UTF_8.INSTANCE);
} }
/** /**
@ -3430,7 +3431,7 @@ public final class Files {
* @since 1.8 * @since 1.8
*/ */
public static List<String> readAllLines(Path path) throws IOException { public static List<String> readAllLines(Path path) throws IOException {
return readAllLines(path, StandardCharsets.UTF_8); return readAllLines(path, UTF_8.INSTANCE);
} }
/** /**
@ -3601,7 +3602,7 @@ public final class Files {
OpenOption... options) OpenOption... options)
throws IOException throws IOException
{ {
return write(path, lines, StandardCharsets.UTF_8, options); return write(path, lines, UTF_8.INSTANCE, options);
} }
/** /**
@ -3641,7 +3642,7 @@ public final class Files {
public static Path writeString(Path path, CharSequence csq, OpenOption... options) public static Path writeString(Path path, CharSequence csq, OpenOption... options)
throws IOException throws IOException
{ {
return writeString(path, csq, StandardCharsets.UTF_8, options); return writeString(path, csq, UTF_8.INSTANCE, options);
} }
/** /**
@ -4188,6 +4189,6 @@ public final class Files {
* @since 1.8 * @since 1.8
*/ */
public static Stream<String> lines(Path path) throws IOException { public static Stream<String> lines(Path path) throws IOException {
return lines(path, StandardCharsets.UTF_8); return lines(path, UTF_8.INSTANCE);
} }
} }

View file

@ -31,6 +31,9 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import sun.nio.cs.ISO_8859_1;
import jdk.internal.HotSpotIntrinsicCandidate; import jdk.internal.HotSpotIntrinsicCandidate;
/** /**
@ -584,7 +587,7 @@ public class Base64 {
* if {@code src} is not in valid Base64 scheme * if {@code src} is not in valid Base64 scheme
*/ */
public byte[] decode(String src) { public byte[] decode(String src) {
return decode(src.getBytes(StandardCharsets.ISO_8859_1)); return decode(src.getBytes(ISO_8859_1.INSTANCE));
} }
/** /**

View file

@ -46,6 +46,9 @@ import java.util.function.BiConsumer;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Function; import java.util.function.Function;
import sun.nio.cs.ISO_8859_1;
import sun.nio.cs.UTF_8;
import jdk.internal.access.SharedSecrets; import jdk.internal.access.SharedSecrets;
import jdk.internal.misc.Unsafe; import jdk.internal.misc.Unsafe;
import jdk.internal.util.ArraysSupport; import jdk.internal.util.ArraysSupport;
@ -909,7 +912,7 @@ public class Properties extends Hashtable<Object,Object> {
public void store(OutputStream out, String comments) public void store(OutputStream out, String comments)
throws IOException throws IOException
{ {
store0(new BufferedWriter(new OutputStreamWriter(out, "8859_1")), store0(new BufferedWriter(new OutputStreamWriter(out, ISO_8859_1.INSTANCE)),
comments, comments,
true); true);
} }
@ -1001,7 +1004,7 @@ public class Properties extends Hashtable<Object,Object> {
public void storeToXML(OutputStream os, String comment) public void storeToXML(OutputStream os, String comment)
throws IOException throws IOException
{ {
storeToXML(os, comment, "UTF-8"); storeToXML(os, comment, UTF_8.INSTANCE);
} }
/** /**

View file

@ -44,8 +44,8 @@ import java.io.InputStreamReader;
import java.io.Reader; import java.io.Reader;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.MalformedInputException; import java.nio.charset.MalformedInputException;
import java.nio.charset.StandardCharsets;
import java.nio.charset.UnmappableCharacterException; import java.nio.charset.UnmappableCharacterException;
import sun.nio.cs.ISO_8859_1;
import sun.security.action.GetPropertyAction; import sun.security.action.GetPropertyAction;
import sun.util.PropertyResourceBundleCharset; import sun.util.PropertyResourceBundleCharset;
import sun.util.ResourceBundleEnumeration; import sun.util.ResourceBundleEnumeration;
@ -176,7 +176,7 @@ public class PropertyResourceBundle extends ResourceBundle {
public PropertyResourceBundle (InputStream stream) throws IOException { public PropertyResourceBundle (InputStream stream) throws IOException {
this(new InputStreamReader(stream, this(new InputStreamReader(stream,
"ISO-8859-1".equals(encoding) ? "ISO-8859-1".equals(encoding) ?
StandardCharsets.ISO_8859_1.newDecoder() : ISO_8859_1.INSTANCE.newDecoder() :
new PropertyResourceBundleCharset("UTF-8".equals(encoding)).newDecoder())); new PropertyResourceBundleCharset("UTF-8".equals(encoding)).newDecoder()));
} }

View file

@ -45,6 +45,8 @@ import java.util.function.Supplier;
import java.util.stream.Stream; import java.util.stream.Stream;
import java.util.stream.StreamSupport; import java.util.stream.StreamSupport;
import sun.nio.cs.UTF_8;
import jdk.internal.loader.BootLoader; import jdk.internal.loader.BootLoader;
import jdk.internal.loader.ClassLoaders; import jdk.internal.loader.ClassLoaders;
import jdk.internal.access.JavaLangAccess; import jdk.internal.access.JavaLangAccess;
@ -55,7 +57,6 @@ import jdk.internal.module.ServicesCatalog.ServiceProvider;
import jdk.internal.reflect.CallerSensitive; import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.Reflection; import jdk.internal.reflect.Reflection;
/** /**
* A facility to load implementations of a service. * A facility to load implementations of a service.
* *
@ -1164,7 +1165,7 @@ public final class ServiceLoader<S>
uc.setUseCaches(false); uc.setUseCaches(false);
try (InputStream in = uc.getInputStream(); try (InputStream in = uc.getInputStream();
BufferedReader r BufferedReader r
= new BufferedReader(new InputStreamReader(in, "utf-8"))) = new BufferedReader(new InputStreamReader(in, UTF_8.INSTANCE)))
{ {
int lc = 1; int lc = 1;
while ((lc = parseLine(u, r, lc, names)) >= 0); while ((lc = parseLine(u, r, lc, names)) >= 0);

View file

@ -36,9 +36,9 @@ import java.util.Set;
import jdk.internal.misc.VM; import jdk.internal.misc.VM;
import jdk.internal.vm.annotation.Stable; import jdk.internal.vm.annotation.Stable;
import sun.util.logging.PlatformLogger;
import static java.nio.charset.StandardCharsets.UTF_8; import sun.nio.cs.UTF_8;
import sun.util.logging.PlatformLogger;
/** /**
* The Attributes class maps Manifest attribute names to associated string * The Attributes class maps Manifest attribute names to associated string
@ -337,7 +337,7 @@ public class Attributes implements Map<Object,Object>, Cloneable {
buffer.append(vername); buffer.append(vername);
buffer.append(": "); buffer.append(": ");
buffer.append(version); buffer.append(version);
out.write(buffer.toString().getBytes(UTF_8)); out.write(buffer.toString().getBytes(UTF_8.INSTANCE));
Manifest.println(out); Manifest.println(out);
} }
@ -399,7 +399,7 @@ public class Attributes implements Map<Object,Object>, Cloneable {
lastline = buf; lastline = buf;
continue; continue;
} }
value = new String(buf, 0, buf.length, UTF_8); value = new String(buf, 0, buf.length, UTF_8.INSTANCE);
lastline = null; lastline = null;
} else { } else {
while (lbuf[i++] != ':') { while (lbuf[i++] != ':') {
@ -412,13 +412,13 @@ public class Attributes implements Map<Object,Object>, Cloneable {
throw new IOException("invalid header field (" throw new IOException("invalid header field ("
+ Manifest.getErrorPosition(filename, lineNumber) + ")"); + Manifest.getErrorPosition(filename, lineNumber) + ")");
} }
name = new String(lbuf, 0, i - 2, UTF_8); name = new String(lbuf, 0, i - 2, UTF_8.INSTANCE);
if (is.peek() == ' ') { if (is.peek() == ' ') {
lastline = new byte[len - i]; lastline = new byte[len - i];
System.arraycopy(lbuf, i, lastline, 0, len - i); System.arraycopy(lbuf, i, lastline, 0, len - i);
continue; continue;
} }
value = new String(lbuf, i, len - i, UTF_8); value = new String(lbuf, i, len - i, UTF_8.INSTANCE);
} }
try { try {
if ((putValue(name, value) != null) && (!lineContinued)) { if ((putValue(name, value) != null) && (!lineContinued)) {

View file

@ -33,10 +33,9 @@ import java.io.OutputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import sun.nio.cs.UTF_8;
import sun.security.util.SecurityProperties; import sun.security.util.SecurityProperties;
import static java.nio.charset.StandardCharsets.UTF_8;
/** /**
* The Manifest class is used to maintain Manifest entry names and their * The Manifest class is used to maintain Manifest entry names and their
* associated Attributes. There are main Manifest Attributes as well as * associated Attributes. There are main Manifest Attributes as well as
@ -237,7 +236,7 @@ public class Manifest implements Cloneable {
*/ */
static void println72(OutputStream out, String line) throws IOException { static void println72(OutputStream out, String line) throws IOException {
if (!line.isEmpty()) { if (!line.isEmpty()) {
byte[] lineBytes = line.getBytes(UTF_8); byte[] lineBytes = line.getBytes(UTF_8.INSTANCE);
int length = lineBytes.length; int length = lineBytes.length;
// first line can hold one byte more than subsequent lines which // first line can hold one byte more than subsequent lines which
// start with a continuation line break space // start with a continuation line break space
@ -337,7 +336,7 @@ public class Manifest implements Cloneable {
lastline = buf; lastline = buf;
continue; continue;
} }
name = new String(buf, 0, buf.length, UTF_8); name = new String(buf, 0, buf.length, UTF_8.INSTANCE);
lastline = null; lastline = null;
} }
Attributes attr = getAttributes(name); Attributes attr = getAttributes(name);
@ -362,11 +361,7 @@ public class Manifest implements Cloneable {
if (toLower(lbuf[0]) == 'n' && toLower(lbuf[1]) == 'a' && if (toLower(lbuf[0]) == 'n' && toLower(lbuf[1]) == 'a' &&
toLower(lbuf[2]) == 'm' && toLower(lbuf[3]) == 'e' && toLower(lbuf[2]) == 'm' && toLower(lbuf[3]) == 'e' &&
lbuf[4] == ':' && lbuf[5] == ' ') { lbuf[4] == ':' && lbuf[5] == ' ') {
try { return new String(lbuf, 6, len - 6, UTF_8.INSTANCE);
return new String(lbuf, 6, len - 6, UTF_8);
}
catch (Exception e) {
}
} }
return null; return null;
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -33,7 +33,7 @@ import java.nio.charset.CharsetEncoder;
import java.nio.charset.CharacterCodingException; import java.nio.charset.CharacterCodingException;
import java.nio.charset.CodingErrorAction; import java.nio.charset.CodingErrorAction;
import static java.nio.charset.StandardCharsets.UTF_8; import sun.nio.cs.UTF_8;
/** /**
* Utility class for zipfile name and comment decoding and encoding * Utility class for zipfile name and comment decoding and encoding
@ -67,10 +67,10 @@ class ZipCoder {
} }
// UTF_8.ArrayEn/Decoder is stateless, so make it singleton. // UTF_8.ArrayEn/Decoder is stateless, so make it singleton.
private static ZipCoder utf8 = new UTF8(UTF_8); private static ZipCoder utf8 = new UTF8(UTF_8.INSTANCE);
public static ZipCoder get(Charset charset) { public static ZipCoder get(Charset charset) {
if (charset == UTF_8) if (charset == UTF_8.INSTANCE)
return utf8; return utf8;
return new ZipCoder(charset); return new ZipCoder(charset);
} }

View file

@ -34,7 +34,6 @@ import java.io.RandomAccessFile;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.lang.ref.Cleaner.Cleanable; import java.lang.ref.Cleaner.Cleanable;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.InvalidPathException; import java.nio.file.InvalidPathException;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.Files; import java.nio.file.Files;
@ -65,6 +64,7 @@ import jdk.internal.misc.VM;
import jdk.internal.perf.PerfCounter; import jdk.internal.perf.PerfCounter;
import jdk.internal.ref.CleanerFactory; import jdk.internal.ref.CleanerFactory;
import jdk.internal.vm.annotation.Stable; import jdk.internal.vm.annotation.Stable;
import sun.nio.cs.UTF_8;
import static java.util.zip.ZipConstants64.*; import static java.util.zip.ZipConstants64.*;
import static java.util.zip.ZipUtils.*; import static java.util.zip.ZipUtils.*;
@ -165,7 +165,7 @@ public class ZipFile implements ZipConstants, Closeable {
* @since 1.3 * @since 1.3
*/ */
public ZipFile(File file, int mode) throws IOException { public ZipFile(File file, int mode) throws IOException {
this(file, mode, StandardCharsets.UTF_8); this(file, mode, UTF_8.INSTANCE);
} }
/** /**
@ -1042,7 +1042,7 @@ public class ZipFile implements ZipConstants, Closeable {
for (int i = 0; i < names.length; i++) { for (int i = 0; i < names.length; i++) {
int pos = zsrc.metanames[i]; int pos = zsrc.metanames[i];
names[i] = new String(cen, pos + CENHDR, CENNAM(cen, pos), names[i] = new String(cen, pos + CENHDR, CENNAM(cen, pos),
StandardCharsets.UTF_8); UTF_8.INSTANCE);
} }
return names; return names;
} }

View file

@ -30,7 +30,9 @@ import java.io.IOException;
import java.io.EOFException; import java.io.EOFException;
import java.io.PushbackInputStream; import java.io.PushbackInputStream;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import sun.nio.cs.UTF_8;
import static java.util.zip.ZipConstants64.*; import static java.util.zip.ZipConstants64.*;
import static java.util.zip.ZipUtils.*; import static java.util.zip.ZipUtils.*;
@ -77,7 +79,7 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
* @param in the actual input stream * @param in the actual input stream
*/ */
public ZipInputStream(InputStream in) { public ZipInputStream(InputStream in) {
this(in, StandardCharsets.UTF_8); this(in, UTF_8.INSTANCE);
} }
/** /**

View file

@ -28,11 +28,11 @@ package java.util.zip;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Vector; import java.util.Vector;
import java.util.HashSet; import java.util.HashSet;
import static java.util.zip.ZipConstants64.*; import static java.util.zip.ZipConstants64.*;
import static java.util.zip.ZipUtils.*; import static java.util.zip.ZipUtils.*;
import sun.nio.cs.UTF_8;
import sun.security.action.GetPropertyAction; import sun.security.action.GetPropertyAction;
/** /**
@ -116,7 +116,7 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant
* @param out the actual output stream * @param out the actual output stream
*/ */
public ZipOutputStream(OutputStream out) { public ZipOutputStream(OutputStream out) {
this(out, StandardCharsets.UTF_8); this(out, UTF_8.INSTANCE);
} }
/** /**

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -24,6 +24,8 @@
*/ */
package jdk.internal.module; package jdk.internal.module;
import sun.nio.cs.UTF_8;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -37,8 +39,6 @@ import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static java.nio.charset.StandardCharsets.*;
/** /**
* Generates the maps of concealed and exported packages to open at run-time. * Generates the maps of concealed and exported packages to open at run-time.
* *
@ -90,7 +90,9 @@ public class IllegalAccessMaps {
if (in == null) { if (in == null) {
throw new InternalError(rn + " not found"); throw new InternalError(rn + " not found");
} }
try (BufferedReader br = new BufferedReader(new InputStreamReader(in, UTF_8))) { try (BufferedReader br = new BufferedReader(
new InputStreamReader(in, UTF_8.INSTANCE)))
{
br.lines() br.lines()
.filter(line -> !line.isEmpty() && !line.startsWith("#")) .filter(line -> !line.isEmpty() && !line.startsWith("#"))
.forEach(pn -> { .forEach(pn -> {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -61,6 +61,8 @@ import java.util.stream.Collectors;
import java.util.zip.ZipException; import java.util.zip.ZipException;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import sun.nio.cs.UTF_8;
import jdk.internal.jmod.JmodFile; import jdk.internal.jmod.JmodFile;
import jdk.internal.jmod.JmodFile.Section; import jdk.internal.jmod.JmodFile.Section;
import jdk.internal.perf.PerfCounter; import jdk.internal.perf.PerfCounter;
@ -543,7 +545,7 @@ public class ModulePath implements ModuleFinder {
List<String> providerClasses = new ArrayList<>(); List<String> providerClasses = new ArrayList<>();
try (InputStream in = jf.getInputStream(entry)) { try (InputStream in = jf.getInputStream(entry)) {
BufferedReader reader BufferedReader reader
= new BufferedReader(new InputStreamReader(in, "UTF-8")); = new BufferedReader(new InputStreamReader(in, UTF_8.INSTANCE));
String cn; String cn;
while ((cn = nextLine(reader)) != null) { while ((cn = nextLine(reader)) != null) {
if (!cn.isEmpty()) { if (!cn.isEmpty()) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,7 +28,9 @@ import java.nio.ByteBuffer;
import java.security.Permission; import java.security.Permission;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import sun.nio.cs.UTF_8;
import jdk.internal.ref.CleanerFactory; import jdk.internal.ref.CleanerFactory;
/** /**
@ -413,7 +415,7 @@ public final class Perf {
public ByteBuffer createString(String name, int variability, public ByteBuffer createString(String name, int variability,
int units, String value, int maxLength) int units, String value, int maxLength)
{ {
byte[] v = getBytes(value); byte[] v = value.getBytes(UTF_8.INSTANCE);
byte[] v1 = new byte[v.length+1]; byte[] v1 = new byte[v.length+1];
System.arraycopy(v, 0, v1, 0, v.length); System.arraycopy(v, 0, v1, 0, v.length);
v1[v.length] = '\0'; v1[v.length] = '\0';
@ -452,7 +454,7 @@ public final class Perf {
public ByteBuffer createString(String name, int variability, public ByteBuffer createString(String name, int variability,
int units, String value) int units, String value)
{ {
byte[] v = getBytes(value); byte[] v = value.getBytes(UTF_8.INSTANCE);
byte[] v1 = new byte[v.length+1]; byte[] v1 = new byte[v.length+1];
System.arraycopy(v, 0, v1, 0, v.length); System.arraycopy(v, 0, v1, 0, v.length);
v1[v.length] = '\0'; v1[v.length] = '\0';
@ -491,24 +493,6 @@ public final class Perf {
int units, byte[] value, int units, byte[] value,
int maxLength); int maxLength);
/**
* convert string to an array of UTF-8 bytes
*/
private static byte[] getBytes(String s)
{
byte[] bytes = null;
try {
bytes = s.getBytes("UTF-8");
}
catch (UnsupportedEncodingException e) {
// ignore, UTF-8 encoding is always known
}
return bytes;
}
/** /**
* Return the value of the High Resolution Counter. * Return the value of the High Resolution Counter.
* *

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,10 +25,13 @@
package jdk.internal.util.jar; package jdk.internal.util.jar;
import sun.nio.cs.UTF_8;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
import java.util.jar.*; import java.util.jar.*;
import java.util.zip.*; import java.util.zip.*;
import static sun.security.action.GetPropertyAction.privilegedGetProperty; import static sun.security.action.GetPropertyAction.privilegedGetProperty;
/** /**
@ -250,7 +253,7 @@ public class JarIndex {
*/ */
public void write(OutputStream out) throws IOException { public void write(OutputStream out) throws IOException {
BufferedWriter bw = new BufferedWriter BufferedWriter bw = new BufferedWriter
(new OutputStreamWriter(out, "UTF8")); (new OutputStreamWriter(out, UTF_8.INSTANCE));
bw.write("JarIndex-Version: 1.0\n\n"); bw.write("JarIndex-Version: 1.0\n\n");
if (jarFiles != null) { if (jarFiles != null) {
@ -280,7 +283,7 @@ public class JarIndex {
*/ */
public void read(InputStream is) throws IOException { public void read(InputStream is) throws IOException {
BufferedReader br = new BufferedReader BufferedReader br = new BufferedReader
(new InputStreamReader(is, "UTF8")); (new InputStreamReader(is, UTF_8.INSTANCE));
String line = null; String line = null;
String currentJar = null; String currentJar = null;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,19 +26,20 @@
package sun.net.www; package sun.net.www;
import java.io.File; import java.io.File;
import java.net.URL;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException; import java.nio.charset.CharacterCodingException;
import sun.nio.cs.ThreadLocalCoders;
import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetDecoder;
import java.nio.charset.CoderResult; import java.nio.charset.CoderResult;
import java.nio.charset.CodingErrorAction; import java.nio.charset.CodingErrorAction;
import sun.nio.cs.ThreadLocalCoders;
import sun.nio.cs.UTF_8;
/** /**
* A class that contains useful routines common to sun.net.www * A class that contains useful routines common to sun.net.www
* @author Mike McCloskey * @author Mike McCloskey
@ -176,7 +177,7 @@ public final class ParseUtil {
StringBuilder sb = new StringBuilder(n); StringBuilder sb = new StringBuilder(n);
ByteBuffer bb = ByteBuffer.allocate(n); ByteBuffer bb = ByteBuffer.allocate(n);
CharBuffer cb = CharBuffer.allocate(n); CharBuffer cb = CharBuffer.allocate(n);
CharsetDecoder dec = ThreadLocalCoders.decoderFor("UTF-8") CharsetDecoder dec = ThreadLocalCoders.decoderFor(UTF_8.INSTANCE)
.onMalformedInput(CodingErrorAction.REPORT) .onMalformedInput(CodingErrorAction.REPORT)
.onUnmappableCharacter(CodingErrorAction.REPORT); .onUnmappableCharacter(CodingErrorAction.REPORT);
@ -496,7 +497,7 @@ public final class ParseUtil {
private static void appendEncoded(StringBuilder sb, char c) { private static void appendEncoded(StringBuilder sb, char c) {
ByteBuffer bb = null; ByteBuffer bb = null;
try { try {
bb = ThreadLocalCoders.encoderFor("UTF-8") bb = ThreadLocalCoders.encoderFor(UTF_8.INSTANCE)
.encode(CharBuffer.wrap("" + c)); .encode(CharBuffer.wrap("" + c));
} catch (CharacterCodingException x) { } catch (CharacterCodingException x) {
assert false; assert false;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -29,6 +29,7 @@ import java.util.*;
import sun.net.*; import sun.net.*;
import sun.net.www.*; import sun.net.www.*;
import sun.nio.cs.US_ASCII;
/** /**
* A <code>ChunkedInputStream</code> provides a stream for reading a body of * A <code>ChunkedInputStream</code> provides a stream for reading a body of
@ -307,7 +308,8 @@ class ChunkedInputStream extends InputStream implements Hurryable {
/* /*
* Extract the chunk size from the header (ignoring extensions). * Extract the chunk size from the header (ignoring extensions).
*/ */
String header = new String(rawData, rawPos, pos-rawPos+1, "US-ASCII"); String header = new String(rawData, rawPos, pos-rawPos+1,
US_ASCII.INSTANCE);
for (i=0; i < header.length(); i++) { for (i=0; i < header.length(); i++) {
if (Character.digit(header.charAt(i), 16) == -1) if (Character.digit(header.charAt(i), 16) == -1)
break; break;
@ -461,7 +463,8 @@ class ChunkedInputStream extends InputStream implements Hurryable {
* Extract any tailers and append them to the message * Extract any tailers and append them to the message
* headers. * headers.
*/ */
String trailer = new String(rawData, rawPos, pos-rawPos, "US-ASCII"); String trailer = new String(rawData, rawPos, pos-rawPos,
US_ASCII.INSTANCE);
i = trailer.indexOf(':'); i = trailer.indexOf(':');
if (i == -1) { if (i == -1) {
throw new IOException("Malformed tailer - format should be key:value"); throw new IOException("Malformed tailer - format should be key:value");

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2004, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,6 +26,8 @@ package sun.net.www.http;
import java.io.*; import java.io.*;
import sun.nio.cs.US_ASCII;
/** /**
* OutputStream that sends the output to the underlying stream using chunked * OutputStream that sends the output to the underlying stream using chunked
* encoding as specified in RFC 2068. * encoding as specified in RFC 2068.
@ -67,20 +69,15 @@ public class ChunkedOutputStream extends PrintStream {
} }
/* return a header for a particular chunk size */ /* return a header for a particular chunk size */
private static byte[] getHeader(int size){ private static byte[] getHeader(int size) {
try {
String hexStr = Integer.toHexString(size); String hexStr = Integer.toHexString(size);
byte[] hexBytes = hexStr.getBytes("US-ASCII"); byte[] hexBytes = hexStr.getBytes(US_ASCII.INSTANCE);
byte[] header = new byte[getHeaderSize(size)]; byte[] header = new byte[getHeaderSize(size)];
for (int i=0; i<hexBytes.length; i++) for (int i=0; i<hexBytes.length; i++)
header[i] = hexBytes[i]; header[i] = hexBytes[i];
header[hexBytes.length] = CRLF[0]; header[hexBytes.length] = CRLF[0];
header[hexBytes.length+1] = CRLF[1]; header[hexBytes.length+1] = CRLF[1];
return header; return header;
} catch (java.io.UnsupportedEncodingException e) {
/* This should never happen */
throw new InternalError(e.getMessage(), e);
}
} }
public ChunkedOutputStream(PrintStream o) { public ChunkedOutputStream(PrintStream o) {

View file

@ -38,8 +38,8 @@ import java.util.Arrays;
import java.util.Base64; import java.util.Base64;
import java.util.Objects; import java.util.Objects;
import sun.net.www.HeaderParser; import sun.net.www.HeaderParser;
import static java.nio.charset.StandardCharsets.UTF_8; import sun.nio.cs.ISO_8859_1;
import static java.nio.charset.StandardCharsets.ISO_8859_1; import sun.nio.cs.UTF_8;
/** /**
* BasicAuthentication: Encapsulate an http server authentication using * BasicAuthentication: Encapsulate an http server authentication using
@ -101,10 +101,11 @@ class BasicAuthentication extends AuthenticationInfo {
char[] password = pw.getPassword(); char[] password = pw.getPassword();
CharBuffer cbuf = CharBuffer.allocate(plain.length() + password.length); CharBuffer cbuf = CharBuffer.allocate(plain.length() + password.length);
cbuf.put(plain).put(password).flip(); cbuf.put(plain).put(password).flip();
Charset charset = isUTF8 ? UTF_8 : ISO_8859_1; Charset charset = isUTF8 ? UTF_8.INSTANCE : ISO_8859_1.INSTANCE;
ByteBuffer buf = charset.encode(cbuf); ByteBuffer buf = charset.encode(cbuf);
ByteBuffer enc = Base64.getEncoder().encode(buf); ByteBuffer enc = Base64.getEncoder().encode(buf);
String ret = "Basic " + new String(enc.array(), enc.position(), enc.remaining(), ISO_8859_1); String ret = "Basic " + new String(enc.array(), enc.position(), enc.remaining(),
ISO_8859_1.INSTANCE);
Arrays.fill(buf.array(), (byte) 0); Arrays.fill(buf.array(), (byte) 0);
Arrays.fill(enc.array(), (byte) 0); Arrays.fill(enc.array(), (byte) 0);
Arrays.fill(cbuf.array(), (char) 0); Arrays.fill(cbuf.array(), (char) 0);

View file

@ -26,19 +26,21 @@
package sun.net.www.protocol.http; package sun.net.www.protocol.http;
import java.io.*; import java.io.*;
import java.net.URL;
import java.net.ProtocolException;
import java.net.PasswordAuthentication; import java.net.PasswordAuthentication;
import java.util.Arrays; import java.net.ProtocolException;
import java.util.Random; import java.net.URL;
import java.security.AccessController;
import sun.net.www.HeaderParser;
import sun.net.NetProperties;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.security.AccessController; import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
import java.util.Random;
import sun.net.NetProperties;
import sun.net.www.HeaderParser;
import sun.nio.cs.ISO_8859_1;
import static sun.net.www.protocol.http.HttpURLConnection.HTTP_CONNECT; import static sun.net.www.protocol.http.HttpURLConnection.HTTP_CONNECT;
/** /**
@ -521,11 +523,7 @@ class DigestAuthentication extends AuthenticationInfo {
}; };
private String encode(String src, char[] passwd, MessageDigest md) { private String encode(String src, char[] passwd, MessageDigest md) {
try { md.update(src.getBytes(ISO_8859_1.INSTANCE));
md.update(src.getBytes("ISO-8859-1"));
} catch (java.io.UnsupportedEncodingException uee) {
assert false;
}
if (passwd != null) { if (passwd != null) {
byte[] passwdBytes = new byte[passwd.length]; byte[] passwdBytes = new byte[passwd.length];
for (int i=0; i<passwd.length; i++) for (int i=0; i<passwd.length; i++)

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -87,17 +87,17 @@ public class ThreadLocalCoders {
private static Cache decoderCache = new Cache(CACHE_SIZE) { private static Cache decoderCache = new Cache(CACHE_SIZE) {
boolean hasName(Object ob, Object name) { boolean hasName(Object ob, Object name) {
if (name instanceof String)
return (((CharsetDecoder)ob).charset().name().equals(name));
if (name instanceof Charset) if (name instanceof Charset)
return ((CharsetDecoder)ob).charset().equals(name); return ((CharsetDecoder)ob).charset().equals(name);
if (name instanceof String)
return (((CharsetDecoder)ob).charset().name().equals(name));
return false; return false;
} }
Object create(Object name) { Object create(Object name) {
if (name instanceof String)
return Charset.forName((String)name).newDecoder();
if (name instanceof Charset) if (name instanceof Charset)
return ((Charset)name).newDecoder(); return ((Charset)name).newDecoder();
if (name instanceof String)
return Charset.forName((String)name).newDecoder();
assert false; assert false;
return null; return null;
} }
@ -111,17 +111,17 @@ public class ThreadLocalCoders {
private static Cache encoderCache = new Cache(CACHE_SIZE) { private static Cache encoderCache = new Cache(CACHE_SIZE) {
boolean hasName(Object ob, Object name) { boolean hasName(Object ob, Object name) {
if (name instanceof String)
return (((CharsetEncoder)ob).charset().name().equals(name));
if (name instanceof Charset) if (name instanceof Charset)
return ((CharsetEncoder)ob).charset().equals(name); return ((CharsetEncoder)ob).charset().equals(name);
if (name instanceof String)
return (((CharsetEncoder)ob).charset().name().equals(name));
return false; return false;
} }
Object create(Object name) { Object create(Object name) {
if (name instanceof String)
return Charset.forName((String)name).newEncoder();
if (name instanceof Charset) if (name instanceof Charset)
return ((Charset)name).newEncoder(); return ((Charset)name).newEncoder();
if (name instanceof String)
return Charset.forName((String)name).newEncoder();
assert false; assert false;
return null; return null;
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,9 @@
package sun.util; package sun.util;
import sun.nio.cs.ISO_8859_1;
import sun.nio.cs.UTF_8;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
@ -70,7 +73,7 @@ public class PropertyResourceBundleCharset extends Charset {
private final class PropertiesFileDecoder extends CharsetDecoder { private final class PropertiesFileDecoder extends CharsetDecoder {
private CharsetDecoder cdUTF_8 = StandardCharsets.UTF_8.newDecoder() private CharsetDecoder cdUTF_8 = UTF_8.INSTANCE.newDecoder()
.onMalformedInput(CodingErrorAction.REPORT) .onMalformedInput(CodingErrorAction.REPORT)
.onUnmappableCharacter(CodingErrorAction.REPORT); .onUnmappableCharacter(CodingErrorAction.REPORT);
private CharsetDecoder cdISO_8859_1 = null; private CharsetDecoder cdISO_8859_1 = null;
@ -98,7 +101,7 @@ public class PropertyResourceBundleCharset extends Charset {
assert cr.isMalformed() || cr.isUnmappable(); assert cr.isMalformed() || cr.isUnmappable();
in.reset(); in.reset();
out.reset(); out.reset();
cdISO_8859_1 = StandardCharsets.ISO_8859_1.newDecoder(); cdISO_8859_1 = ISO_8859_1.INSTANCE.newDecoder();
return cdISO_8859_1.decode(in, out, false); return cdISO_8859_1.decode(in, out, false);
} }
} }

View file

@ -25,6 +25,8 @@
package sun.nio.fs; package sun.nio.fs;
import sun.nio.cs.UTF_8;
import jdk.internal.util.StaticProperty; import jdk.internal.util.StaticProperty;
import java.nio.file.*; import java.nio.file.*;
@ -277,7 +279,7 @@ abstract class UnixFileStore
Path file = Path.of(fstypes); Path file = Path.of(fstypes);
try { try {
try (ReadableByteChannel rbc = Files.newByteChannel(file)) { try (ReadableByteChannel rbc = Files.newByteChannel(file)) {
result.load(Channels.newReader(rbc, "UTF-8")); result.load(Channels.newReader(rbc, UTF_8.INSTANCE));
} }
} catch (IOException x) { } catch (IOException x) {
} }

View file

@ -39,7 +39,6 @@ import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.io.UnsupportedEncodingException;
import java.lang.System.Logger.Level; import java.lang.System.Logger.Level;
import java.net.ConnectException; import java.net.ConnectException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -74,6 +73,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import static java.lang.String.format; import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.joining;
import jdk.internal.net.http.HttpRequestImpl; import jdk.internal.net.http.HttpRequestImpl;
@ -538,15 +538,9 @@ public final class Utils {
public static String stackTrace(Throwable t) { public static String stackTrace(Throwable t) {
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
String s = null; PrintStream p = new PrintStream(bos, true, US_ASCII);
try {
PrintStream p = new PrintStream(bos, true, "US-ASCII");
t.printStackTrace(p); t.printStackTrace(p);
s = bos.toString("US-ASCII"); return bos.toString(US_ASCII);
} catch (UnsupportedEncodingException ex) {
throw new InternalError(ex); // Can't happen
}
return s;
} }
/** /**

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -34,6 +34,8 @@ import javax.xml.transform.stream.*;
import org.xml.sax.*; import org.xml.sax.*;
import org.w3c.dom.*; import org.w3c.dom.*;
import static java.nio.charset.StandardCharsets.UTF_8;
/** /**
* XML Support for java.util.prefs. Methods to import and export preference * XML Support for java.util.prefs. Methods to import and export preference
* nodes and subtrees. * nodes and subtrees.
@ -274,7 +276,7 @@ class XmlSupport {
//an OutputStream object embedded, creating a Writer object on top of that //an OutputStream object embedded, creating a Writer object on top of that
//OutputStream object however works. //OutputStream object however works.
t.transform(new DOMSource(doc), t.transform(new DOMSource(doc),
new StreamResult(new BufferedWriter(new OutputStreamWriter(out, "UTF-8")))); new StreamResult(new BufferedWriter(new OutputStreamWriter(out, UTF_8))));
} catch(TransformerException e) { } catch(TransformerException e) {
throw new AssertionError(e); throw new AssertionError(e);
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -42,6 +42,8 @@ import com.sun.rowset.internal.*;
import com.sun.rowset.providers.*; import com.sun.rowset.providers.*;
import sun.reflect.misc.ReflectUtil; import sun.reflect.misc.ReflectUtil;
import static java.nio.charset.StandardCharsets.US_ASCII;
/** /**
* The standard implementation of the <code>CachedRowSet</code> interface. * The standard implementation of the <code>CachedRowSet</code> interface.
* *
@ -2348,15 +2350,11 @@ public class CachedRowSetImpl extends BaseRowSet implements RowSet, RowSetIntern
return null; return null;
} }
try {
if (isString(RowSetMD.getColumnType(columnIndex))) { if (isString(RowSetMD.getColumnType(columnIndex))) {
asciiStream = new ByteArrayInputStream(((String)value).getBytes("ASCII")); asciiStream = new ByteArrayInputStream(((String)value).getBytes(US_ASCII));
} else { } else {
throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString()); throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString());
} }
} catch (java.io.UnsupportedEncodingException ex) {
throw new SQLException(ex.getMessage());
}
return asciiStream; return asciiStream;
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,7 @@
* @test * @test
* @build TrySetAccessibleTest * @build TrySetAccessibleTest
* @modules java.base/java.lang:open * @modules java.base/java.lang:open
* java.base/jdk.internal.module
* java.base/jdk.internal.perf * java.base/jdk.internal.perf
* java.base/jdk.internal.misc:+open * java.base/jdk.internal.misc:+open
* @run testng/othervm --illegal-access=deny TrySetAccessibleTest * @run testng/othervm --illegal-access=deny TrySetAccessibleTest
@ -38,6 +39,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import jdk.internal.misc.Unsafe; import jdk.internal.misc.Unsafe;
import jdk.internal.module.ModulePath;
import jdk.internal.perf.Perf; import jdk.internal.perf.Perf;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -80,7 +82,7 @@ public class TrySetAccessibleTest {
* Invoke a private method on a public class in an exported package * Invoke a private method on a public class in an exported package
*/ */
public void testPrivateMethodInExportedPackage() throws Exception { public void testPrivateMethodInExportedPackage() throws Exception {
Method m = Perf.class.getDeclaredMethod("getBytes", String.class); Method m = ModulePath.class.getDeclaredMethod("packageName", String.class);
try { try {
m.invoke(null); m.invoke(null);
assertTrue(false); assertTrue(false);