[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:
parent
abfdf83f11
commit
a6ca4165a8
|
@ -164,7 +164,7 @@ final class ExtendedBufferedReader extends BufferedReader {
|
||||||
for (int i = offset; i < offset + len; i++) {
|
for (int i = offset; i < offset + len; i++) {
|
||||||
final char ch = buf[i];
|
final char ch = buf[i];
|
||||||
if (ch == LF) {
|
if (ch == LF) {
|
||||||
if (CR != (i > 0 ? buf[i - 1] : lastChar)) {
|
if (CR != (i > offset ? buf[i - 1] : lastChar)) {
|
||||||
eolCounter++;
|
eolCounter++;
|
||||||
}
|
}
|
||||||
} else if (ch == CR) {
|
} else if (ch == CR) {
|
||||||
|
|
|
@ -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) {
|
private ExtendedBufferedReader createBufferedReader(final String s) {
|
||||||
return new ExtendedBufferedReader(new StringReader(s));
|
return new ExtendedBufferedReader(new StringReader(s));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue