From ae990d4d0dbd8203973fe3190578b65eb8624d39 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Thu, 5 Oct 2017 17:54:36 -0700 Subject: [PATCH] yet more refactoring --- .../fasterxml/jackson/core/JsonFactory.java | 4 +- .../jackson/core/base/BinaryTSFactory.java | 32 +++---- .../jackson/core/base/DecorableTSFactory.java | 20 ++--- .../jackson/core/base/TextualTSFactory.java | 89 ++++++++++--------- 4 files changed, 73 insertions(+), 72 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/core/JsonFactory.java b/src/main/java/com/fasterxml/jackson/core/JsonFactory.java index ae8cdbe41c..e99350aaa4 100644 --- a/src/main/java/com/fasterxml/jackson/core/JsonFactory.java +++ b/src/main/java/com/fasterxml/jackson/core/JsonFactory.java @@ -310,7 +310,7 @@ protected JsonParser _createParser(DataInput input, IOContext ctxt) throws IOExc @Override protected JsonGenerator _createGenerator(ObjectWriteContext writeCtxt, - Writer out, IOContext ioCtxt) throws IOException + IOContext ioCtxt, Writer out) throws IOException { SerializableString rootSep = writeCtxt.getRootValueSeparator(_rootValueSeparator); CharacterEscapes charEsc = writeCtxt.getCharacterEscapes(); @@ -326,7 +326,7 @@ protected JsonGenerator _createGenerator(ObjectWriteContext writeCtxt, @Override protected JsonGenerator _createUTF8Generator(ObjectWriteContext writeCtxt, - OutputStream out, IOContext ioCtxt) throws IOException + IOContext ioCtxt, OutputStream out) throws IOException { SerializableString rootSep = writeCtxt.getRootValueSeparator(_rootValueSeparator); CharacterEscapes charEsc = writeCtxt.getCharacterEscapes(); diff --git a/src/main/java/com/fasterxml/jackson/core/base/BinaryTSFactory.java b/src/main/java/com/fasterxml/jackson/core/base/BinaryTSFactory.java index 330b6d6c0a..1be9f00481 100644 --- a/src/main/java/com/fasterxml/jackson/core/base/BinaryTSFactory.java +++ b/src/main/java/com/fasterxml/jackson/core/base/BinaryTSFactory.java @@ -51,23 +51,23 @@ public boolean canHandleBinaryNatively() { @Override public JsonParser createParser(File f) throws IOException { // true, since we create InputStream from File - IOContext ctxt = _createContext(f, true); + IOContext ioCtxt = _createContext(f, true); InputStream in = new FileInputStream(f); - return _createParser(_decorate(in, ctxt), ctxt); + return _createParser(_decorate(ioCtxt, in), ioCtxt); } @Override public JsonParser createParser(URL url) throws IOException { // true, since we create InputStream from URL - IOContext ctxt = _createContext(url, true); + IOContext ioCtxt = _createContext(url, true); InputStream in = _optimizedStreamFromURL(url); - return _createParser(_decorate(in, ctxt), ctxt); + return _createParser(_decorate(ioCtxt, in), ioCtxt); } @Override public JsonParser createParser(InputStream in) throws IOException { - IOContext ctxt = _createContext(in, false); - return _createParser(_decorate(in, ctxt), ctxt); + IOContext ioCtxt = _createContext(in, false); + return _createParser(_decorate(ioCtxt, in), ioCtxt); } @Override @@ -77,14 +77,14 @@ public JsonParser createParser(Reader r) throws IOException { @Override public JsonParser createParser(byte[] data, int offset, int len) throws IOException { - IOContext ctxt = _createContext(data, true, null); + IOContext ioCtxt = _createContext(data, true, null); if (_inputDecorator != null) { - InputStream in = _inputDecorator.decorate(ctxt, data, offset, len); + InputStream in = _inputDecorator.decorate(ioCtxt, data, offset, len); if (in != null) { - return _createParser(in, ctxt); + return _createParser(in, ioCtxt); } } - return _createParser(data, offset, len, ctxt); + return _createParser(data, offset, len, ioCtxt); } @Override @@ -99,8 +99,8 @@ public JsonParser createParser(char[] content, int offset, int len) throws IOExc @Override public JsonParser createParser(DataInput in) throws IOException { - IOContext ctxt = _createContext(in, false); - return _createParser(_decorate(in, ctxt), ctxt); + IOContext ioCtxt = _createContext(in, false); + return _createParser(_decorate(ioCtxt, in), ioCtxt); } protected abstract JsonParser _createParser(InputStream in, IOContext ctxt) throws IOException; @@ -121,7 +121,7 @@ public JsonGenerator createGenerator(OutputStream out, JsonEncoding enc) { // false -> we won't manage the stream unless explicitly directed to IOContext ioCtxt = _createContext(out, false, enc); - return _createGenerator(EMPTY_WRITE_CONTEXT, ioCtxt, _decorate(out, ioCtxt)); + return _createGenerator(EMPTY_WRITE_CONTEXT, ioCtxt, _decorate(ioCtxt, out)); } @Override @@ -135,7 +135,7 @@ public JsonGenerator createGenerator(File f, JsonEncoding enc) throws IOExceptio OutputStream out = new FileOutputStream(f); // true -> yes, we have to manage the stream since we created it IOContext ioCtxt = _createContext(out, true, enc); - return _createGenerator(EMPTY_WRITE_CONTEXT, ioCtxt, _decorate(out, ioCtxt)); + return _createGenerator(EMPTY_WRITE_CONTEXT, ioCtxt, _decorate(ioCtxt, out)); } @Override @@ -145,7 +145,7 @@ public JsonGenerator createGenerator(ObjectWriteContext writeCtxt, { // false -> we won't manage the stream unless explicitly directed to IOContext ioCtxt = _createContext(out, false, enc); - return _createGenerator(writeCtxt, ioCtxt, _decorate(out, ioCtxt)); + return _createGenerator(writeCtxt, ioCtxt, _decorate(ioCtxt, out)); } @Override @@ -161,7 +161,7 @@ public JsonGenerator createGenerator(ObjectWriteContext writeCtxt, OutputStream out = new FileOutputStream(f); // true -> yes, we have to manage the stream since we created it IOContext ioCtxt = _createContext(out, true, enc); - return _createGenerator(writeCtxt, ioCtxt, _decorate(out, ioCtxt)); + return _createGenerator(writeCtxt, ioCtxt, _decorate(ioCtxt, out)); } /* diff --git a/src/main/java/com/fasterxml/jackson/core/base/DecorableTSFactory.java b/src/main/java/com/fasterxml/jackson/core/base/DecorableTSFactory.java index 02fc0cd0c5..eef96dc438 100644 --- a/src/main/java/com/fasterxml/jackson/core/base/DecorableTSFactory.java +++ b/src/main/java/com/fasterxml/jackson/core/base/DecorableTSFactory.java @@ -105,10 +105,10 @@ public DecorableTSFactory setInputDecorator(InputDecorator d) { /********************************************************** */ - protected InputStream _decorate(InputStream in, IOContext ctxt) throws IOException + protected InputStream _decorate(IOContext ioCtxt, InputStream in) throws IOException { if (_inputDecorator != null) { - InputStream in2 = _inputDecorator.decorate(ctxt, in); + InputStream in2 = _inputDecorator.decorate(ioCtxt, in); if (in2 != null) { return in2; } @@ -116,10 +116,10 @@ protected InputStream _decorate(InputStream in, IOContext ctxt) throws IOExcepti return in; } - protected Reader _decorate(Reader in, IOContext ctxt) throws IOException + protected Reader _decorate(IOContext ioCtxt, Reader in) throws IOException { if (_inputDecorator != null) { - Reader in2 = _inputDecorator.decorate(ctxt, in); + Reader in2 = _inputDecorator.decorate(ioCtxt, in); if (in2 != null) { return in2; } @@ -127,10 +127,10 @@ protected Reader _decorate(Reader in, IOContext ctxt) throws IOException return in; } - protected DataInput _decorate(DataInput in, IOContext ctxt) throws IOException + protected DataInput _decorate(IOContext ioCtxt, DataInput in) throws IOException { if (_inputDecorator != null) { - DataInput in2 = _inputDecorator.decorate(ctxt, in); + DataInput in2 = _inputDecorator.decorate(ioCtxt, in); if (in2 != null) { return in2; } @@ -144,10 +144,10 @@ protected DataInput _decorate(DataInput in, IOContext ctxt) throws IOException /********************************************************** */ - protected OutputStream _decorate(OutputStream out, IOContext ctxt) throws IOException + protected OutputStream _decorate(IOContext ioCtxt, OutputStream out) throws IOException { if (_outputDecorator != null) { - OutputStream out2 = _outputDecorator.decorate(ctxt, out); + OutputStream out2 = _outputDecorator.decorate(ioCtxt, out); if (out2 != null) { return out2; } @@ -155,10 +155,10 @@ protected OutputStream _decorate(OutputStream out, IOContext ctxt) throws IOExce return out; } - protected Writer _decorate(Writer out, IOContext ctxt) throws IOException + protected Writer _decorate(IOContext ioCtxt, Writer out) throws IOException { if (_outputDecorator != null) { - Writer out2 = _outputDecorator.decorate(ctxt, out); + Writer out2 = _outputDecorator.decorate(ioCtxt, out); if (out2 != null) { return out2; } diff --git a/src/main/java/com/fasterxml/jackson/core/base/TextualTSFactory.java b/src/main/java/com/fasterxml/jackson/core/base/TextualTSFactory.java index df73775843..f2e82ff956 100644 --- a/src/main/java/com/fasterxml/jackson/core/base/TextualTSFactory.java +++ b/src/main/java/com/fasterxml/jackson/core/base/TextualTSFactory.java @@ -70,40 +70,40 @@ public boolean canHandleBinaryNatively() { @Override public JsonParser createParser(File f) throws IOException { // true, since we create InputStream from File - IOContext ctxt = _createContext(f, true); - return _createParser(_decorate(new FileInputStream(f), ctxt), ctxt); + IOContext ioCtxt = _createContext(f, true); + return _createParser(_decorate(ioCtxt, new FileInputStream(f)), ioCtxt); } @Override public JsonParser createParser(URL url) throws IOException { // true, since we create InputStream from URL - IOContext ctxt = _createContext(url, true); - return _createParser(_decorate(_optimizedStreamFromURL(url), ctxt), ctxt); + IOContext ioCtxt = _createContext(url, true); + return _createParser(_decorate(ioCtxt, _optimizedStreamFromURL(url)), ioCtxt); } @Override public JsonParser createParser(InputStream in) throws IOException { - IOContext ctxt = _createContext(in, false); - return _createParser(_decorate(in, ctxt), ctxt); + IOContext ioCtxt = _createContext(in, false); + return _createParser(_decorate(ioCtxt, in), ioCtxt); } @Override public JsonParser createParser(Reader r) throws IOException { // false -> we do NOT own Reader (did not create it) - IOContext ctxt = _createContext(r, false); - return _createParser(_decorate(r, ctxt), ctxt); + IOContext ioCtxt = _createContext(r, false); + return _createParser(_decorate(ioCtxt, r), ioCtxt); } @Override public JsonParser createParser(byte[] data, int offset, int len) throws IOException { - IOContext ctxt = _createContext(data, true); + IOContext ioCtxt = _createContext(data, true); if (_inputDecorator != null) { - InputStream in = _inputDecorator.decorate(ctxt, data, offset, len); + InputStream in = _inputDecorator.decorate(ioCtxt, data, offset, len); if (in != null) { - return _createParser(in, ctxt); + return _createParser(in, ioCtxt); } } - return _createParser(data, offset, len, ctxt); + return _createParser(data, offset, len, ioCtxt); } @Override @@ -115,10 +115,10 @@ public JsonParser createParser(String content) throws IOException { // is too long for us to copy it over return createParser(new StringReader(content)); } - IOContext ctxt = _createContext(content, true); - char[] buf = ctxt.allocTokenBuffer(strLen); + IOContext ioCtxt = _createContext(content, true); + char[] buf = ioCtxt.allocTokenBuffer(strLen); content.getChars(0, strLen, buf, 0); - return _createParser(buf, 0, strLen, ctxt, true); + return _createParser(buf, 0, strLen, ioCtxt, true); } @Override @@ -133,8 +133,8 @@ public JsonParser createParser(char[] content, int offset, int len) throws IOExc @Override public JsonParser createParser(DataInput in) throws IOException { - IOContext ctxt = _createContext(in, false); - return _createParser(_decorate(in, ctxt), ctxt); + IOContext ioCtxt = _createContext(in, false); + return _createParser(_decorate(ioCtxt, in), ioCtxt); } protected abstract JsonParser _createParser(InputStream in, IOContext ctxt) throws IOException; @@ -159,21 +159,21 @@ public JsonGenerator createGenerator(OutputStream out, JsonEncoding enc) throws IOException { // false -> we won't manage the stream unless explicitly directed to - IOContext ctxt = _createContext(out, false).setEncoding(enc); + IOContext ioCtxt = _createContext(out, false).setEncoding(enc); if (enc == JsonEncoding.UTF8) { - return _createUTF8Generator(EMPTY_WRITE_CONTEXT, - _decorate(out, ctxt), ctxt); + return _createUTF8Generator(EMPTY_WRITE_CONTEXT, ioCtxt, + _decorate(ioCtxt, out)); } - Writer w = _createWriter(out, enc, ctxt); - return _createGenerator(EMPTY_WRITE_CONTEXT, - _decorate(w, ctxt), ctxt); + Writer w = _createWriter(ioCtxt, out, enc); + return _createGenerator(EMPTY_WRITE_CONTEXT, ioCtxt, + _decorate(ioCtxt, w)); } @Override public JsonGenerator createGenerator(Writer w) throws IOException { - IOContext ctxt = _createContext(w, false); - return _createGenerator(EMPTY_WRITE_CONTEXT, - _decorate(w, ctxt), ctxt); + IOContext ioCtxt = _createContext(w, false); + return _createGenerator(EMPTY_WRITE_CONTEXT, ioCtxt, + _decorate(ioCtxt, w)); } @Override @@ -181,13 +181,13 @@ public JsonGenerator createGenerator(File f, JsonEncoding enc) throws IOExceptio { OutputStream out = new FileOutputStream(f); // true -> yes, we have to manage the stream since we created it - IOContext ctxt = _createContext(f, true).setEncoding(enc); + IOContext ioCtxt = _createContext(f, true).setEncoding(enc); if (enc == JsonEncoding.UTF8) { - return _createUTF8Generator(EMPTY_WRITE_CONTEXT, - _decorate(out, ctxt), ctxt); + return _createUTF8Generator(EMPTY_WRITE_CONTEXT, ioCtxt, + _decorate(ioCtxt, out)); } - return _createGenerator(EMPTY_WRITE_CONTEXT, - _decorate(_createWriter(out, enc, ctxt), ctxt), ctxt); + return _createGenerator(EMPTY_WRITE_CONTEXT, ioCtxt, + _decorate(ioCtxt, _createWriter(ioCtxt, out, enc))); } @Override @@ -196,20 +196,20 @@ public JsonGenerator createGenerator(ObjectWriteContext writeCtxt, throws IOException { // false -> we won't manage the stream unless explicitly directed to - IOContext ctxt = _createContext(out, false, enc); + IOContext ioCtxt = _createContext(out, false, enc); if (enc == JsonEncoding.UTF8) { - return _createUTF8Generator(writeCtxt, _decorate(out, ctxt), ctxt); + return _createUTF8Generator(writeCtxt, ioCtxt, _decorate(ioCtxt, out)); } - return _createGenerator(writeCtxt, - _decorate(_createWriter(out, enc, ctxt), ctxt), ctxt); + return _createGenerator(writeCtxt, ioCtxt, + _decorate(ioCtxt, _createWriter(ioCtxt, out, enc))); } @Override public JsonGenerator createGenerator(ObjectWriteContext writeCtxt, Writer w) throws IOException { - IOContext ctxt = _createContext(w, false); - return _createGenerator(writeCtxt, _decorate(w, ctxt), ctxt); + IOContext ioCtxt = _createContext(w, false); + return _createGenerator(writeCtxt, ioCtxt, _decorate(ioCtxt, w)); } @Override @@ -218,11 +218,12 @@ public JsonGenerator createGenerator(ObjectWriteContext writeCtxt, throws IOException { OutputStream out = new FileOutputStream(f); - IOContext ctxt = _createContext(f, true, enc); + IOContext ioCtxt = _createContext(f, true, enc); if (enc == JsonEncoding.UTF8) { - return _createUTF8Generator(writeCtxt, _decorate(out, ctxt), ctxt); + return _createUTF8Generator(writeCtxt, ioCtxt, _decorate(ioCtxt, out)); } - return _createGenerator(writeCtxt, _decorate(_createWriter(out, enc, ctxt), ctxt), ctxt); + return _createGenerator(writeCtxt, ioCtxt, + _decorate(ioCtxt, _createWriter(ioCtxt, out, enc))); } /* @@ -242,7 +243,7 @@ public JsonGenerator createGenerator(ObjectWriteContext writeCtxt, * method available to users of factory implementations. */ protected abstract JsonGenerator _createGenerator(ObjectWriteContext writeCtxt, - Writer out, IOContext ioCtxt) throws IOException; + IOContext ioCtxt, Writer out) throws IOException; /** * Overridable factory method that actually instantiates generator for @@ -255,14 +256,14 @@ protected abstract JsonGenerator _createGenerator(ObjectWriteContext writeCtxt, * method available to users of factory implementations. */ protected abstract JsonGenerator _createUTF8Generator(ObjectWriteContext writeCtxt, - OutputStream out, IOContext ctxt) throws IOException; + IOContext ioCtxt, OutputStream out) throws IOException; - protected Writer _createWriter(OutputStream out, JsonEncoding enc, IOContext ctxt) + protected Writer _createWriter(IOContext ioCtxt, OutputStream out, JsonEncoding enc) throws IOException { // note: this should not get called any more (caller checks, dispatches) if (enc == JsonEncoding.UTF8) { // We have optimized writer for UTF-8 - return new UTF8Writer(ctxt, out); + return new UTF8Writer(ioCtxt, out); } // not optimal, but should do unless we really care about UTF-16/32 encoding speed return new OutputStreamWriter(out, enc.getJavaName());