Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
updated ExtendedBufferedReader.java
  • Loading branch information
ymittalunisa committed Dec 29, 2023
commit 9a29262ae62369677736591e2723bb3b46990616
22 changes: 13 additions & 9 deletions src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,28 @@ public int read(final char[] buf, final int offset, final int length) throws IOE

final int len = super.read(buf, offset, length);

int eolCount = 0;


if (len > 0) {

for (int i = offset; i < offset + len; i++) {
final char ch = buf[i];
if (ch == CR) {
if (i < offset + len - 1 && buf[i + 1] == LF) {
i++;
if (ch == LF) {
if (CR != (i > offset ? buf[i - 1] : lastChar)) {
eolCounter++;
}
} else if (ch == LF) {
eolCount++;
} else if (ch == CR) {
eolCounter++;
}
}

lastChar = buf[offset + len - 1];

} else if (len == -1) {
lastChar = END_OF_STREAM;
} else {
throw new IOException("Unexpected read length");
}

position += len;
return len;
eolCounter += eolCount;

position += len;
Expand Down