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 @@ -234,7 +234,7 @@ public int read() throws IOException {
return EOF;
}
}
return Short.toUnsignedInt(buffer.get());
return buffer.get() & 0xFF;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ void testReadAfterClose(final int len) throws Exception {
}
}

@Test
void testReadSingleByteIsUnsigned() throws IOException {
final byte[] expectedData = { 0x00, 0x01, 0x7F, (byte) 0x80, (byte) 0xAB, (byte) 0xFE, (byte) 0xFF };
final Path file = Files.write(Files.createTempFile(tempDir, null, null), expectedData);
try (InputStream inputStream = newInputStream(file, 4)) {
for (final byte expected : expectedData) {
assertEquals(expected & 0xFF, inputStream.read());
}
assertEquals(IOUtils.EOF, inputStream.read());
}
}

@Test
void testReadSingleByte() throws IOException {
// setup
Expand Down