Repository: johnzon Updated Branches: refs/heads/master e20ac4ff9 -> d7a4a2f9d
JOHNZON-134 fix buffer autoExtend Also reduce fallbackBuffer to 256k as we now have autoextend in place Project: http://git-wip-us.apache.org/repos/asf/johnzon/repo Commit: http://git-wip-us.apache.org/repos/asf/johnzon/commit/d7a4a2f9 Tree: http://git-wip-us.apache.org/repos/asf/johnzon/tree/d7a4a2f9 Diff: http://git-wip-us.apache.org/repos/asf/johnzon/diff/d7a4a2f9 Branch: refs/heads/master Commit: d7a4a2f9de8c39b84fbb8b73b13c6f7f6514a9cf Parents: e20ac4f Author: Mark Struberg <[email protected]> Authored: Fri Sep 22 22:22:01 2017 +0200 Committer: Mark Struberg <[email protected]> Committed: Fri Sep 22 22:22:01 2017 +0200 ---------------------------------------------------------------------- .../java/org/apache/johnzon/core/JsonGeneratorImpl.java | 3 ++- .../org/apache/johnzon/core/JsonParserFactoryImpl.java | 2 +- .../org/apache/johnzon/core/JsonStreamParserImpl.java | 12 ++++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/johnzon/blob/d7a4a2f9/johnzon-core/src/main/java/org/apache/johnzon/core/JsonGeneratorImpl.java ---------------------------------------------------------------------- diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonGeneratorImpl.java b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonGeneratorImpl.java index 1b8b573..bc17340 100644 --- a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonGeneratorImpl.java +++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonGeneratorImpl.java @@ -462,8 +462,9 @@ class JsonGeneratorImpl implements JsonGenerator, JsonChars, Serializable { writer.close(); } catch (final IOException e) { throw new JsonException(e.getMessage(), e); + } finally { + bufferProvider.release(buffer); } - bufferProvider.release(buffer); } } http://git-wip-us.apache.org/repos/asf/johnzon/blob/d7a4a2f9/johnzon-core/src/main/java/org/apache/johnzon/core/JsonParserFactoryImpl.java ---------------------------------------------------------------------- diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonParserFactoryImpl.java b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonParserFactoryImpl.java index 666dae6..440b4cb 100644 --- a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonParserFactoryImpl.java +++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonParserFactoryImpl.java @@ -33,7 +33,7 @@ import static java.util.Arrays.asList; public class JsonParserFactoryImpl extends AbstractJsonFactory implements JsonParserFactory { public static final String MAX_STRING_LENGTH = "org.apache.johnzon.max-string-length"; - public static final int DEFAULT_MAX_STRING_LENGTH = Integer.getInteger(MAX_STRING_LENGTH, 10 * 1024 * 1024); //10m + public static final int DEFAULT_MAX_STRING_LENGTH = Integer.getInteger(MAX_STRING_LENGTH, 256 * 1024); //256kB public static final String AUTO_ADJUST_STRING_BUFFER = "org.apache.johnzon.auto-adjust-buffer"; public static final String BUFFER_LENGTH = "org.apache.johnzon.default-char-buffer"; http://git-wip-us.apache.org/repos/asf/johnzon/blob/d7a4a2f9/johnzon-core/src/main/java/org/apache/johnzon/core/JsonStreamParserImpl.java ---------------------------------------------------------------------- diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonStreamParserImpl.java b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonStreamParserImpl.java index 31e9c1b..7011e01 100644 --- a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonStreamParserImpl.java +++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonStreamParserImpl.java @@ -68,7 +68,7 @@ public class JsonStreamParserImpl implements JsonChars, JohnzonJsonParser { //this buffer is used to store current String or Number value in case that //within the value a buffer boundary is crossed or the string contains escaped characters private char[] fallBackCopyBuffer; - private boolean releaseFallBackCopyBufferLength; + private boolean releaseFallBackCopyBufferLength = true; private int fallBackCopyBufferLength; // location (line, column, offset) @@ -172,7 +172,7 @@ public class JsonStreamParserImpl implements JsonChars, JohnzonJsonParser { throw new ArrayIndexOutOfBoundsException("Buffer too small for such a long string"); } - final char[] newArray = new char[fallBackCopyBuffer.length + 1024]; // small incr to not explode the mem + final char[] newArray = new char[fallBackCopyBuffer.length + getBufferExtends(fallBackCopyBuffer.length)]; // TODO: log to adjust size once? System.arraycopy(fallBackCopyBuffer, 0, newArray, 0, fallBackCopyBufferLength); System.arraycopy(buffer, startOfValueInBuffer, newArray, fallBackCopyBufferLength, length); @@ -190,6 +190,14 @@ public class JsonStreamParserImpl implements JsonChars, JohnzonJsonParser { startOfValueInBuffer = endOfValueInBuffer = -1; } + /** + * @return the amount of bytes the current buffer should get extended with + */ + protected int getBufferExtends(int currentLength) { + return currentLength/4; + } + + @Override public final boolean hasNext() {
