From e588a1bd9da8e4cc6131ad2fac672b8feeff750e Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Wed, 20 May 2020 16:14:05 +0200 Subject: [PATCH] Fixes #4892 - Non-blocking JSON parser. Added parse(byte[], int, int). Signed-off-by: Simone Bordet --- .../org/eclipse/jetty/util/ajax/AsyncJSON.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/AsyncJSON.java b/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/AsyncJSON.java index 9899258cfac..83087aa38db 100644 --- a/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/AsyncJSON.java +++ b/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/AsyncJSON.java @@ -203,10 +203,25 @@ public class AsyncJSON * * @param bytes the bytes to parse * @return whether the JSON parsing was complete + * @throws IllegalArgumentException if the JSON is malformed */ public boolean parse(byte[] bytes) { - return parse(ByteBuffer.wrap(bytes)); + return parse(bytes, 0, bytes.length); + } + + /** + *

Feeds the parser with the given bytes chunk.

+ * + * @param bytes the bytes to parse + * @param offset the offset to start parsing from + * @param length the number of bytes to parse + * @return whether the JSON parsing was complete + * @throws IllegalArgumentException if the JSON is malformed + */ + public boolean parse(byte[] bytes, int offset, int length) + { + return parse(ByteBuffer.wrap(bytes, offset, length)); } /**