From 74916100ff6956c3ea590be5dbbb3fafed2a66ac Mon Sep 17 00:00:00 2001 From: Paolo Di Tommaso Date: Mon, 20 Dec 2021 18:42:19 +0100 Subject: [PATCH] Fix cross compilation error --- .../com/upplication/s3fs/S3OutputStream.java | 14 ++++++++++---- .../com/upplication/s3fs/ng/ChunkBuffer.java | 17 ++++++----------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/plugins/nf-amazon/src/main/com/upplication/s3fs/S3OutputStream.java b/plugins/nf-amazon/src/main/com/upplication/s3fs/S3OutputStream.java index 8c04015912..4db9181e70 100644 --- a/plugins/nf-amazon/src/main/com/upplication/s3fs/S3OutputStream.java +++ b/plugins/nf-amazon/src/main/com/upplication/s3fs/S3OutputStream.java @@ -211,7 +211,9 @@ private ByteBuffer expandBuffer(ByteBuffer byteBuffer) { final float expandFactor = 2.5f; final int newCapacity = Math.min( (int)(byteBuffer.capacity() * expandFactor), chunkSize ); - byteBuffer.flip(); + // cast to prevent Java 8 / Java 11 cross compile-runtime error + // https://www.morling.dev/blog/bytebuffer-and-the-dreaded-nosuchmethoderror/ + ((java.nio.Buffer)byteBuffer).flip(); ByteBuffer expanded = ByteBuffer.allocate(newCapacity); expanded.order(byteBuffer.order()); expanded.put(byteBuffer); @@ -434,8 +436,10 @@ private InitiateMultipartUploadResult initiateMultipartUpload() throws IOExcepti * @throws IOException */ private void uploadPart( final ByteBuffer buf, final byte[] checksum, final int partNumber, final boolean lastPart ) throws IOException { - buf.flip(); - buf.mark(); + // cast to prevent Java 8 / Java 11 cross compile-runtime error + // https://www.morling.dev/blog/bytebuffer-and-the-dreaded-nosuchmethoderror/ + ((java.nio.Buffer)buf).flip(); + ((java.nio.Buffer)buf).mark(); int attempt=0; boolean success=false; @@ -545,7 +549,9 @@ private void completeMultipartUpload() throws IOException { * @throws IOException */ private void putObject(ByteBuffer buf, byte[] checksum) throws IOException { - buf.flip(); + // cast to prevent Java 8 / Java 11 cross compile-runtime error + // https://www.morling.dev/blog/bytebuffer-and-the-dreaded-nosuchmethoderror/ + ((java.nio.Buffer)buf).flip(); putObject(new ByteBufferInputStream(buf), buf.limit(), checksum); } diff --git a/plugins/nf-amazon/src/main/com/upplication/s3fs/ng/ChunkBuffer.java b/plugins/nf-amazon/src/main/com/upplication/s3fs/ng/ChunkBuffer.java index 45f2fe6966..6f2bd46ada 100644 --- a/plugins/nf-amazon/src/main/com/upplication/s3fs/ng/ChunkBuffer.java +++ b/plugins/nf-amazon/src/main/com/upplication/s3fs/ng/ChunkBuffer.java @@ -42,7 +42,6 @@ public class ChunkBuffer implements Comparable { this.index = index; } - int getIndex() { return index; } @@ -64,19 +63,15 @@ void fill(InputStream stream) throws IOException { } void makeReadable() { - target.flip(); - } - - void mark() { - target.mark(); - } - - void reset() { - target.reset(); + // cast to prevent Java 8 / Java 11 cross compile-runtime error + // https://www.morling.dev/blog/bytebuffer-and-the-dreaded-nosuchmethoderror/ + ((java.nio.Buffer)target).flip(); } void clear() { - target.clear(); + // cast to prevent Java 8 / Java 11 cross compile-runtime error + // https://www.morling.dev/blog/bytebuffer-and-the-dreaded-nosuchmethoderror/ + ((java.nio.Buffer)target).clear(); } int getBytes( byte[] buff, int off, int len ) {