Author: nextgens
Date: 2008-08-17 18:48:01 +0000 (Sun, 17 Aug 2008)
New Revision: 21980
Modified:
trunk/freenet/src/freenet/support/io/LineReadingInputStream.java
Log:
bug #2501: fix the reallocation policy
Modified: trunk/freenet/src/freenet/support/io/LineReadingInputStream.java
===================================================================
--- trunk/freenet/src/freenet/support/io/LineReadingInputStream.java
2008-08-17 18:38:15 UTC (rev 21979)
+++ trunk/freenet/src/freenet/support/io/LineReadingInputStream.java
2008-08-17 18:48:01 UTC (rev 21980)
@@ -57,9 +57,11 @@
if(ctr >= maxLength)
throw new TooLongException("We reached
maxLength="+maxLength+ " parsing\n "+HexUtil.bytesToHex(buf, 0, ctr) + "\n" +
new String(buf, 0, ctr, utf ? "UTF-8" : "ISO-8859-1"));
}
- byte[] newBuf = new byte[buf.length * 2];
- System.arraycopy(buf, 0, newBuf, 0, buf.length);
- buf = newBuf;
+ if(buf.length - ctr < 1) {
+ byte[] newBuf = new byte[Math.min(buf.length *
2, maxLength)];
+ System.arraycopy(buf, 0, newBuf, 0, buf.length);
+ buf = newBuf;
+ }
}
}