Bit more work on DataInput source, test refactoring
diff --git a/src/main/java/com/fasterxml/jackson/core/JsonFactory.java b/src/main/java/com/fasterxml/jackson/core/JsonFactory.java
index 9a9082e..c85652f 100644
--- a/src/main/java/com/fasterxml/jackson/core/JsonFactory.java
+++ b/src/main/java/com/fasterxml/jackson/core/JsonFactory.java
@@ -875,7 +875,7 @@
public JsonParser createParser(String content) throws IOException, JsonParseException {
final int strLen = content.length();
// Actually, let's use this for medium-sized content, up to 64kB chunk (32kb char)
- if (_inputDecorator != null || strLen > 0x8000 || !canUseCharArrays()) {
+ if ((_inputDecorator != null) || (strLen > 0x8000) || !canUseCharArrays()) {
// easier to just wrap in a Reader than extend InputDecorator; or, if content
// is too long for us to copy it over
return createParser(new StringReader(content));
@@ -910,6 +910,14 @@
false);
}
+ /**
+ * @since 2.8
+ */
+ public JsonParser createParser(DataInput in) throws IOException {
+ IOContext ctxt = _createContext(in, false);
+ return _createParser(_decorate(in, ctxt), ctxt);
+ }
+
/*
/**********************************************************
/* Parser factories (old ones, pre-2.2)
@@ -1308,6 +1316,23 @@
_objectCodec, _byteSymbolCanonicalizer, _rootCharSymbols, _factoryFeatures);
}
+ /**
+ * @since 2.8
+ */
+ protected JsonParser _createParser(DataInput input, IOContext ctxt) throws IOException
+ {
+ // 13-May-2016, tatu: Need to take care not to accidentally create JSON parser for
+ // non-JSON input. So, bit unclean but...
+ String format = getFormatName();
+ if (format != FORMAT_NAME_JSON) {
+ throw new UnsupportedOperationException(String.format(
+ "InputData source not (yet?) support for this format (%s)", format));
+ }
+ ByteQuadsCanonicalizer can = _byteSymbolCanonicalizer.makeChild(_factoryFeatures);
+ return new UTF8DataInputJsonParser(ctxt, _parserFeatures, input,
+ _objectCodec, can);
+ }
+
/*
/**********************************************************
/* Factory methods used by factory for creating generator instances,
@@ -1390,7 +1415,7 @@
}
return in;
}
-
+
/**
* @since 2.4
*/
@@ -1405,6 +1430,19 @@
}
/**
+ * @since 2.8
+ */
+ protected final DataInput _decorate(DataInput in, IOContext ctxt) throws IOException {
+ if (_inputDecorator != null) {
+ DataInput in2 = _inputDecorator.decorate(ctxt, in);
+ if (in2 != null) {
+ return in2;
+ }
+ }
+ return in;
+ }
+
+ /**
* @since 2.4
*/
protected final OutputStream _decorate(OutputStream out, IOContext ctxt) throws IOException {