Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8272805: Avoid looking up standard charsets #5210

Closed
Closed
Changes from 4 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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 @@

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 @@ private static void readLSRfile(String filename) throws Exception {
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:")) {
@@ -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.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 @@ private 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 @@ private static boolean isEncodingSupported(String encoding) {
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);

@@ -339,7 +339,7 @@ private int getNamespacePid(int pid) throws AttachNotSupportedException, IOExcep
Path statusPath = Paths.get(statusFile);

try {
for (String line : Files.readAllLines(statusPath, 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+");
@@ -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.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 SjavacClient(Options options) {
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, "");
@@ -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 @@

public class ELFFileParser {
private static ELFFileParser elfParser;
private static final String US_ASCII = "US-ASCII";

public static ELFFileParser getParser() {
if (elfParser == null) {
@@ -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.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 int getNamespaceVmId(int pid) {
}

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+");