[OLINGO-1547]Avoid BufferOverFlowException in BatchLineReader
This commit is contained in:
parent
911d9d8e7f
commit
e429cb24ad
|
@ -145,12 +145,7 @@ public class BatchLineReader {
|
||||||
|
|
||||||
if (!foundLineEnd) {
|
if (!foundLineEnd) {
|
||||||
byte currentChar = buffer[offset++];
|
byte currentChar = buffer[offset++];
|
||||||
if (!innerBuffer.hasRemaining()) {
|
innerBuffer = grantBuffer(innerBuffer);
|
||||||
innerBuffer.flip();
|
|
||||||
ByteBuffer tmp = ByteBuffer.allocate(innerBuffer.limit() * 2);
|
|
||||||
tmp.put(innerBuffer);
|
|
||||||
innerBuffer = tmp;
|
|
||||||
}
|
|
||||||
innerBuffer.put(currentChar);
|
innerBuffer.put(currentChar);
|
||||||
|
|
||||||
if (currentChar == LF) {
|
if (currentChar == LF) {
|
||||||
|
@ -166,6 +161,7 @@ public class BatchLineReader {
|
||||||
|
|
||||||
// Check if there is at least one character
|
// Check if there is at least one character
|
||||||
if (limit != EOF && buffer[offset] == LF) {
|
if (limit != EOF && buffer[offset] == LF) {
|
||||||
|
innerBuffer = grantBuffer(innerBuffer);
|
||||||
innerBuffer.put(LF);
|
innerBuffer.put(LF);
|
||||||
offset++;
|
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 {
|
private int fillBuffer() throws IOException {
|
||||||
limit = reader.read(buffer, 0, buffer.length);
|
limit = reader.read(buffer, 0, buffer.length);
|
||||||
offset = 0;
|
offset = 0;
|
||||||
|
|
Loading…
Reference in New Issue