From c917ff2d3faa7434cdc162983dd085cb7ec555bc Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Mon, 8 Aug 2022 21:14:03 +0900 Subject: [PATCH] Require Java 11 Jetty 11 requires this. Also address some Modernizer issues. References #422. --- pom.xml | 2 +- .../java/org/gaul/s3proxy/NullBlobStore.java | 5 +++-- .../java/org/gaul/s3proxy/S3ProxyHandler.java | 10 ++++++---- src/test/java/org/gaul/s3proxy/AwsSdkTest.java | 6 +++--- .../org/gaul/s3proxy/NullBlobStoreTest.java | 18 +++++++++--------- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/pom.xml b/pom.xml index 455a5288..8c90f020 100644 --- a/pom.xml +++ b/pom.xml @@ -381,7 +381,7 @@ UTF-8 - 1.8 + 11 2.5.0 1.7.36 ${project.groupId}.shaded diff --git a/src/main/java/org/gaul/s3proxy/NullBlobStore.java b/src/main/java/org/gaul/s3proxy/NullBlobStore.java index 860bada0..14f23fd3 100644 --- a/src/main/java/org/gaul/s3proxy/NullBlobStore.java +++ b/src/main/java/org/gaul/s3proxy/NullBlobStore.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.util.Arrays; import java.util.List; @@ -119,7 +120,7 @@ public String putBlob(String containerName, Blob blob, PutOptions options) { long length; try (InputStream is = blob.getPayload().openStream()) { - length = ByteStreams.copy(is, ByteStreams.nullOutputStream()); + length = is.transferTo(OutputStream.nullOutputStream()); } catch (IOException ioe) { throw new RuntimeException(ioe); } @@ -175,7 +176,7 @@ public MultipartPart uploadMultipartPart(MultipartUpload mpu, int partNumber, Payload payload) { long length; try (InputStream is = payload.openStream()) { - length = ByteStreams.copy(is, ByteStreams.nullOutputStream()); + length = is.transferTo(OutputStream.nullOutputStream()); } catch (IOException ioe) { throw new RuntimeException(ioe); } diff --git a/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java b/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java index 064886b6..6636cd8a 100644 --- a/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java +++ b/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java @@ -471,7 +471,7 @@ public final void doHandle(HttpServletRequest baseRequest, String[] path = uri.split("/", 3); for (int i = 0; i < path.length; i++) { - path[i] = URLDecoder.decode(path[i], UTF_8); + path[i] = URLDecoder.decode(path[i], StandardCharsets.UTF_8); } Map.Entry provider = @@ -1762,7 +1762,7 @@ private void handleGetBlob(HttpServletRequest request, try (InputStream is = blob.getPayload().openStream(); OutputStream os = response.getOutputStream()) { - ByteStreams.copy(is, os); + is.transferTo(os); os.flush(); } } @@ -1772,7 +1772,8 @@ private void handleCopyBlob(HttpServletRequest request, String destContainerName, String destBlobName) throws IOException, S3Exception { String copySourceHeader = request.getHeader(AwsHttpHeaders.COPY_SOURCE); - copySourceHeader = URLDecoder.decode(copySourceHeader, UTF_8); + copySourceHeader = URLDecoder.decode( + copySourceHeader, StandardCharsets.UTF_8); if (copySourceHeader.startsWith("/")) { // Some clients like boto do not include the leading slash copySourceHeader = copySourceHeader.substring(1); @@ -2520,7 +2521,8 @@ private void handleCopyPart(HttpServletRequest request, throws IOException, S3Exception { // TODO: duplicated from handlePutBlob String copySourceHeader = request.getHeader(AwsHttpHeaders.COPY_SOURCE); - copySourceHeader = URLDecoder.decode(copySourceHeader, UTF_8); + copySourceHeader = URLDecoder.decode( + copySourceHeader, StandardCharsets.UTF_8); if (copySourceHeader.startsWith("/")) { // Some clients like boto do not include the leading slash copySourceHeader = copySourceHeader.substring(1); diff --git a/src/test/java/org/gaul/s3proxy/AwsSdkTest.java b/src/test/java/org/gaul/s3proxy/AwsSdkTest.java index c5e9b80b..3ecf7532 100644 --- a/src/test/java/org/gaul/s3proxy/AwsSdkTest.java +++ b/src/test/java/org/gaul/s3proxy/AwsSdkTest.java @@ -20,6 +20,7 @@ import static org.junit.Assume.assumeTrue; import java.io.InputStream; +import java.io.OutputStream; import java.net.URI; import java.net.URL; import java.net.URLConnection; @@ -93,7 +94,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import com.google.common.io.ByteSource; -import com.google.common.io.ByteStreams; import org.assertj.core.api.Fail; @@ -653,7 +653,7 @@ public void testOverrideResponseHeader() throws Exception { S3Object object = client.getObject(getObjectRequest); try (InputStream is = object.getObjectContent()) { assertThat(is).isNotNull(); - ByteStreams.copy(is, ByteStreams.nullOutputStream()); + is.transferTo(OutputStream.nullOutputStream()); } ObjectMetadata reponseMetadata = object.getObjectMetadata(); @@ -1446,7 +1446,7 @@ public void testConditionalGet() throws Exception { .withMatchingETagConstraint(result.getETag())); try (InputStream is = object.getObjectContent()) { assertThat(is).isNotNull(); - ByteStreams.copy(is, ByteStreams.nullOutputStream()); + is.transferTo(OutputStream.nullOutputStream()); } object = client.getObject( diff --git a/src/test/java/org/gaul/s3proxy/NullBlobStoreTest.java b/src/test/java/org/gaul/s3proxy/NullBlobStoreTest.java index d8e223a3..21687626 100644 --- a/src/test/java/org/gaul/s3proxy/NullBlobStoreTest.java +++ b/src/test/java/org/gaul/s3proxy/NullBlobStoreTest.java @@ -20,13 +20,13 @@ import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.util.List; import java.util.Random; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.io.ByteSource; -import com.google.common.io.ByteStreams; import com.google.common.net.MediaType; import com.google.inject.Module; @@ -91,10 +91,10 @@ public void testCreateBlobGetBlob() throws Exception { // content differs, only compare length try (InputStream actual = blob.getPayload().openStream(); InputStream expected = BYTE_SOURCE.openStream()) { - long actualLength = ByteStreams.copy(actual, - ByteStreams.nullOutputStream()); - long expectedLength = ByteStreams.copy(expected, - ByteStreams.nullOutputStream()); + long actualLength = actual.transferTo( + OutputStream.nullOutputStream()); + long expectedLength = expected.transferTo( + OutputStream.nullOutputStream()); assertThat(actualLength).isEqualTo(expectedLength); } @@ -157,10 +157,10 @@ public void testCreateMultipartBlobGetBlob() throws Exception { // content differs, only compare length try (InputStream actual = newBlob.getPayload().openStream(); InputStream expected = byteSource.openStream()) { - long actualLength = ByteStreams.copy(actual, - ByteStreams.nullOutputStream()); - long expectedLength = ByteStreams.copy(expected, - ByteStreams.nullOutputStream()); + long actualLength = actual.transferTo( + OutputStream.nullOutputStream()); + long expectedLength = expected.transferTo( + OutputStream.nullOutputStream()); assertThat(actualLength).isEqualTo(expectedLength); }