Skip to content
Merged
Show file tree
Hide file tree
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 @@ -117,7 +117,7 @@ public int read() throws IOException {
readBytes.increment();
readOperations.increment();

return singleByteBuffer.array()[0];
return singleByteBuffer.array()[0] & 0xFF;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use Byte.toUnsignedInt() here to be more clear?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ public void testRead() throws Exception {
}
}

@Test
public void testReadSingle() throws Exception {
BlobId uri = BlobId.fromGsUtilUri("gs://bucket/path/to/read.dat");
int i0 = 1;
int i1 = 255;
byte[] data = {(byte) i0, (byte) i1};

writeGCSData(uri, data);

try (SeekableInputStream in =
new GCSInputStream(storage, uri, gcpProperties, MetricsContext.nullMetrics())) {
assertThat(in.read()).isEqualTo(i0);
assertThat(in.read()).isEqualTo(i1);
}
}

private void readAndCheck(
SeekableInputStream in, long rangeStart, int size, byte[] original, boolean buffered)
throws IOException {
Expand Down