mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +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
|
@ -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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -24,6 +24,10 @@
|
|||
*/
|
||||
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.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
|
@ -32,7 +36,6 @@ import java.nio.channels.Channels;
|
|||
import java.nio.channels.FileChannel;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.Spliterator;
|
||||
|
@ -66,9 +69,9 @@ final class FileChannelLinesSpliterator implements Spliterator<String> {
|
|||
static final Set<String> SUPPORTED_CHARSET_NAMES;
|
||||
static {
|
||||
SUPPORTED_CHARSET_NAMES = new HashSet<>();
|
||||
SUPPORTED_CHARSET_NAMES.add(StandardCharsets.UTF_8.name());
|
||||
SUPPORTED_CHARSET_NAMES.add(StandardCharsets.ISO_8859_1.name());
|
||||
SUPPORTED_CHARSET_NAMES.add(StandardCharsets.US_ASCII.name());
|
||||
SUPPORTED_CHARSET_NAMES.add(UTF_8.INSTANCE.name());
|
||||
SUPPORTED_CHARSET_NAMES.add(ISO_8859_1.INSTANCE.name());
|
||||
SUPPORTED_CHARSET_NAMES.add(US_ASCII.INSTANCE.name());
|
||||
}
|
||||
|
||||
private final FileChannel fc;
|
||||
|
|
|
@ -79,6 +79,7 @@ import java.util.stream.StreamSupport;
|
|||
|
||||
import jdk.internal.util.ArraysSupport;
|
||||
import sun.nio.ch.FileChannelImpl;
|
||||
import sun.nio.cs.UTF_8;
|
||||
import sun.nio.fs.AbstractFileSystemProvider;
|
||||
|
||||
/**
|
||||
|
@ -2944,7 +2945,7 @@ public final class Files {
|
|||
* @since 1.8
|
||||
*/
|
||||
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)
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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)
|
||||
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)
|
||||
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
|
||||
*/
|
||||
public static Stream<String> lines(Path path) throws IOException {
|
||||
return lines(path, StandardCharsets.UTF_8);
|
||||
return lines(path, UTF_8.INSTANCE);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue