Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -230,10 +232,14 @@ public int read()
public long skip(long length)
throws IOException
{
if (length <= 0) {
return 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for length == 0, it's obvious.
why also for length < 0? is it worth explanatory comment?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the behavior specified in the Javadoc and in the default implementation.

}

int availableBytes = availableBytes();
// is skip within the current buffer?
if (availableBytes >= length) {
bufferPosition = checkedCast(bufferPosition + length);
bufferPosition = addExact(bufferPosition, toIntExact(length));
return length;
}

Expand Down Expand Up @@ -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
//
Expand Down