Skip to content
Closed
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 @@ -16,6 +16,7 @@
*/
package org.apache.commons.io.input;

import static org.junit.jupiter.api.Assertions.assertNull;
import static org.apache.commons.io.input.ReversedLinesFileReaderParamBlockSizeTest.assertEqualsAndNoLineBreaks;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand All @@ -25,7 +26,10 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.charset.StandardCharsets;

import java.util.List;

import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -108,4 +112,23 @@ void testUnsupportedEncodingUTF16() throws URISyntaxException {
assertThrows(UnsupportedEncodingException.class,
() -> new ReversedLinesFileReader(testFileEmpty, IOUtils.DEFAULT_BUFFER_SIZE, StandardCharsets.UTF_16.name()).close());
}
@Test
public void testEmptyFirstLineIsRead() throws Exception {
Path file = Files.createTempFile("reversed", ".txt");

// Write a file that contains ONLY a newline
Files.write(file, "\n".getBytes(StandardCharsets.UTF_8));

try (ReversedLinesFileReader reader =
new ReversedLinesFileReader(file.toFile(), StandardCharsets.UTF_8)) {

// BUG: this currently returns null, but should return ""
String firstLine = reader.readLine();

assertEquals("", firstLine, "Empty first line should be returned as empty string");

// After that, there should be no more lines
assertNull(reader.readLine());
}
}
}
Loading