Skip to content
Open
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 @@ -189,7 +189,7 @@ public int readTail(byte[] buffer, int offset, int length) throws IOException {
if (this.fileSize == null) {
this.fileSize = fileClient.getProperties().getFileSize();
}
long readStart = fileSize - length;
long readStart = Math.max(0, fileSize - length);

try (InputStream inputStream = openRange(new FileRange(readStart)).getInputStream()) {
return IOUtil.readRemaining(inputStream, buffer, offset, length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,27 @@ void testReadTailClosesTheStream() throws IOException {

verify(inputStream).close();
}

@Test
void testReadTailLengthLargerThanFileSize() throws IOException {
byte[] data = new byte[] {1, 2, 3};
InputStream byteStream = new ByteArrayInputStream(data);
InternalDataLakeFileOpenInputStreamResult openInputStreamResult =
new InternalDataLakeFileOpenInputStreamResult(byteStream, mock());
when(fileClient.openInputStream(any())).thenReturn(openInputStreamResult);

try (ADLSInputStream in =
new ADLSInputStream(
"abfs://container@account.dfs.core.windows.net/path/to/file",
fileClient,
3L,
mock(),
MetricsContext.nullMetrics())) {

byte[] actual = new byte[10];
int bytesRead = in.readTail(actual, 0, 10);
assertThat(bytesRead).isEqualTo(3);
assertThat(Arrays.copyOfRange(actual, 0, bytesRead)).isEqualTo(data);
}
}
}