juneau-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamesbog...@apache.org
Subject [juneau] branch master updated: Minor cleanup of ParserPipe.
Date Fri, 23 Mar 2018 23:52:52 GMT
This is an automated email from the ASF dual-hosted git repository.

jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git


The following commit(s) were added to refs/heads/master by this push:
     new e5072b9  Minor cleanup of ParserPipe.
e5072b9 is described below

commit e5072b96b89024befaa967edf6d6f78269e9e412
Author: JamesBognar <jamesbognar@apache.org>
AuthorDate: Fri Mar 23 19:52:51 2018 -0400

    Minor cleanup of ParserPipe.
---
 .../java/org/apache/juneau/ParserReaderTest.java   |  2 +-
 .../juneau/parser/InputStreamParserSession.java    |  2 +-
 .../java/org/apache/juneau/parser/ParserPipe.java  | 36 +++++++++++++++++++---
 .../apache/juneau/parser/ReaderParserSession.java  |  2 +-
 .../java/org/apache/juneau/rest/RestUtils.java     |  2 +-
 5 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/ParserReaderTest.java
b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/ParserReaderTest.java
index d8a2577..f7a92ed 100755
--- a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/ParserReaderTest.java
+++ b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/ParserReaderTest.java
@@ -180,6 +180,6 @@ public class ParserReaderTest {
 	}
 
 	private ParserReader createParserReader(Object in) throws Exception {
-		return new ParserReader(new ParserPipe(in, false, false, false, false, null, null, null));
+		return new ParserReader(new ParserPipe(in));
 	}
 }
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/InputStreamParserSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/InputStreamParserSession.java
index 44943d4..39e7a02 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/InputStreamParserSession.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/InputStreamParserSession.java
@@ -78,7 +78,7 @@ public abstract class InputStreamParserSession extends ParserSession {
 	 */
 	@Override /* ParserSession */
 	public final ParserPipe createPipe(Object input) {
-		return new ParserPipe(input, isDebug(), strict, autoCloseStreams, unbuffered, null, null,
binaryFormat);
+		return new ParserPipe(input, isDebug(), autoCloseStreams, unbuffered, binaryFormat);
 	}
 
 	@Override /* Session */
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ParserPipe.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ParserPipe.java
index 16962b1..deefa1d 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ParserPipe.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ParserPipe.java
@@ -63,7 +63,7 @@ public final class ParserPipe implements Closeable {
 	private BinaryFormat binaryFormat;
 
 	/**
-	 * Constructor.
+	 * Constructor for reader-based parsers.
 	 * 
 	 * @param input The parser input object.
 	 * @param debug
@@ -86,9 +86,8 @@ public final class ParserPipe implements Closeable {
 	 * @param inputStreamCharset
 	 * 	The charset to expect when reading from {@link InputStream InputStreams}.
 	 * 	Use <js>"default"</js> to specify {@link Charset#defaultCharset()}.
-	 * @param binaryFormat The binary format of input strings when converted to bytes.
 	 */
-	public ParserPipe(Object input, boolean debug, boolean strict, boolean autoCloseStreams,
boolean unbuffered, String fileCharset, String inputStreamCharset, BinaryFormat binaryFormat)
{
+	public ParserPipe(Object input, boolean debug, boolean strict, boolean autoCloseStreams,
boolean unbuffered, String fileCharset, String inputStreamCharset) {
 		this.input = input;
 		this.debug = debug;
 		this.strict = strict;
@@ -98,6 +97,35 @@ public final class ParserPipe implements Closeable {
 		this.inputStreamCharset = inputStreamCharset;
 		if (input instanceof CharSequence)
 			this.inputString = input.toString();
+		this.binaryFormat = null;
+	}
+
+	/**
+	 * Constructor for stream-based parsers.
+	 * 
+	 * @param input The parser input object.
+	 * @param debug
+	 * 	If <jk>true</jk>, the input contents will be copied locally and accessible
via the {@link #getInputAsString()}
+	 * 	method.
+	 * 	This allows the contents of the pipe to be accessed when a problem occurs.
+	 * @param autoCloseStreams 
+	 * 	Automatically close {@link InputStream InputStreams} and {@link Reader Readers} when
passed in as input.
+	 * @param unbuffered 
+	 * 	If <jk>true</jk>, we read one character at a time from underlying readers
when the readers are expected to be parsed
+	 * 	multiple times.
+	 * 	<br>Otherwise, we read character data into a reusable buffer.
+	 * @param binaryFormat The binary format of input strings when converted to bytes.
+	 */
+	public ParserPipe(Object input, boolean debug, boolean autoCloseStreams, boolean unbuffered,
BinaryFormat binaryFormat) {
+		this.input = input;
+		this.debug = debug;
+		this.strict = false;
+		this.autoCloseStreams = autoCloseStreams;
+		this.unbuffered = unbuffered;
+		this.fileCharset = null;
+		this.inputStreamCharset = null;
+		if (input instanceof CharSequence)
+			this.inputString = input.toString();
 		this.binaryFormat = binaryFormat;
 	}
 
@@ -110,7 +138,7 @@ public final class ParserPipe implements Closeable {
 	 * @param input The input object.
 	 */
 	public ParserPipe(Object input) {
-		this(input, false, false, false, false, null, null, null);
+		this(input, false, false, false, false, null, null);
 	}
 
 	/**
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ReaderParserSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ReaderParserSession.java
index 1e3b818..cc51d48 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ReaderParserSession.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ReaderParserSession.java
@@ -83,7 +83,7 @@ public abstract class ReaderParserSession extends ParserSession {
 	 */
 	@Override /* ParserSesson */
 	public final ParserPipe createPipe(Object input) {
-		return new ParserPipe(input, isDebug(), strict, autoCloseStreams, unbuffered, fileCharset,
inputStreamCharset, null);
+		return new ParserPipe(input, isDebug(), strict, autoCloseStreams, unbuffered, fileCharset,
inputStreamCharset);
 	}
 
 	@Override /* Session */
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestUtils.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestUtils.java
index 53d2538..e3ee38c 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestUtils.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestUtils.java
@@ -270,7 +270,7 @@ public final class RestUtils {
 		if (qs == null || ((qs instanceof CharSequence) && isEmpty(qs)))
 			return m;
 
-		try (ParserPipe p = new ParserPipe(qs, false, false, false, false, null, null, null)) {
+		try (ParserPipe p = new ParserPipe(qs)) {
 			
 			final int S1=1; // Looking for attrName start.
 			final int S2=2; // Found attrName start, looking for = or & or end.

-- 
To stop receiving notification emails like this one, please contact
jamesbognar@apache.org.

Mime
View raw message