8272805: Avoid looking up standard charsets

Reviewed-by: weijun, naoto, dfuchs, azvegint, erikj
This commit is contained in:
Sergey Bylokhov 2021-09-02 22:56:20 +00:00
parent 92b05fe0f4
commit 7fff22afe7
53 changed files with 236 additions and 266 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021, 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
@ -27,7 +27,6 @@ package build.tools.generatelsrequivmaps;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.ZoneId;
@ -79,8 +78,7 @@ public class EquivMapsGenerator {
String preferred = null;
String prefix = null;
for (String line : Files.readAllLines(Paths.get(filename),
Charset.forName("UTF-8"))) {
for (String line : Files.readAllLines(Paths.get(filename))) {
line = line.toLowerCase(Locale.ROOT);
int index = line.indexOf(' ') + 1;
if (line.startsWith("file-date:")) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -72,6 +72,8 @@ import java.util.BitSet;
import javax.swing.*;
import javax.swing.event.*;
import static java.nio.charset.StandardCharsets.UTF_16;
/**
* Font2DTest.java
*
@ -589,7 +591,7 @@ public final class Font2DTest extends JPanel
if (numBytes >= 2 &&
(( byteData[0] == (byte) 0xFF && byteData[1] == (byte) 0xFE ) ||
( byteData[0] == (byte) 0xFE && byteData[1] == (byte) 0xFF )))
fileText = new String( byteData, "UTF-16" );
fileText = new String(byteData, UTF_16);
/// Otherwise, use system default encoding
else
fileText = new String( byteData );
@ -647,7 +649,7 @@ public final class Font2DTest extends JPanel
showFontInfoCBMI.getState() + "\n" +
rm.getSelectedItem() + "\n" +
range[0] + "\n" + range[1] + "\n" + curOptions + tFileName);
byte[] toBeWritten = completeOptions.getBytes( "UTF-16" );
byte[] toBeWritten = completeOptions.getBytes(UTF_16);
bos.write( toBeWritten, 0, toBeWritten.length );
bos.close();
}
@ -712,7 +714,7 @@ public final class Font2DTest extends JPanel
(byteData[0] != (byte) 0xFE || byteData[1] != (byte) 0xFF) )
throw new Exception( "Not a Font2DTest options file" );
String options = new String( byteData, "UTF-16" );
String options = new String(byteData, UTF_16);
StringTokenizer perLine = new StringTokenizer( options, "\n" );
String title = perLine.nextToken();
if ( !title.equals( "Font2DTest Option File" ))

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -80,6 +80,7 @@ import javax.imageio.*;
import javax.swing.*;
import static java.awt.RenderingHints.*;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
/**
* FontPanel.java
@ -643,7 +644,7 @@ public final class FontPanel extends JPanel implements AdjustmentListener {
break;
case DRAW_BYTES:
try {
byte[] lineBytes = line.getBytes( "ISO-8859-1" );
byte[] lineBytes = line.getBytes(ISO_8859_1);
g2.drawBytes( lineBytes, 0, lineBytes.length, 0, 0 );
}
catch ( Exception e ) {

View File

@ -1,6 +1,5 @@
/*
*
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -46,6 +45,8 @@ import java.io.*;
import java.applet.*;
import java.net.*;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* A generic SwingSet2 demo module
*
@ -155,7 +156,7 @@ public class DemoModule extends JFrame {
try {
url = getClass().getResource(filename);
is = url.openStream();
isr = new InputStreamReader(is, "UTF-8");
isr = new InputStreamReader(is, UTF_8);
BufferedReader reader = new BufferedReader(isr);
// Read one line at a time, htmlize using super-spiffy

View File

@ -1,6 +1,5 @@
/*
*
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -44,6 +43,8 @@ import java.io.*;
import java.applet.*;
import java.net.*;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* JTree Demo
*
@ -84,7 +85,7 @@ public class TreeDemo extends DemoModule {
try {
// convert url to buffered string
InputStream is = url.openStream();
InputStreamReader isr = new InputStreamReader(is, "UTF-8");
InputStreamReader isr = new InputStreamReader(is, UTF_8);
BufferedReader reader = new BufferedReader(isr);
// read one line at a time, put into tree

View File

@ -37,7 +37,10 @@ import java.util.Comparator;
import java.util.Arrays;
import java.util.Locale;
import static java.nio.charset.StandardCharsets.*;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static java.nio.charset.StandardCharsets.UTF_16BE;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* Output stream marshaling DER-encoded data. This is eventually provided

View File

@ -34,7 +34,10 @@ import java.math.BigInteger;
import java.nio.charset.Charset;
import java.util.*;
import static java.nio.charset.StandardCharsets.*;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static java.nio.charset.StandardCharsets.UTF_16BE;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* Represents a single DER-encoded value. DER encoding rules are a subset

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, 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
@ -51,6 +51,13 @@ import java.util.SortedSet;
import java.util.TreeSet;
import java.util.function.Supplier;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static java.nio.charset.StandardCharsets.UTF_16;
import static java.nio.charset.StandardCharsets.UTF_16BE;
import static java.nio.charset.StandardCharsets.UTF_16LE;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* Utility class with different datatransfer helper functions.
*
@ -115,12 +122,12 @@ public class DataFlavorUtil {
private static SortedSet<String> load() {
final SortedSet<String> tempSet = new TreeSet<>(getCharsetComparator().reversed());
tempSet.add("US-ASCII");
tempSet.add("ISO-8859-1");
tempSet.add("UTF-8");
tempSet.add("UTF-16BE");
tempSet.add("UTF-16LE");
tempSet.add("UTF-16");
tempSet.add(US_ASCII.name());
tempSet.add(ISO_8859_1.name());
tempSet.add(UTF_8.name());
tempSet.add(UTF_16BE.name());
tempSet.add(UTF_16LE.name());
tempSet.add(UTF_16.name());
tempSet.add(Charset.defaultCharset().name());
return Collections.unmodifiableSortedSet(tempSet);
}
@ -318,13 +325,13 @@ public class DataFlavorUtil {
Map<String, Integer> charsetsMap = new HashMap<>(8, 1.0f);
// we prefer Unicode charsets
charsetsMap.put(canonicalName("UTF-16LE"), 4);
charsetsMap.put(canonicalName("UTF-16BE"), 5);
charsetsMap.put(canonicalName("UTF-8"), 6);
charsetsMap.put(canonicalName("UTF-16"), 7);
charsetsMap.put(UTF_16LE.name(), 4);
charsetsMap.put(UTF_16BE.name(), 5);
charsetsMap.put(UTF_8.name(), 6);
charsetsMap.put(UTF_16.name(), 7);
// US-ASCII is the worst charset supported
charsetsMap.put(canonicalName("US-ASCII"), WORST_CHARSET_INDEX);
charsetsMap.put(US_ASCII.name(), WORST_CHARSET_INDEX);
charsetsMap.putIfAbsent(Charset.defaultCharset().name(), DEFAULT_CHARSET_INDEX);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, 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
@ -27,9 +27,10 @@ package sun.font;
import java.nio.charset.Charset;
import java.util.HashMap;
import sun.awt.FontConfiguration;
import sun.font.CompositeFontDescriptor;
import sun.font.SunFontManager;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
class CFontConfiguration extends FontConfiguration {
@ -79,7 +80,7 @@ class CFontConfiguration extends FontConfiguration {
@Override
protected Charset getDefaultFontCharset(String fontName) {
return Charset.forName("ISO8859_1");
return ISO_8859_1;
}
@Override

View File

@ -42,6 +42,7 @@ import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.SequenceInputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
@ -216,7 +217,7 @@ public class PNGImageReader extends ImageReader {
resetStreamSettings();
}
private String readNullTerminatedString(String charset, int maxLen) throws IOException {
private String readNullTerminatedString(Charset charset, int maxLen) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int b = 0;
int count = 0;
@ -438,7 +439,7 @@ public class PNGImageReader extends ImageReader {
}
private void parse_iCCP_chunk(int chunkLength) throws IOException {
String keyword = readNullTerminatedString("ISO-8859-1", 80);
String keyword = readNullTerminatedString(ISO_8859_1, 80);
int compressedProfileLength = chunkLength - keyword.length() - 2;
if (compressedProfileLength <= 0) {
throw new IIOException("iCCP chunk length is not proper");
@ -458,7 +459,7 @@ public class PNGImageReader extends ImageReader {
private void parse_iTXt_chunk(int chunkLength) throws IOException {
long chunkStart = stream.getStreamPosition();
String keyword = readNullTerminatedString("ISO-8859-1", 80);
String keyword = readNullTerminatedString(ISO_8859_1, 80);
metadata.iTXt_keyword.add(keyword);
int compressionFlag = stream.readUnsignedByte();
@ -469,7 +470,7 @@ public class PNGImageReader extends ImageReader {
long pos = stream.getStreamPosition();
int remainingLen = (int)(chunkStart + chunkLength - pos);
String languageTag = readNullTerminatedString("UTF8", remainingLen);
String languageTag = readNullTerminatedString(UTF_8, remainingLen);
metadata.iTXt_languageTag.add(languageTag);
pos = stream.getStreamPosition();
@ -478,7 +479,7 @@ public class PNGImageReader extends ImageReader {
throw new IIOException("iTXt chunk length is not proper");
}
String translatedKeyword =
readNullTerminatedString("UTF8", remainingLen);
readNullTerminatedString(UTF_8, remainingLen);
metadata.iTXt_translatedKeyword.add(translatedKeyword);
String text;
@ -538,7 +539,7 @@ public class PNGImageReader extends ImageReader {
private void parse_sPLT_chunk(int chunkLength)
throws IOException, IIOException {
metadata.sPLT_paletteName = readNullTerminatedString("ISO-8859-1", 80);
metadata.sPLT_paletteName = readNullTerminatedString(ISO_8859_1, 80);
int remainingChunkLength = chunkLength -
(metadata.sPLT_paletteName.length() + 1);
if (remainingChunkLength <= 0) {
@ -585,7 +586,7 @@ public class PNGImageReader extends ImageReader {
}
private void parse_tEXt_chunk(int chunkLength) throws IOException {
String keyword = readNullTerminatedString("ISO-8859-1", 80);
String keyword = readNullTerminatedString(ISO_8859_1, 80);
int textLength = chunkLength - keyword.length() - 1;
if (textLength < 0) {
throw new IIOException("tEXt chunk length is not proper");
@ -683,7 +684,7 @@ public class PNGImageReader extends ImageReader {
}
private void parse_zTXt_chunk(int chunkLength) throws IOException {
String keyword = readNullTerminatedString("ISO-8859-1", 80);
String keyword = readNullTerminatedString(ISO_8859_1, 80);
int textLength = chunkLength - keyword.length() - 2;
if (textLength < 0) {
throw new IIOException("zTXt chunk length is not proper");

View File

@ -158,7 +158,7 @@ public class FcFontConfiguration extends FontConfiguration {
@Override
protected Charset getDefaultFontCharset(String fontName) {
return Charset.forName("ISO8859_1");
return ISO_8859_1;
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2021, 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
@ -39,6 +39,8 @@ import java.util.HashSet;
import java.util.Properties;
import java.util.Scanner;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
public class MFontConfiguration extends FontConfiguration {
private static FontConfiguration fontConfig = null;
@ -180,7 +182,7 @@ public class MFontConfiguration extends FontConfiguration {
}
protected Charset getDefaultFontCharset(String fontName) {
return Charset.forName("ISO8859_1");
return ISO_8859_1;
}
protected String getFaceNameFromComponentFontName(String componentFontName) {

View File

@ -34,7 +34,8 @@ package sun.security.krb5.internal;
import java.io.IOException;
import java.util.Vector;
import static java.nio.charset.StandardCharsets.*;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
import sun.security.krb5.Asn1Exception;
import sun.security.krb5.internal.util.KerberosString;

View File

@ -36,7 +36,6 @@ import java.security.GeneralSecurityException;
import java.util.Arrays;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.nio.charset.Charset;
import java.nio.CharBuffer;
import java.nio.ByteBuffer;
import sun.security.util.HexDumpEncoder;
@ -44,7 +43,8 @@ import sun.security.krb5.Confounder;
import sun.security.krb5.internal.crypto.KeyUsage;
import sun.security.krb5.KrbCryptoException;
import static java.nio.charset.StandardCharsets.*;
import static java.nio.charset.StandardCharsets.UTF_16LE;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* Implements Derive Key cryptography functionality as defined in RFC 3961.

View File

@ -29,7 +29,8 @@ import java.io.IOException;
import sun.security.action.GetPropertyAction;
import sun.security.util.DerValue;
import static java.nio.charset.StandardCharsets.*;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* Implements the ASN.1 KerberosString type.

View File

@ -41,7 +41,8 @@ import java.security.spec.KeySpec;
import java.security.spec.InvalidKeySpecException;
import java.security.InvalidAlgorithmParameterException;
import static java.nio.charset.StandardCharsets.*;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;

View File

@ -39,7 +39,8 @@ import java.util.logging.Level;
import javax.security.sasl.*;
import javax.security.auth.callback.*;
import static java.nio.charset.StandardCharsets.*;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* An implementation of the DIGEST-MD5 server SASL mechanism.

View File

@ -34,6 +34,8 @@ import java.io.InputStream;
import java.io.IOException;
import java.io.File;
import static java.nio.charset.StandardCharsets.UTF_8;
/*
* Aix implementation of HotSpotVirtualMachine
*/
@ -290,12 +292,7 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine {
*/
private void writeString(int fd, String s) throws IOException {
if (s.length() > 0) {
byte b[];
try {
b = s.getBytes("UTF-8");
} catch (java.io.UnsupportedEncodingException x) {
throw new InternalError(x);
}
byte[] b = s.getBytes(UTF_8);
VirtualMachineImpl.write(fd, b, 0, b.length);
}
byte b[] = new byte[1];

View File

@ -32,11 +32,12 @@ import com.sun.tools.attach.spi.AttachProvider;
import java.io.InputStream;
import java.io.IOException;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.Files;
import static java.nio.charset.StandardCharsets.UTF_8;
/*
* Linux implementation of HotSpotVirtualMachine
*/
@ -315,12 +316,7 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine {
*/
private void writeString(int fd, String s) throws IOException {
if (s.length() > 0) {
byte b[];
try {
b = s.getBytes("UTF-8");
} catch (java.io.UnsupportedEncodingException x) {
throw new InternalError(x);
}
byte[] b = s.getBytes(UTF_8);
VirtualMachineImpl.write(fd, b, 0, b.length);
}
byte b[] = new byte[1];
@ -343,7 +339,7 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine {
Path statusPath = Paths.get(statusFile);
try {
for (String line : Files.readAllLines(statusPath, StandardCharsets.UTF_8)) {
for (String line : Files.readAllLines(statusPath)) {
String[] parts = line.split(":");
if (parts.length == 2 && parts[0].trim().equals("NSpid")) {
parts = parts[1].trim().split("\\s+");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2021, 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,6 +33,8 @@ import java.io.InputStream;
import java.io.IOException;
import java.io.File;
import static java.nio.charset.StandardCharsets.UTF_8;
/*
* Bsd implementation of HotSpotVirtualMachine
*/
@ -274,12 +276,7 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine {
*/
private void writeString(int fd, String s) throws IOException {
if (s.length() > 0) {
byte b[];
try {
b = s.getBytes("UTF-8");
} catch (java.io.UnsupportedEncodingException x) {
throw new InternalError(x);
}
byte[] b = s.getBytes(UTF_8);
VirtualMachineImpl.write(fd, b, 0, b.length);
}
byte b[] = new byte[1];

View File

@ -82,6 +82,7 @@ import com.sun.tools.javac.util.DefinedBy.Api;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.ListBuffer;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static java.nio.file.FileVisitOption.FOLLOW_LINKS;
import static javax.tools.StandardLocation.*;
@ -281,13 +282,8 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
}
private static void printAscii(String format, Object... args) {
String message;
try {
final String ascii = "US-ASCII";
message = new String(String.format(null, format, args).getBytes(ascii), ascii);
} catch (java.io.UnsupportedEncodingException ex) {
throw new AssertionError(ex);
}
String message = new String(
String.format(null, format, args).getBytes(US_ASCII), US_ASCII);
System.out.println(message);
}

View File

@ -28,7 +28,6 @@ package com.sun.tools.javac.platform;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URI;
import java.nio.charset.Charset;
import java.nio.file.DirectoryStream;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
@ -72,6 +71,8 @@ import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Log;
import com.sun.tools.javac.util.StringUtils;
import static java.nio.charset.StandardCharsets.UTF_8;
/** PlatformProvider for JDK N.
*
* <p><b>This is NOT part of any supported API.
@ -262,7 +263,6 @@ public class JDKPlatformProvider implements PlatformProvider {
boolean hasModules =
Feature.MODULES.allowedInSource(Source.lookup(sourceVersion));
Path systemModules = root.resolve(ctSymVersion).resolve("system-modules");
Charset utf8 = Charset.forName("UTF-8");
if (!hasModules) {
List<Path> paths = new ArrayList<>();
@ -288,7 +288,7 @@ public class JDKPlatformProvider implements PlatformProvider {
FileSystems.getFileSystem(URI.create("jrt:/"))
.getPath("modules");
try (Stream<String> lines =
Files.lines(systemModules, utf8)) {
Files.lines(systemModules, UTF_8)) {
lines.map(line -> jrtModules.resolve(line))
.filter(mod -> Files.exists(mod))
.forEach(mod -> setModule(fm, mod));

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2021, 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,6 +33,8 @@ import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* Utility class to determine if a service can be found on the
* path that might be used to create a class loader.
@ -86,7 +88,7 @@ class ServiceProxy {
BufferedReader r = null;
try {
in = u.openStream();
r = new BufferedReader(new InputStreamReader(in, "utf-8"));
r = new BufferedReader(new InputStreamReader(in, UTF_8));
int lc = 1;
String ln;
while ((ln = r.readLine()) != null) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, 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
@ -34,7 +34,6 @@ import java.io.Reader;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
@ -79,7 +78,7 @@ public class SjavacClient implements Sjavac {
String configFile = Util.extractStringOption("conf", serverConf, "");
try {
List<String> configFileLines = Files.readAllLines(Path.of(configFile), StandardCharsets.UTF_8);
List<String> configFileLines = Files.readAllLines(Path.of(configFile));
String configFileContent = String.join("\n", configFileLines);
String portfileName = Util.extractStringOptionLine("portfile", configFileContent, "");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2021, 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
@ -26,6 +26,8 @@ package sun.jvm.hotspot.debugger;
import java.io.*;
import static java.nio.charset.StandardCharsets.US_ASCII;
/** InputLexer is the lexer through which the current set of debuggers
see the debug server. It provides the ability to read all of the
types the debuggers are interested in. All read operations are
@ -152,12 +154,7 @@ public class InputLexer {
for (int i = 0; i < len; i++) {
b[i] = readByte();
}
try {
return new String(b, "US-ASCII");
}
catch (UnsupportedEncodingException e) {
throw new IOException(e.toString());
}
return new String(b, US_ASCII);
}
/** Reads binary data; a Unicode string of the specified length */

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2021, 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
@ -32,7 +32,6 @@ import sun.jvm.hotspot.debugger.RandomAccessFileDataSource;
public class ELFFileParser {
private static ELFFileParser elfParser;
private static final String US_ASCII = "US-ASCII";
public static ELFFileParser getParser() {
if (elfParser == null) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2021, 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
@ -34,6 +34,8 @@ import sun.jvm.hotspot.utilities.Assert;
import sun.jvm.hotspot.debugger.DataSource;
import sun.jvm.hotspot.debugger.MappedByteBufferDataSource;
import static java.nio.charset.StandardCharsets.US_ASCII;
/** Top-level factory which parses COFF files, including object files,
Portable Executables and DLLs. Returns {@link
sun.jvm.hotspot.debugger.win32.coff.COFFFile} objects. This class is a
@ -49,8 +51,6 @@ public class COFFFileParser {
private static final int RELOCATION_SIZE = 10;
private static final int LINE_NUMBER_SIZE = 6;
private static final String US_ASCII = "US-ASCII";
private COFFFileParser() {}
/** This class is a singleton; returns the sole instance. */
@ -1195,11 +1195,7 @@ public class COFFFileParser {
int cbName = readByte() & 0xFF;
byte[] res = new byte[cbName];
readBytes(res);
try {
return new String(res, US_ASCII);
} catch (UnsupportedEncodingException e) {
throw new COFFException(e);
}
return new String(res, US_ASCII);
}
};
}
@ -3336,11 +3332,7 @@ public class COFFFileParser {
throw new COFFException("Error reading length prefixed string in symbol at offset " +
absoluteOffset);
}
try {
return new String(res, US_ASCII);
} catch (UnsupportedEncodingException e) {
throw new COFFException(e);
}
return new String(res, US_ASCII);
}
private int unbiasTypeIndex(int index) {
@ -3385,24 +3377,18 @@ public class COFFFileParser {
} catch (NumberFormatException e) {
throw new COFFException("Error parsing string table index of name of section header " +
"at offset " + offset);
} catch (UnsupportedEncodingException e) {
throw new COFFException(e);
}
// Look up in string table
// FIXME: this index value is assumed to be in the valid range
name = getStringTable().get(index);
} else {
try {
int length = 0;
// find last non-NULL
for (; length < tmpName.length && tmpName[length] != '\0';) {
length++;
}
// don't include NULL chars in returned name String
name = new String(tmpName, 0, length, US_ASCII);
} catch (UnsupportedEncodingException e) {
throw new COFFException(e);
int length = 0;
// find last non-NULL
for (; length < tmpName.length && tmpName[length] != '\0';) {
length++;
}
// don't include NULL chars in returned name String
name = new String(tmpName, 0, length, US_ASCII);
}
virtualSize = readInt();
virtualAddress = readInt();
@ -3636,11 +3622,7 @@ public class COFFFileParser {
if (numRead != 18) {
throw new COFFException("Error reading auxiliary file record at offset " + offset);
}
try {
name = new String(tmpName, US_ASCII);
} catch (UnsupportedEncodingException e) {
throw new COFFException(e);
}
name = new String(tmpName, US_ASCII);
}
public String getName() { return name; }
@ -3751,12 +3733,8 @@ public class COFFFileParser {
while (data[ptr] != 0) {
ptr++;
}
try {
strings[i] = new COFFString(new String(data, lastPtr, ptr - lastPtr, US_ASCII),
offset + ptr + 4);
} catch (UnsupportedEncodingException e) {
throw new COFFException(e);
}
strings[i] = new COFFString(new String(data, lastPtr, ptr - lastPtr, US_ASCII),
offset + ptr + 4);
ptr++;
lastPtr = ptr;
}
@ -3910,11 +3888,7 @@ public class COFFFileParser {
for (int i = 0; i < data.size(); i++) {
bytes[i] = (data.get(i)).byteValue();
}
try {
return new String(bytes, US_ASCII);
} catch (UnsupportedEncodingException e) {
throw new COFFException(e);
}
return new String(bytes, US_ASCII);
}
void seek(long offset) throws COFFException {

View File

@ -37,6 +37,8 @@ import sun.jvm.hotspot.runtime.*;
import sun.jvm.hotspot.classfile.*;
import sun.jvm.hotspot.gc.z.ZCollectedHeap;
import static java.nio.charset.StandardCharsets.UTF_8;
/*
* This class writes Java heap in hprof binary format. This format is
* used by Heap Analysis Tool (HAT). The class is heavily influenced
@ -1128,7 +1130,7 @@ public class HeapHprofBinWriter extends AbstractHeapGraphWriter {
// If name is already written don't write it again.
if (names.add(sym)) {
if(sym != null) {
byte[] buf = sym.asString().getBytes("UTF-8");
byte[] buf = sym.asString().getBytes(UTF_8);
writeHeader(HPROF_UTF8, buf.length + OBJ_ID_SIZE);
writeSymbolID(sym);
out.write(buf);

View File

@ -38,6 +38,8 @@ import java.security.AccessController;
import java.security.PrivilegedAction;
import sun.net.httpserver.HttpConnection.State;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
/**
* Provides implementation for both HTTP and HTTPS
*/
@ -759,7 +761,7 @@ class ServerImpl implements TimeSource {
}
builder.append ("\r\n").append (text);
String s = builder.toString();
byte[] b = s.getBytes("ISO8859_1");
byte[] b = s.getBytes(ISO_8859_1);
rawout.write (b);
rawout.flush();
if (closeNow) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, 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
@ -26,7 +26,6 @@
package jdk.internal.editor.external;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.ClosedWatchServiceException;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult;
@ -41,6 +40,8 @@ import java.util.Scanner;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE;
import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
@ -120,7 +121,7 @@ public class ExternalEditor {
this.watcher = FileSystems.getDefault().newWatchService();
this.dir = Files.createTempDirectory("extedit");
this.tmpfile = Files.createTempFile(dir, null, ".java");
Files.write(tmpfile, initialText.getBytes(Charset.forName("UTF-8")));
Files.write(tmpfile, initialText.getBytes(UTF_8));
dir.register(watcher,
ENTRY_CREATE,
ENTRY_DELETE,

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, 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
@ -31,7 +31,6 @@ import java.util.regex.*;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.Files;
import java.nio.charset.*;
/*
* Linux specific implementation of the PlatformSupport routines
@ -206,7 +205,7 @@ public class PlatformSupportImpl extends PlatformSupport {
}
try {
for (String line : Files.readAllLines(statusPath, StandardCharsets.UTF_8)) {
for (String line : Files.readAllLines(statusPath)) {
String[] parts = line.split(":");
if (parts.length == 2 && parts[0].trim().equals("NSpid")) {
parts = parts[1].trim().split("\\s+");

View File

@ -38,6 +38,8 @@ import java.util.Set;
import jdk.internal.misc.VM;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* Provides utilities needed by JVMCI clients.
*/
@ -286,8 +288,8 @@ public final class Services {
String name = e.getKey();
String value = e.getValue();
if (name.length() > MAX_UTF8_PROPERTY_STRING_LENGTH || value.length() > MAX_UTF8_PROPERTY_STRING_LENGTH) {
byte[] utf8Name = name.getBytes("UTF-8");
byte[] utf8Value = value.getBytes("UTF-8");
byte[] utf8Name = name.getBytes(UTF_8);
byte[] utf8Value = value.getBytes(UTF_8);
out.writeInt(utf8Name.length);
out.write(utf8Name);
out.writeInt(utf8Value.length);
@ -329,8 +331,8 @@ public final class Services {
int valueLen = in.readInt();
byte[] valueBytes = new byte[valueLen];
in.read(valueBytes);
String name = new String(nameBytes, "UTF-8");
String value = new String(valueBytes, "UTF-8");
String name = new String(nameBytes, UTF_8);
String value = new String(valueBytes, UTF_8);
props.put(name, value);
}
index++;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, 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
@ -32,6 +32,8 @@ import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Arrays;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* A helper class which prints the content of input streams to print streams.
*/
@ -47,7 +49,7 @@ public class PrintStreamPrinter {
long result = 0;
try (BufferedInputStream bis = new BufferedInputStream(is);
InputStreamReader isr = new InputStreamReader(bis, "UTF-8")) {
InputStreamReader isr = new InputStreamReader(bis, UTF_8)) {
char c[] = new char[256];
int n;

View File

@ -28,7 +28,6 @@ package sun.tools.jmap;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Collection;
import com.sun.tools.attach.VirtualMachine;
@ -37,6 +36,8 @@ import com.sun.tools.attach.AttachNotSupportedException;
import sun.tools.attach.HotSpotVirtualMachine;
import sun.tools.common.ProcessArgumentMatcher;
import static java.nio.charset.StandardCharsets.UTF_8;
/*
* This class is the main class for the JMap utility. It parses its arguments
* and decides if the command should be satisfied using the VM attach mechanism
@ -123,8 +124,7 @@ public class JMap {
}
private static void executeCommandForPid(String pid, String command, Object ... args)
throws AttachNotSupportedException, IOException,
UnsupportedEncodingException {
throws AttachNotSupportedException, IOException {
VirtualMachine vm = VirtualMachine.attach(pid);
// Cast to HotSpotVirtualMachine as this is an
@ -137,7 +137,7 @@ public class JMap {
do {
n = in.read(b);
if (n > 0) {
String s = new String(b, 0, n, "UTF-8");
String s = new String(b, 0, n, UTF_8);
System.out.print(s);
}
} while (n > 0);
@ -165,8 +165,7 @@ public class JMap {
}
private static void histo(String pid, String options)
throws AttachNotSupportedException, IOException,
UnsupportedEncodingException {
throws AttachNotSupportedException, IOException {
String liveopt = "-all";
String filename = null;
String parallel = null;
@ -203,8 +202,7 @@ public class JMap {
}
private static void dump(String pid, String options)
throws AttachNotSupportedException, IOException,
UnsupportedEncodingException {
throws AttachNotSupportedException, IOException {
String subopts[] = options.split(",");
String filename = null;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, 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
@ -28,7 +28,8 @@ package com.sun.tools.classfile;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* See JVMS, section 4.8.15.
@ -39,7 +40,6 @@ import java.nio.charset.Charset;
* deletion without notice.</b>
*/
public class SourceDebugExtension_attribute extends Attribute {
private static final Charset UTF8 = Charset.forName("UTF-8");
SourceDebugExtension_attribute(ClassReader cr, int name_index, int length) throws IOException {
super(name_index, length);
@ -58,7 +58,7 @@ public class SourceDebugExtension_attribute extends Attribute {
}
public String getValue() {
return new String(debug_extension, UTF8);
return new String(debug_extension, UTF_8);
}
public <R, D> R accept(Visitor<R, D> visitor, D data) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021, 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
@ -47,6 +47,8 @@ import com.sun.jdi.PrimitiveValue;
import com.sun.jdi.ShortValue;
import com.sun.jdi.Value;
import static java.nio.charset.StandardCharsets.UTF_8;
class PacketStream {
final VirtualMachineImpl vm;
private int inCursor = 0;
@ -189,13 +191,9 @@ class PacketStream {
}
void writeString(String string) {
try {
byte[] stringBytes = string.getBytes("UTF8");
writeInt(stringBytes.length);
writeByteArray(stringBytes);
} catch (java.io.UnsupportedEncodingException e) {
throw new InternalException("Cannot convert string to UTF8 bytes");
}
byte[] stringBytes = string.getBytes(UTF_8);
writeInt(stringBytes.length);
writeByteArray(stringBytes);
}
void writeLocation(Location location) {
@ -405,15 +403,8 @@ class PacketStream {
* characters of the string.
*/
String readString() {
String ret;
int len = readInt();
try {
ret = new String(pkt.data, inCursor, len, "UTF8");
} catch(java.io.UnsupportedEncodingException e) {
System.err.println(e);
ret = "Conversion error!";
}
String ret = new String(pkt.data, inCursor, len, UTF_8);
inCursor += len;
return ret;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021, 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
@ -39,6 +39,8 @@ import com.sun.jdi.connect.TransportTimeoutException;
import com.sun.jdi.connect.spi.Connection;
import com.sun.jdi.connect.spi.TransportService;
import static java.nio.charset.StandardCharsets.UTF_8;
/*
* A transport service based on a TCP connection between the
* debugger and debugee.
@ -120,7 +122,7 @@ public class SocketTransportService extends TransportService {
void handshake(Socket s, long timeout) throws IOException {
s.setSoTimeout((int)timeout);
byte[] hello = "JDWP-Handshake".getBytes("UTF-8");
byte[] hello = "JDWP-Handshake".getBytes(UTF_8);
s.getOutputStream().write(hello);
byte[] b = new byte[hello.length];

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, 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
@ -31,6 +31,8 @@ import com.sun.jdi.connect.spi.*;
import java.io.IOException;
import static java.nio.charset.StandardCharsets.UTF_8;
class SharedMemoryConnection extends Connection {
private long id;
private Object receiveLock = new Object();
@ -46,7 +48,7 @@ class SharedMemoryConnection extends Connection {
// handshake with the target VM
void handshake(long handshakeTimeout) throws IOException {
byte[] hello = "JDWP-Handshake".getBytes("UTF-8");
byte[] hello = "JDWP-Handshake".getBytes(UTF_8);
for (int i=0; i<hello.length; i++) {
sendByte0(id, hello[i]);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, 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
@ -28,6 +28,9 @@ package jdk.jfr.internal.consumer;
import java.io.IOException;
import java.nio.charset.Charset;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
public final class StringParser extends Parser {
public enum Encoding {
@ -53,8 +56,6 @@ public final class StringParser extends Parser {
}
}
private static final Charset UTF8 = Charset.forName("UTF-8");
private static final Charset LATIN1 = Charset.forName("ISO-8859-1");
private static final class CharsetParser extends Parser {
private final Charset charset;
@ -154,8 +155,8 @@ public final class StringParser extends Parser {
private final ConstantLookup stringLookup;
private final CharArrayParser charArrayParser = new CharArrayParser();
private final CharsetParser utf8parser = new CharsetParser(UTF8);
private final CharsetParser latin1parser = new CharsetParser(LATIN1);
private final CharsetParser utf8parser = new CharsetParser(UTF_8);
private final CharsetParser latin1parser = new CharsetParser(ISO_8859_1);
private final boolean event;
public StringParser(ConstantLookup stringLookup, boolean event) {

View File

@ -26,7 +26,6 @@ package jdk.jfr.internal.jfc.model;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
@ -36,6 +35,8 @@ import java.util.Map;
import jdk.jfr.internal.SecuritySupport.SafePath;
import static java.nio.charset.StandardCharsets.UTF_8;
// Holds the structure of a .jfc file similar to an XML DOM.
public final class JFCModel {
private final Map<String, List<ControlElement>> controls = new LinkedHashMap<>();
@ -131,7 +132,7 @@ public final class JFCModel {
}
public void saveToFile(SafePath path) throws IOException {
try (PrintWriter p = new PrintWriter(path.toFile(), Charset.forName("UTF-8"))) {
try (PrintWriter p = new PrintWriter(path.toFile(), UTF_8)) {
PrettyPrinter pp = new PrettyPrinter(p);
pp.print(configuration);
if (p.checkError()) {

View File

@ -26,7 +26,6 @@ package jdk.jfr.internal.jfc.model;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.text.ParseException;
import java.util.ArrayDeque;
@ -39,10 +38,12 @@ import jdk.internal.org.xml.sax.helpers.DefaultHandler;
import jdk.internal.util.xml.SAXParser;
import jdk.internal.util.xml.impl.SAXParserImpl;
import static java.nio.charset.StandardCharsets.UTF_8;
final class Parser {
static XmlConfiguration parse(Path path) throws ParseException, IOException {
try (FileReader r = new FileReader(path.toFile(), Charset.forName("UTF-8"))) {
try (FileReader r = new FileReader(path.toFile(), UTF_8)) {
SAXParser saxParser = new SAXParserImpl();
ConfigurationHandler handler = new ConfigurationHandler();
saxParser.parse(new InputSource(r), handler);

View File

@ -28,7 +28,6 @@ package jdk.jfr.internal.tool;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
@ -47,6 +46,8 @@ import jdk.jfr.internal.Type;
import jdk.jfr.internal.TypeLibrary;
import jdk.jfr.internal.consumer.JdkJfrConsumer;
import static java.nio.charset.StandardCharsets.UTF_8;
final class Metadata extends Command {
private static final JdkJfrConsumer PRIVATE_ACCESS = JdkJfrConsumer.instance();
@ -197,7 +198,7 @@ final class Metadata extends Command {
optionCount = options.size();
}
try (PrintWriter pw = new PrintWriter(System.out, false, Charset.forName("UTF-8"))) {
try (PrintWriter pw = new PrintWriter(System.out, false, UTF_8)) {
PrettyWriter prettyWriter = new PrettyWriter(pw);
prettyWriter.setShowIds(showIds);
if (filter != null) {

View File

@ -28,7 +28,6 @@ package jdk.jfr.internal.tool;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Deque;
@ -37,6 +36,8 @@ import java.util.function.Predicate;
import jdk.jfr.EventType;
import static java.nio.charset.StandardCharsets.UTF_8;
final class Print extends Command {
@Override
public String getName() {
@ -100,7 +101,7 @@ final class Print extends Command {
@Override
public void execute(Deque<String> options) throws UserSyntaxException, UserDataException {
Path file = getJFRInputFile(options);
PrintWriter pw = new PrintWriter(System.out, false, Charset.forName("UTF-8"));
PrintWriter pw = new PrintWriter(System.out, false, UTF_8);
Predicate<EventType> eventFilter = null;
int stackDepth = 5;
EventPrintWriter eventWriter = null;

View File

@ -35,7 +35,6 @@ import java.io.InterruptedIOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.URI;
import java.nio.charset.Charset;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
@ -90,6 +89,8 @@ import jdk.jshell.Snippet.SubKind;
import jdk.jshell.SourceCodeAnalysis.CompletionInfo;
import jdk.jshell.VarSnippet;
import static java.nio.charset.StandardCharsets.UTF_8;
class ConsoleIOContext extends IOContext {
private static final String HISTORY_LINE_PREFIX = "HISTORY_LINE_";
@ -1309,7 +1310,7 @@ class ConsoleIOContext extends IOContext {
protected ProgrammaticInTerminal(InputStream input, OutputStream output,
String terminal, Size size, Size bufferSize) throws Exception {
super("non-system-in", terminal, output, Charset.forName("UTF-8"));
super("non-system-in", terminal, output, UTF_8);
this.inputReader = NonBlocking.nonBlocking(getName(), input, encoding());
Attributes a = new Attributes(getAttributes());
a.setLocalFlag(LocalFlag.ECHO, false);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021, 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
@ -30,6 +30,8 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* Read from an InputStream which has been packetized and write its contents
* to the named OutputStreams.
@ -64,7 +66,7 @@ class DemultiplexInput extends Thread {
int dataLen = delegate.read();
byte[] data = new byte[dataLen];
DemultiplexInput.this.delegate.readFully(data);
String chan = new String(name, "UTF-8");
String chan = new String(name, UTF_8);
OutputStream out = io.get(chan);
if (out == null) {
debug("Unexpected channel name: %s", chan);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021, 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
@ -26,7 +26,8 @@ package jdk.jshell.execution;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* Packetize an OutputStream, dividing it into named channels.
@ -40,12 +41,8 @@ class MultiplexingOutputStream extends OutputStream {
private final OutputStream delegate;
MultiplexingOutputStream(String name, OutputStream delegate) {
try {
this.name = name.getBytes("UTF-8");
this.delegate = delegate;
} catch (UnsupportedEncodingException ex) {
throw new IllegalStateException(ex); //should not happen
}
this.name = name.getBytes(UTF_8);
this.delegate = delegate;
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021, 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
@ -45,6 +45,7 @@ import com.sun.jdi.VirtualMachine;
import jdk.jshell.spi.ExecutionControl;
import jdk.jshell.spi.ExecutionControl.ExecutionControlException;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* Miscellaneous utility methods for setting-up implementations of
@ -120,7 +121,7 @@ public class Util {
for (int i = 0; i < len; i++) {
message[i] = (byte) super.read();
}
throw new IOException(new String(message, "UTF-8"));
throw new IOException(new String(message, UTF_8));
case -1:
return -1;
default:
@ -183,7 +184,7 @@ public class Util {
debug(ex, "$" + e.getKey() + "-input-requested.write");
}
} catch (IOException exc) {
byte[] message = exc.getMessage().getBytes("UTF-8");
byte[] message = exc.getMessage().getBytes(UTF_8);
inTarget.write(TAG_EXCEPTION);
inTarget.write((message.length >> 0) & 0xFF);
inTarget.write((message.length >> 8) & 0xFF);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, 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
@ -28,11 +28,12 @@ import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* JdpPacketReader responsible for reading a packet <p>This class gets a byte
* array as it came from a Net, validates it and breaks a part </p>
@ -90,12 +91,10 @@ public final class JdpPacketReader {
if (pkt.read(b) != len) {
throw new JdpException("Broken JDP packet. Unable to read entry.");
}
return new String(b, "UTF-8");
return new String(b, UTF_8);
} catch (EOFException e) {
throw e;
} catch (UnsupportedEncodingException ex) {
throw new JdpException("Broken JDP packet. Unable to decode entry.");
} catch (IOException e) {
throw new JdpException("Broken JDP packet. Unable to read entry.");
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2021, 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
@ -53,6 +53,8 @@
package com.sun.security.auth.module;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
class Crypt {
/* EXPORT DELETE START */
@ -385,14 +387,10 @@ class Crypt {
}
Crypt c = new Crypt();
try {
byte[] result = c.crypt
(arg[0].getBytes("ISO-8859-1"), arg[1].getBytes("ISO-8859-1"));
for (int i=0; i<result.length; i++) {
System.out.println(" "+i+" "+(char)result[i]);
}
} catch (java.io.UnsupportedEncodingException uee) {
// cannot happen
byte[] result = c.crypt
(arg[0].getBytes(ISO_8859_1), arg[1].getBytes(ISO_8859_1));
for (int i=0; i<result.length; i++) {
System.out.println(" "+i+" "+(char)result[i]);
}
}
}

View File

@ -38,6 +38,8 @@ import java.util.LinkedList;
import com.sun.security.auth.UnixPrincipal;
import com.sun.security.auth.UnixNumericUserPrincipal;
import com.sun.security.auth.UnixNumericGroupPrincipal;
import static java.nio.charset.StandardCharsets.UTF_8;
import static sun.security.util.ResourcesMgr.getAuthResourceString;
@ -550,7 +552,7 @@ public class JndiLoginModule implements LoginModule {
// channels. For nonsecure channels, SSL is recommended.
Attribute pwd = attributes.get(USER_PWD);
String encryptedPwd = new String((byte[])pwd.get(), "UTF8");
String encryptedPwd = new String((byte[])pwd.get(), UTF_8);
encryptedPassword = encryptedPwd.substring(CRYPT.length());
// check the password
@ -640,15 +642,6 @@ public class JndiLoginModule implements LoginModule {
ne.printStackTrace();
}
throw new FailedLoginException("User not found");
} catch (java.io.UnsupportedEncodingException uee) {
// password stored in incorrect format
if (debug) {
System.out.println("\t\t[JndiLoginModule]: " +
"password incorrectly encoded");
uee.printStackTrace();
}
throw new LoginException("Login failure due to incorrect " +
"password encoding in the password database");
}
// authentication succeeded
@ -729,19 +722,14 @@ public class JndiLoginModule implements LoginModule {
return false;
Crypt c = new Crypt();
try {
byte[] oldCrypt = encryptedPassword.getBytes("UTF8");
byte[] newCrypt = c.crypt(password.getBytes("UTF8"),
oldCrypt);
if (newCrypt.length != oldCrypt.length)
return false;
for (int i = 0; i < newCrypt.length; i++) {
if (oldCrypt[i] != newCrypt[i])
return false;
}
} catch (java.io.UnsupportedEncodingException uee) {
// cannot happen, but return false just to be safe
byte[] oldCrypt = encryptedPassword.getBytes(UTF_8);
byte[] newCrypt = c.crypt(password.getBytes(UTF_8),
oldCrypt);
if (newCrypt.length != oldCrypt.length)
return false;
for (int i = 0; i < newCrypt.length; i++) {
if (oldCrypt[i] != newCrypt[i])
return false;
}
return true;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021, 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
@ -31,7 +31,6 @@ import java.io.EOFException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
import java.nio.charset.Charset;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -39,6 +38,8 @@ import javax.swing.SwingUtilities;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import static java.nio.charset.StandardCharsets.UTF_8;
public class BinaryParser implements GraphParser {
private static final int BEGIN_GROUP = 0x00;
private static final int BEGIN_GRAPH = 0x01;
@ -69,8 +70,6 @@ public class BinaryParser implements GraphParser {
private static final String NO_BLOCK = "noBlock";
private static final Charset utf8 = Charset.forName("UTF-8");
private final GroupCallback callback;
private final List<Object> constantPool;
private final ByteBuffer buffer;
@ -341,7 +340,7 @@ public class BinaryParser implements GraphParser {
}
private String readString() throws IOException {
return new String(readBytes(), utf8).intern();
return new String(readBytes(), UTF_8).intern();
}
private byte[] readBytes() throws IOException {

View File

@ -28,6 +28,8 @@ package com.sun.hotspot.igv.data.serialization;
import com.sun.hotspot.igv.data.*;
import java.io.*;
import java.nio.channels.Channels;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.*;
@ -67,18 +69,14 @@ public class ParserTest {
}
private void test(GraphDocument document, String xmlString) {
InputStream in = new ByteArrayInputStream(xmlString.getBytes(UTF_8));
try {
InputStream in = new ByteArrayInputStream(xmlString.getBytes("UTF-8"));
try {
Parser parser = new Parser(Channels.newChannel(in));
parser.setInvokeLater(false);
final GraphDocument parsedDocument = parser.parse();
Util.assertGraphDocumentEquals(document, parsedDocument);
} catch (IOException ex) {
fail(ex.toString());
}
} catch (UnsupportedEncodingException ex) {
Exceptions.printStackTrace(ex);
Parser parser = new Parser(Channels.newChannel(in));
parser.setInvokeLater(false);
final GraphDocument parsedDocument = parser.parse();
Util.assertGraphDocumentEquals(document, parsedDocument);
} catch (IOException ex) {
fail(ex.toString());
}
}

View File

@ -70,6 +70,8 @@ import org.openide.windows.Mode;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
*
* @author Thomas Wuerthinger
@ -111,13 +113,11 @@ public final class EditorTopComponent extends TopComponent implements PropertyCh
FileOutputStream os = null;
try {
os = new FileOutputStream(f);
Writer out = new OutputStreamWriter(os, "UTF-8");
Writer out = new OutputStreamWriter(os, UTF_8);
BatikSVG.printToStream(svgGenerator, out, true);
} catch (FileNotFoundException e) {
NotifyDescriptor message = new NotifyDescriptor.Message("For export to SVG files the Batik SVG Toolkit must be intalled.", NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notifyLater(message);
} catch (UnsupportedEncodingException e) {
} finally {
if (os != null) {
try {