From ff1b535411fdf0f00002d27f297dce4425eb19cd Mon Sep 17 00:00:00 2001 From: guicamest Date: Wed, 8 Nov 2023 14:23:00 +0100 Subject: [PATCH] rewrite(S3FileSystemProvider): instantiate S3FileAttributes once. Remove `asMap()` with no filter --- .../nio/spi/s3/S3BasicFileAttributes.java | 8 -------- .../nio/spi/s3/S3FileSystemProvider.java | 19 +++++++++++-------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/main/java/software/amazon/nio/spi/s3/S3BasicFileAttributes.java b/src/main/java/software/amazon/nio/spi/s3/S3BasicFileAttributes.java index c54025a5..b0616e49 100644 --- a/src/main/java/software/amazon/nio/spi/s3/S3BasicFileAttributes.java +++ b/src/main/java/software/amazon/nio/spi/s3/S3BasicFileAttributes.java @@ -191,14 +191,6 @@ private HeadObjectResponse getObjectMetadata(String forOperation) { } } - /** - * Construct a Map representation of this object - * @return a map - */ - protected Map asMap(){ - return asMap(x -> true); - } - /** * Construct a Map representation of this object with properties filtered * @param attributeFilter a filter to include properties in the resulting Map diff --git a/src/main/java/software/amazon/nio/spi/s3/S3FileSystemProvider.java b/src/main/java/software/amazon/nio/spi/s3/S3FileSystemProvider.java index 0ef9ee53..40d64ef6 100644 --- a/src/main/java/software/amazon/nio/spi/s3/S3FileSystemProvider.java +++ b/src/main/java/software/amazon/nio/spi/s3/S3FileSystemProvider.java @@ -52,6 +52,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import java.util.function.Predicate; import java.util.stream.Collectors; import static java.nio.file.LinkOption.NOFOLLOW_LINKS; @@ -680,14 +681,16 @@ public Map readAttributes(Path path, String attributes, LinkOpti if (s3Path.isDirectory() || attributes.trim().isEmpty()) return Collections.emptyMap(); - if (attributes.equals("*") || attributes.equals("s3")) - return new S3BasicFileAttributes(s3Path, Duration.ofMinutes(TimeOutUtils.TIMEOUT_TIME_LENGTH_1)).asMap(); - - final var attrSet = Arrays.stream(attributes.split(",")) - .map(attr -> attr.replaceAll("^s3:", "")) - .collect(Collectors.toSet()); - return ((S3BasicFileAttributes)readAttributes(path, BasicFileAttributes.class, options)) - .asMap(attrSet::contains); + Predicate attributesFilter; + if (attributes.equals("*") || attributes.equals("s3")) { + attributesFilter = x -> true; + } else { + final var attrSet = Arrays.stream(attributes.split(",")) + .map(attr -> attr.replaceAll("^s3:", "")) + .collect(Collectors.toSet()); + attributesFilter = attrSet::contains; + } + return new S3BasicFileAttributes(s3Path, Duration.ofMinutes(TimeOutUtils.TIMEOUT_TIME_LENGTH_1)).asMap(attributesFilter); } /**