8302979: (fs) Files usage of SUPPORTED_CHARSETS could be simplified

Reviewed-by: alanb, jwaters
This commit is contained in:
Sergey Tsypanov 2023-02-22 14:08:51 +00:00 committed by Julian Waters
parent 0d5f7439a4
commit 25bfed3b12
2 changed files with 8 additions and 11 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2023, 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
@ -36,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.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.Spliterator; import java.util.Spliterator;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -70,13 +69,11 @@ import jdk.internal.access.JavaNioAccess;
*/ */
final class FileChannelLinesSpliterator implements Spliterator<String> { final class FileChannelLinesSpliterator implements Spliterator<String> {
static final Set<String> SUPPORTED_CHARSET_NAMES; static final Set<Charset> SUPPORTED_CHARSETS = Set.of(
static { UTF_8.INSTANCE,
SUPPORTED_CHARSET_NAMES = new HashSet<>(); ISO_8859_1.INSTANCE,
SUPPORTED_CHARSET_NAMES.add(UTF_8.INSTANCE.name()); US_ASCII.INSTANCE
SUPPORTED_CHARSET_NAMES.add(ISO_8859_1.INSTANCE.name()); );
SUPPORTED_CHARSET_NAMES.add(US_ASCII.INSTANCE.name());
}
private final FileChannel fc; private final FileChannel fc;
private final Charset cs; private final Charset cs;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2023, 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
@ -4103,7 +4103,7 @@ public final class Files {
// 3) the file size is such that all bytes can be indexed by int values // 3) the file size is such that all bytes can be indexed by int values
// (this limitation is imposed by ByteBuffer) // (this limitation is imposed by ByteBuffer)
if (path.getFileSystem() == FileSystems.getDefault() && if (path.getFileSystem() == FileSystems.getDefault() &&
FileChannelLinesSpliterator.SUPPORTED_CHARSET_NAMES.contains(cs.name())) { FileChannelLinesSpliterator.SUPPORTED_CHARSETS.contains(cs)) {
FileChannel fc = FileChannel.open(path, StandardOpenOption.READ); FileChannel fc = FileChannel.open(path, StandardOpenOption.READ);
Stream<String> fcls = createFileChannelLinesStream(fc, cs); Stream<String> fcls = createFileChannelLinesStream(fc, cs);