steveloughran commented on code in PR #3543:
URL: https://github.com/apache/parquet-java/pull/3543#discussion_r3221267913
##########
parquet-common/src/test/java/org/apache/parquet/io/TestLocalInputOutput.java:
##########
@@ -89,4 +92,144 @@ private File createTempFile() throws IOException {
tmp.delete();
return tmp;
}
+
+ @Test
+ public void readFullyIntoHeapByteBuffer() throws IOException {
+ Path path = writeBytes(new byte[] {1, 2, 3, 4, 5});
+ try (SeekableInputStream stream = new LocalInputFile(path).newStream()) {
+ ByteBuffer buf = ByteBuffer.allocate(5);
+ stream.readFully(buf);
+ assertEquals(5, buf.position());
+ buf.flip();
+ byte[] out = new byte[5];
+ buf.get(out);
+ assertArrayEquals(new byte[] {1, 2, 3, 4, 5}, out);
+ }
+ }
+
+ @Test
+ public void readFullyIntoHeapByteBufferWithNonZeroPosition() throws
IOException {
+ Path path = writeBytes(new byte[] {10, 20, 30, 40});
+ try (SeekableInputStream stream = new LocalInputFile(path).newStream()) {
+ ByteBuffer buf = ByteBuffer.allocate(6);
+ buf.put(new byte[] {99, 99}); // advance position to 2
+ stream.readFully(buf);
+ assertEquals(6, buf.position());
+ buf.flip();
+ byte[] out = new byte[6];
+ buf.get(out);
+ assertArrayEquals(new byte[] {99, 99, 10, 20, 30, 40}, out);
+ }
+ }
+
+ @Test
+ public void readFullyIntoDirectByteBuffer() throws IOException {
+ Path path = writeBytes(new byte[] {7, 8, 9});
+ try (SeekableInputStream stream = new LocalInputFile(path).newStream()) {
+ ByteBuffer buf = ByteBuffer.allocateDirect(3);
+ stream.readFully(buf);
+ assertEquals(3, buf.position());
+ buf.flip();
+ byte[] out = new byte[3];
+ buf.get(out);
+ assertArrayEquals(new byte[] {7, 8, 9}, out);
+ }
+ }
+
+ @Test
+ public void readFullyIntoReadOnlyByteBuffer() throws IOException {
+ Path path = writeBytes(new byte[] {7, 8, 9});
+ try (SeekableInputStream stream = new LocalInputFile(path).newStream()) {
+ ByteBuffer backing = ByteBuffer.allocate(3);
+ ByteBuffer buf = backing.asReadOnlyBuffer();
+ assertThrows(java.nio.ReadOnlyBufferException.class, () ->
stream.readFully(buf));
Review Comment:
nit: use an import here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]