[CSV-158] Fix EOL checking for read array in ExtendedBufferedReader (#5)

* Fix eol checking for read array in ExtendedBufferedReader

* Add test for eol checking when reading to different buffers

Co-authored-by: mirasrael <d_signer@mail.ru>
Co-authored-by: Alexander Bondarev <alexander.bondarev@thomsonreuters.com>
This commit is contained in:
Alexander Bondarev 2021-07-07 15:35:17 +03:00 committed by GitHub
parent abfdf83f11
commit a6ca4165a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -164,7 +164,7 @@ final class ExtendedBufferedReader extends BufferedReader {
for (int i = offset; i < offset + len; i++) {
final char ch = buf[i];
if (ch == LF) {
if (CR != (i > 0 ? buf[i - 1] : lastChar)) {
if (CR != (i > offset ? buf[i - 1] : lastChar)) {
eolCounter++;
}
} else if (ch == CR) {

View File

@ -204,6 +204,15 @@ public class ExtendedBufferedReaderTest {
}
}
@Test
public void testReadingInDifferentBuffer() throws Exception {
char[] tmp1 = new char[2], tmp2 = new char[4];
ExtendedBufferedReader br = createBufferedReader("1\r\n2\r\n");
br.read(tmp1, 0, 2);
br.read(tmp2, 2, 2);
assertEquals(2, br.getCurrentLineNumber());
}
private ExtendedBufferedReader createBufferedReader(final String s) {
return new ExtendedBufferedReader(new StringReader(s));
}