From 2f6ad0076490438b6dea232de2ccaaf23d54ee45 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Sat, 18 Dec 2021 11:34:44 +0000 Subject: [PATCH] Use Java 16 ByteBuffer methods where possible --- .../java/dan200/computercraft/client/sound/DfpwmStream.java | 3 ++- .../computercraft/shared/computer/upload/FileSlice.java | 6 +----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/dan200/computercraft/client/sound/DfpwmStream.java b/src/main/java/dan200/computercraft/client/sound/DfpwmStream.java index db69c77a4..38c29c851 100644 --- a/src/main/java/dan200/computercraft/client/sound/DfpwmStream.java +++ b/src/main/java/dan200/computercraft/client/sound/DfpwmStream.java @@ -106,7 +106,8 @@ class DfpwmStream implements AudioStream if( head == null ) break; int toRead = Math.min( head.remaining(), result.remaining() ); - result.put( head.array(), head.position(), toRead ); // TODO: In 1.17 convert this to a ByteBuffer override + result.put( result.position(), head, head.position(), toRead ); + result.position( result.position() + toRead ); head.position( head.position() + toRead ); if( head.hasRemaining() ) break; diff --git a/src/main/java/dan200/computercraft/shared/computer/upload/FileSlice.java b/src/main/java/dan200/computercraft/shared/computer/upload/FileSlice.java index c9103891b..5f1a7e2d2 100644 --- a/src/main/java/dan200/computercraft/shared/computer/upload/FileSlice.java +++ b/src/main/java/dan200/computercraft/shared/computer/upload/FileSlice.java @@ -53,10 +53,6 @@ public class FileSlice return; } - ByteBuffer other = file.duplicate(); - other.position( offset ); // TODO: In 1.17 we can use a separate put(idx, _) method. - other.put( bytes ); - - if( bytes.remaining() != 0 ) throw new IllegalStateException( "Should have read the whole buffer" ); + file.put( offset, bytes, bytes.position(), bytes.remaining() ); } }