Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ai.rapids.cudf.HostMemoryBuffer#copyFromStream public. #17179

Merged
merged 10 commits into from
Oct 30, 2024
6 changes: 4 additions & 2 deletions java/src/main/java/ai/rapids/cudf/HostMemoryBuffer.java
liurenjie1024 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -255,16 +255,18 @@ public final void copyFromHostBuffer(long destOffset, HostMemoryBuffer srcData,
* @param destOffset offset in bytes in this buffer to start copying to
* @param in input stream to copy bytes from
* @param byteLength number of bytes to copy
* @throws EOFException If there are not enough bytes in the stream to copy.
* @throws IOException If there is an error reading from the stream.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update the docs so that it is clear that an EOFException is thrown if the InputStream does not include enough bytes to do the copy. Also it would really be nice if we could include a message with the EOFException to indicate what happened.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

final void copyFromStream(long destOffset, InputStream in, long byteLength) throws IOException {
public final void copyFromStream(long destOffset, InputStream in, long byteLength) throws IOException {
addressOutOfBoundsCheck(address + destOffset, byteLength, "copy from stream");
byte[] arrayBuffer = new byte[(int) Math.min(1024 * 128, byteLength)];
long left = byteLength;
while (left > 0) {
int amountToCopy = (int) Math.min(arrayBuffer.length, left);
int amountRead = in.read(arrayBuffer, 0, amountToCopy);
if (amountRead < 0) {
throw new EOFException();
throw new EOFException("Unexpected end of stream, expected " + left + " more bytes");
}
setBytes(destOffset, arrayBuffer, 0, amountRead);
destOffset += amountRead;
Expand Down
Loading