Skip to content

Commit

Permalink
Fix cross compilation error
Browse files Browse the repository at this point in the history
  • Loading branch information
pditommaso committed Dec 20, 2021
1 parent e78a997 commit 7491610
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public class ChunkBuffer implements Comparable<ChunkBuffer> {
this.index = index;
}


int getIndex() {
return index;
}
Expand All @@ -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 ) {
Expand Down

0 comments on commit 7491610

Please sign in to comment.