[OLINGO-1547]Avoid BufferOverFlowException in BatchLineReader
This commit is contained in:
parent
911d9d8e7f
commit
e429cb24ad
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue