Skip to content
Permalink
Browse files
[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>
  • Loading branch information
3 people committed Jul 7, 2021
1 parent abfdf83 commit a6ca4165a8f8d156f0fbfe33627bac1509e7ae9c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
@@ -164,7 +164,7 @@ public int read(final char[] buf, final int offset, final int length) throws IOE
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) {
@@ -204,6 +204,15 @@ public void testReadChar() throws Exception {
}
}

@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));
}

0 comments on commit a6ca416

Please sign in to comment.