diff --git a/lib/trino-hive-formats/src/main/java/io/trino/hive/formats/TrinoDataInputStream.java b/lib/trino-hive-formats/src/main/java/io/trino/hive/formats/TrinoDataInputStream.java index 8521bcd4174e..5d1996634246 100644 --- a/lib/trino-hive-formats/src/main/java/io/trino/hive/formats/TrinoDataInputStream.java +++ b/lib/trino-hive-formats/src/main/java/io/trino/hive/formats/TrinoDataInputStream.java @@ -31,6 +31,8 @@ import static io.airlift.slice.SizeOf.SIZE_OF_SHORT; import static io.airlift.slice.SizeOf.instanceSize; import static io.airlift.slice.SizeOf.sizeOf; +import static java.lang.Math.addExact; +import static java.lang.Math.toIntExact; import static java.util.Objects.requireNonNull; public final class TrinoDataInputStream @@ -86,7 +88,7 @@ public long getReadBytes() public long getPos() throws IOException { - return checkedCast(bufferOffset + bufferPosition); + return addExact(bufferOffset, bufferPosition); } public void seek(long newPos) @@ -230,10 +232,14 @@ public int read() public long skip(long length) throws IOException { + if (length <= 0) { + return 0; + } + int availableBytes = availableBytes(); // is skip within the current buffer? if (availableBytes >= length) { - bufferPosition = checkedCast(bufferPosition + length); + bufferPosition = addExact(bufferPosition, toIntExact(length)); return length; } @@ -398,13 +404,6 @@ private int fillBuffer() return bufferFill; } - private static int checkedCast(long value) - { - int result = (int) value; - checkArgument(result == value, "Size is greater than maximum int value"); - return result; - } - // // Unsupported operations //