-
Notifications
You must be signed in to change notification settings - Fork 78
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
Core: BlobReadChannel limit parameter doesn't behave as documented in ReadChannel #1512
Comments
When performing a range get of an object, the When running the below code sample, you can see in the further logs public static void main(String[] args) {
Storage s = StorageOptions.newBuilder().build().getService();
BlobInfo obj = BlobInfo.newBuilder(bucket, "obj/62").build();
String base62 = Streams.concat(
IntStream.rangeClosed('0', '9'),
IntStream.rangeClosed('A', 'Z'),
IntStream.rangeClosed('a', 'z')
)
.mapToObj(i -> (char) i)
.map(Object::toString)
.collect(Collectors.joining(""));
Blob blob = s.create(obj, base62.getBytes(StandardCharsets.UTF_8), BlobTargetOption.doesNotExist());
Long size = blob.getSize();
System.out.println("size = " + size);
try (ReadChannel r = s.reader(obj.getBlobId()).limit(35)) {
r.seek(5);
ByteStreams.copy(Channels.newInputStream(r), System.out);
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
|
@BenWhitehead First of all thank you for the response and explanation 😀 Sounds like ReadChannel treats it as number of bytes to read |
Do you feel like the following modification clarifies and matches better with the behavior? - * Limit the maximum number of bytes available to be read from this channel. If the limit is
- * larger than the actual size of the content this will have no material impact.
+ * Limit the maximum number of bytes to be read from the objects content, counting from the
+ * beginning of the object, which will be available to read from this channel. If the limit
+ * is larger than the actual size of the content this will have no material impact.
+ *
+ * If used in conjunction with {@link #seek(long)} the total number of returned bytes from
+ * this channel will be reduced by the number of bytes specified to seek. |
@BenWhitehead That's better I think |
Environment details
Any additional information below
The limit parameter in ReadChannel is documented as the following:
However, when trying to use the BlobReadChannel to read a range of bytes from object storage, limit is used as end-exclusive:
final int toRead = Math.toIntExact(Math.min(limit - position, Math.max(byteBuffer.remaining(), chunkSize)));
If you look in documentation it is also stated explicitly:
https://cloud.google.com/storage/docs/samples/storage-download-byte-range
Is this unintended behaviour or a documentation issue?
Thanks!
The text was updated successfully, but these errors were encountered: