[OLINGO-1547]Avoid BufferOverFlowException in BatchLineReader

This commit is contained in:
ramya vasanth 2021-09-17 11:35:14 +05:30
parent 911d9d8e7f
commit e429cb24ad
1 changed files with 12 additions and 6 deletions

View File

@ -145,12 +145,7 @@ public class BatchLineReader {
if (!foundLineEnd) {
byte currentChar = buffer[offset++];
if (!innerBuffer.hasRemaining()) {
innerBuffer.flip();
ByteBuffer tmp = ByteBuffer.allocate(innerBuffer.limit() * 2);
tmp.put(innerBuffer);
innerBuffer = tmp;
}
innerBuffer = grantBuffer(innerBuffer);
innerBuffer.put(currentChar);
if (currentChar == LF) {
@ -166,6 +161,7 @@ public class BatchLineReader {
// Check if there is at least one character
if (limit != EOF && buffer[offset] == LF) {
innerBuffer = grantBuffer(innerBuffer);
innerBuffer.put(LF);
offset++;
}
@ -183,6 +179,16 @@ public class BatchLineReader {
}
}
private ByteBuffer grantBuffer(ByteBuffer buffer) {
if(!buffer.hasRemaining()) {
buffer.flip();
ByteBuffer tmp = ByteBuffer.allocate(buffer.limit() *2);
tmp.put(buffer);
buffer = tmp;
}
return buffer;
}
private int fillBuffer() throws IOException {
limit = reader.read(buffer, 0, buffer.length);
offset = 0;