mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8234147: Avoid looking up standard charsets in core libraries
Reviewed-by: alanb
This commit is contained in:
parent
4e64af81a2
commit
cd589d8469
36 changed files with 200 additions and 237 deletions
|
@ -31,6 +31,9 @@ import java.io.IOException;
|
|||
import java.io.OutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import sun.nio.cs.ISO_8859_1;
|
||||
|
||||
import jdk.internal.HotSpotIntrinsicCandidate;
|
||||
|
||||
/**
|
||||
|
@ -584,7 +587,7 @@ public class Base64 {
|
|||
* if {@code src} is not in valid Base64 scheme
|
||||
*/
|
||||
public byte[] decode(String src) {
|
||||
return decode(src.getBytes(StandardCharsets.ISO_8859_1));
|
||||
return decode(src.getBytes(ISO_8859_1.INSTANCE));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,6 +46,9 @@ import java.util.function.BiConsumer;
|
|||
import java.util.function.BiFunction;
|
||||
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.misc.Unsafe;
|
||||
import jdk.internal.util.ArraysSupport;
|
||||
|
@ -909,7 +912,7 @@ public class Properties extends Hashtable<Object,Object> {
|
|||
public void store(OutputStream out, String comments)
|
||||
throws IOException
|
||||
{
|
||||
store0(new BufferedWriter(new OutputStreamWriter(out, "8859_1")),
|
||||
store0(new BufferedWriter(new OutputStreamWriter(out, ISO_8859_1.INSTANCE)),
|
||||
comments,
|
||||
true);
|
||||
}
|
||||
|
@ -1001,7 +1004,7 @@ public class Properties extends Hashtable<Object,Object> {
|
|||
public void storeToXML(OutputStream os, String comment)
|
||||
throws IOException
|
||||
{
|
||||
storeToXML(os, comment, "UTF-8");
|
||||
storeToXML(os, comment, UTF_8.INSTANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,8 +44,8 @@ import java.io.InputStreamReader;
|
|||
import java.io.Reader;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.MalformedInputException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.charset.UnmappableCharacterException;
|
||||
import sun.nio.cs.ISO_8859_1;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
import sun.util.PropertyResourceBundleCharset;
|
||||
import sun.util.ResourceBundleEnumeration;
|
||||
|
@ -176,7 +176,7 @@ public class PropertyResourceBundle extends ResourceBundle {
|
|||
public PropertyResourceBundle (InputStream stream) throws IOException {
|
||||
this(new InputStreamReader(stream,
|
||||
"ISO-8859-1".equals(encoding) ?
|
||||
StandardCharsets.ISO_8859_1.newDecoder() :
|
||||
ISO_8859_1.INSTANCE.newDecoder() :
|
||||
new PropertyResourceBundleCharset("UTF-8".equals(encoding)).newDecoder()));
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,8 @@ import java.util.function.Supplier;
|
|||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import sun.nio.cs.UTF_8;
|
||||
|
||||
import jdk.internal.loader.BootLoader;
|
||||
import jdk.internal.loader.ClassLoaders;
|
||||
import jdk.internal.access.JavaLangAccess;
|
||||
|
@ -55,7 +57,6 @@ import jdk.internal.module.ServicesCatalog.ServiceProvider;
|
|||
import jdk.internal.reflect.CallerSensitive;
|
||||
import jdk.internal.reflect.Reflection;
|
||||
|
||||
|
||||
/**
|
||||
* A facility to load implementations of a service.
|
||||
*
|
||||
|
@ -1164,7 +1165,7 @@ public final class ServiceLoader<S>
|
|||
uc.setUseCaches(false);
|
||||
try (InputStream in = uc.getInputStream();
|
||||
BufferedReader r
|
||||
= new BufferedReader(new InputStreamReader(in, "utf-8")))
|
||||
= new BufferedReader(new InputStreamReader(in, UTF_8.INSTANCE)))
|
||||
{
|
||||
int lc = 1;
|
||||
while ((lc = parseLine(u, r, lc, names)) >= 0);
|
||||
|
|
|
@ -36,9 +36,9 @@ import java.util.Set;
|
|||
|
||||
import jdk.internal.misc.VM;
|
||||
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
|
||||
|
@ -337,7 +337,7 @@ public class Attributes implements Map<Object,Object>, Cloneable {
|
|||
buffer.append(vername);
|
||||
buffer.append(": ");
|
||||
buffer.append(version);
|
||||
out.write(buffer.toString().getBytes(UTF_8));
|
||||
out.write(buffer.toString().getBytes(UTF_8.INSTANCE));
|
||||
Manifest.println(out);
|
||||
}
|
||||
|
||||
|
@ -399,7 +399,7 @@ public class Attributes implements Map<Object,Object>, Cloneable {
|
|||
lastline = buf;
|
||||
continue;
|
||||
}
|
||||
value = new String(buf, 0, buf.length, UTF_8);
|
||||
value = new String(buf, 0, buf.length, UTF_8.INSTANCE);
|
||||
lastline = null;
|
||||
} else {
|
||||
while (lbuf[i++] != ':') {
|
||||
|
@ -412,13 +412,13 @@ public class Attributes implements Map<Object,Object>, Cloneable {
|
|||
throw new IOException("invalid header field ("
|
||||
+ 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() == ' ') {
|
||||
lastline = new byte[len - i];
|
||||
System.arraycopy(lbuf, i, lastline, 0, len - i);
|
||||
continue;
|
||||
}
|
||||
value = new String(lbuf, i, len - i, UTF_8);
|
||||
value = new String(lbuf, i, len - i, UTF_8.INSTANCE);
|
||||
}
|
||||
try {
|
||||
if ((putValue(name, value) != null) && (!lineContinued)) {
|
||||
|
|
|
@ -33,10 +33,9 @@ import java.io.OutputStream;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import sun.nio.cs.UTF_8;
|
||||
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
|
||||
* 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 {
|
||||
if (!line.isEmpty()) {
|
||||
byte[] lineBytes = line.getBytes(UTF_8);
|
||||
byte[] lineBytes = line.getBytes(UTF_8.INSTANCE);
|
||||
int length = lineBytes.length;
|
||||
// first line can hold one byte more than subsequent lines which
|
||||
// start with a continuation line break space
|
||||
|
@ -337,7 +336,7 @@ public class Manifest implements Cloneable {
|
|||
lastline = buf;
|
||||
continue;
|
||||
}
|
||||
name = new String(buf, 0, buf.length, UTF_8);
|
||||
name = new String(buf, 0, buf.length, UTF_8.INSTANCE);
|
||||
lastline = null;
|
||||
}
|
||||
Attributes attr = getAttributes(name);
|
||||
|
@ -362,11 +361,7 @@ public class Manifest implements Cloneable {
|
|||
if (toLower(lbuf[0]) == 'n' && toLower(lbuf[1]) == 'a' &&
|
||||
toLower(lbuf[2]) == 'm' && toLower(lbuf[3]) == 'e' &&
|
||||
lbuf[4] == ':' && lbuf[5] == ' ') {
|
||||
try {
|
||||
return new String(lbuf, 6, len - 6, UTF_8);
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
return new String(lbuf, 6, len - 6, UTF_8.INSTANCE);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* 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.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
|
||||
|
@ -67,10 +67,10 @@ class ZipCoder {
|
|||
}
|
||||
|
||||
// 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) {
|
||||
if (charset == UTF_8)
|
||||
if (charset == UTF_8.INSTANCE)
|
||||
return utf8;
|
||||
return new ZipCoder(charset);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ import java.io.RandomAccessFile;
|
|||
import java.io.UncheckedIOException;
|
||||
import java.lang.ref.Cleaner.Cleanable;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.InvalidPathException;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.nio.file.Files;
|
||||
|
@ -65,6 +64,7 @@ import jdk.internal.misc.VM;
|
|||
import jdk.internal.perf.PerfCounter;
|
||||
import jdk.internal.ref.CleanerFactory;
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
import sun.nio.cs.UTF_8;
|
||||
|
||||
import static java.util.zip.ZipConstants64.*;
|
||||
import static java.util.zip.ZipUtils.*;
|
||||
|
@ -165,7 +165,7 @@ public class ZipFile implements ZipConstants, Closeable {
|
|||
* @since 1.3
|
||||
*/
|
||||
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++) {
|
||||
int pos = zsrc.metanames[i];
|
||||
names[i] = new String(cen, pos + CENHDR, CENNAM(cen, pos),
|
||||
StandardCharsets.UTF_8);
|
||||
UTF_8.INSTANCE);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,9 @@ import java.io.IOException;
|
|||
import java.io.EOFException;
|
||||
import java.io.PushbackInputStream;
|
||||
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.ZipUtils.*;
|
||||
|
||||
|
@ -77,7 +79,7 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
|
|||
* @param in the actual input stream
|
||||
*/
|
||||
public ZipInputStream(InputStream in) {
|
||||
this(in, StandardCharsets.UTF_8);
|
||||
this(in, UTF_8.INSTANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,11 +28,11 @@ package java.util.zip;
|
|||
import java.io.OutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Vector;
|
||||
import java.util.HashSet;
|
||||
import static java.util.zip.ZipConstants64.*;
|
||||
import static java.util.zip.ZipUtils.*;
|
||||
import sun.nio.cs.UTF_8;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
/**
|
||||
|
@ -116,7 +116,7 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant
|
|||
* @param out the actual output stream
|
||||
*/
|
||||
public ZipOutputStream(OutputStream out) {
|
||||
this(out, StandardCharsets.UTF_8);
|
||||
this(out, UTF_8.INSTANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue