This is an automated email from the ASF dual-hosted git repository.

wgtmac pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/parquet-java.git


The following commit(s) were added to refs/heads/master by this push:
     new 9d518b179 MINOR: Preserve ByteBuffer order in little-endian reads 
(#3702)
9d518b179 is described below

commit 9d518b179fc48338322c8e7ef251fdc5b16346e3
Author: Minh Vu <[email protected]>
AuthorDate: Sun Sep 6 17:51:50 2026 +0200

    MINOR: Preserve ByteBuffer order in little-endian reads (#3702)
---
 .../java/org/apache/parquet/io/api/Binary.java     |  3 +--
 .../java/org/apache/parquet/io/api/TestBinary.java | 22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/parquet-column/src/main/java/org/apache/parquet/io/api/Binary.java 
b/parquet-column/src/main/java/org/apache/parquet/io/api/Binary.java
index 58961256f..f53199803 100644
--- a/parquet-column/src/main/java/org/apache/parquet/io/api/Binary.java
+++ b/parquet-column/src/main/java/org/apache/parquet/io/api/Binary.java
@@ -24,7 +24,6 @@ import java.io.ObjectStreamException;
 import java.io.OutputStream;
 import java.io.Serializable;
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
 import java.nio.CharBuffer;
 import java.nio.charset.CharacterCodingException;
 import java.nio.charset.StandardCharsets;
@@ -590,7 +589,7 @@ public abstract class Binary implements Comparable<Binary>, 
Serializable {
         throw new IllegalArgumentException("length must be 2");
       }
 
-      return value.order(ByteOrder.LITTLE_ENDIAN).getShort(offset);
+      return (short) (((value.get(offset + 1) & 0xff) << 8) | 
(value.get(offset) & 0xff));
     }
 
     @Override
diff --git 
a/parquet-column/src/test/java/org/apache/parquet/io/api/TestBinary.java 
b/parquet-column/src/test/java/org/apache/parquet/io/api/TestBinary.java
index cda54becd..d925572bc 100644
--- a/parquet-column/src/test/java/org/apache/parquet/io/api/TestBinary.java
+++ b/parquet-column/src/test/java/org/apache/parquet/io/api/TestBinary.java
@@ -27,6 +27,7 @@ import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
 import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import org.apache.parquet.io.ParquetEncodingException;
@@ -422,6 +423,27 @@ public class TestBinary {
     assertThat(b3.get2BytesLittleEndian()).isEqualTo((short) 0x0201);
   }
 
+  @Test
+  public void testGet2BytesLittleEndianPreservesByteBufferOrder() {
+    assertGet2BytesLittleEndianPreservesOrder(ByteBuffer.wrap(new byte[] 
{0x01, 0x02}));
+
+    ByteBuffer direct = ByteBuffer.allocateDirect(2);
+    direct.put(new byte[] {0x01, 0x02});
+    direct.flip();
+    assertGet2BytesLittleEndianPreservesOrder(direct);
+
+    assertGet2BytesLittleEndianPreservesOrder(
+        ByteBuffer.wrap(new byte[] {0x01, 0x02}).asReadOnlyBuffer());
+  }
+
+  private static void assertGet2BytesLittleEndianPreservesOrder(ByteBuffer 
buffer) {
+    buffer.order(ByteOrder.BIG_ENDIAN);
+    Binary binary = Binary.fromConstantByteBuffer(buffer);
+
+    assertThat(binary.get2BytesLittleEndian()).isEqualTo((short) 0x0201);
+    assertThat(buffer.order()).isEqualTo(ByteOrder.BIG_ENDIAN);
+  }
+
   @Test
   public void testGet2BytesLittleEndianWrongLength() {
     // ByteBufferBackedBinary: get2BytesLittleEndian

Reply via email to