Skip to content

Commit

Permalink
yet more refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 6, 2017
1 parent 38bbcdd commit ae990d4
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 72 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/fasterxml/jackson/core/JsonFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/com/fasterxml/jackson/core/base/BinaryTSFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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));
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,32 +105,32 @@ 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;
}
}
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;
}
}
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;
}
Expand All @@ -144,21 +144,21 @@ 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;
}
}
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;
}
Expand Down
89 changes: 45 additions & 44 deletions src/main/java/com/fasterxml/jackson/core/base/TextualTSFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -159,35 +159,35 @@ 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
public JsonGenerator createGenerator(File f, JsonEncoding enc) throws IOException
{
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
Expand All @@ -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
Expand All @@ -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)));
}

/*
Expand All @@ -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
Expand All @@ -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());
Expand Down

0 comments on commit ae990d4

Please sign in to comment.