Skip to content

Commit 007dccb

Browse files
committed
...
1 parent e15b9a8 commit 007dccb

File tree

4 files changed

+80
-156
lines changed

4 files changed

+80
-156
lines changed

src/main/java/com/fasterxml/jackson/core/json/ByteSourceJsonBootstrapper.java

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ public final class ByteSourceJsonBootstrapper
8181
/**********************************************************
8282
*/
8383

84-
public ByteSourceJsonBootstrapper(IOContext ctxt, InputStream in)
85-
{
84+
public ByteSourceJsonBootstrapper(IOContext ctxt, InputStream in) {
8685
_context = ctxt;
8786
_in = in;
8887
_inputBuffer = ctxt.allocReadIOBuffer();
@@ -91,8 +90,7 @@ public ByteSourceJsonBootstrapper(IOContext ctxt, InputStream in)
9190
_bufferRecyclable = true;
9291
}
9392

94-
public ByteSourceJsonBootstrapper(IOContext ctxt, byte[] inputBuffer, int inputStart, int inputLen)
95-
{
93+
public ByteSourceJsonBootstrapper(IOContext ctxt, byte[] inputBuffer, int inputStart, int inputLen) {
9694
_context = ctxt;
9795
_in = null;
9896
_inputBuffer = inputBuffer;
@@ -114,8 +112,7 @@ public ByteSourceJsonBootstrapper(IOContext ctxt, byte[] inputBuffer, int inputS
114112
* It will figure out encoding that content uses, to allow
115113
* for instantiating a proper scanner object.
116114
*/
117-
public JsonEncoding detectEncoding()
118-
throws IOException, JsonParseException
115+
public JsonEncoding detectEncoding() throws IOException
119116
{
120117
boolean foundEncoding = false;
121118

@@ -162,17 +159,13 @@ public JsonEncoding detectEncoding()
162159
enc = JsonEncoding.UTF8;
163160
} else {
164161
switch (_bytesPerChar) {
165-
case 1:
166-
enc = JsonEncoding.UTF8;
162+
case 1: enc = JsonEncoding.UTF8;
167163
break;
168-
case 2:
169-
enc = _bigEndian ? JsonEncoding.UTF16_BE : JsonEncoding.UTF16_LE;
164+
case 2: enc = _bigEndian ? JsonEncoding.UTF16_BE : JsonEncoding.UTF16_LE;
170165
break;
171-
case 4:
172-
enc = _bigEndian ? JsonEncoding.UTF32_BE : JsonEncoding.UTF32_LE;
166+
case 4: enc = _bigEndian ? JsonEncoding.UTF32_BE : JsonEncoding.UTF32_LE;
173167
break;
174-
default:
175-
throw new RuntimeException("Internal error"); // should never get here
168+
default: throw new RuntimeException("Internal error"); // should never get here
176169
}
177170
}
178171
_context.setEncoding(enc);
@@ -186,8 +179,7 @@ public JsonEncoding detectEncoding()
186179
*/
187180

188181
@SuppressWarnings("resource")
189-
public Reader constructReader()
190-
throws IOException
182+
public Reader constructReader() throws IOException
191183
{
192184
JsonEncoding enc = _context.getEncoding();
193185
switch (enc.bits()) {
@@ -218,8 +210,7 @@ public Reader constructReader()
218210

219211
public JsonParser constructParser(int parserFeatures, ObjectCodec codec,
220212
BytesToNameCanonicalizer rootByteSymbols, CharsToNameCanonicalizer rootCharSymbols,
221-
boolean canonicalize, boolean intern)
222-
throws IOException
213+
boolean canonicalize, boolean intern) throws IOException
223214
{
224215
JsonEncoding enc = detectEncoding();
225216

@@ -384,8 +375,7 @@ private static int skipSpace(InputAccessor acc, byte b) throws IOException
384375
* @return True if a BOM was succesfully found, and encoding
385376
* thereby recognized.
386377
*/
387-
private boolean handleBOM(int quad)
388-
throws IOException
378+
private boolean handleBOM(int quad) throws IOException
389379
{
390380
/* Handling of (usually) optional BOM (required for
391381
* multi-byte formats); first 32-bit charsets:
@@ -430,8 +420,7 @@ private boolean handleBOM(int quad)
430420
return false;
431421
}
432422

433-
private boolean checkUTF32(int quad)
434-
throws IOException
423+
private boolean checkUTF32(int quad) throws IOException
435424
{
436425
/* Handling of (usually) optional BOM (required for
437426
* multi-byte formats); first 32-bit charsets:
@@ -475,9 +464,7 @@ private boolean checkUTF16(int i16)
475464
/**********************************************************
476465
*/
477466

478-
private void reportWeirdUCS4(String type)
479-
throws IOException
480-
{
467+
private void reportWeirdUCS4(String type) throws IOException {
481468
throw new CharConversionException("Unsupported UCS-4 endianness ("+type+") detected");
482469
}
483470

@@ -487,9 +474,7 @@ private void reportWeirdUCS4(String type)
487474
/**********************************************************
488475
*/
489476

490-
protected boolean ensureLoaded(int minimum)
491-
throws IOException
492-
{
477+
protected boolean ensureLoaded(int minimum) throws IOException {
493478
/* Let's assume here buffer has enough room -- this will always
494479
* be true for the limited used this method gets
495480
*/

src/main/java/com/fasterxml/jackson/core/json/JsonReadContext.java

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
* core methods needed, and also exposes
99
* more complete API to parser implementation classes.
1010
*/
11-
public final class JsonReadContext
12-
extends JsonStreamContext
11+
public final class JsonReadContext extends JsonStreamContext
1312
{
1413
// // // Configuration
1514

@@ -46,9 +45,7 @@ public final class JsonReadContext
4645
/**********************************************************
4746
*/
4847

49-
public JsonReadContext(JsonReadContext parent, DupDetector dups,
50-
int type, int lineNr, int colNr)
51-
{
48+
public JsonReadContext(JsonReadContext parent, DupDetector dups, int type, int lineNr, int colNr) {
5249
super();
5350
_parent = parent;
5451
_dups = dups;
@@ -58,8 +55,7 @@ public JsonReadContext(JsonReadContext parent, DupDetector dups,
5855
_index = -1;
5956
}
6057

61-
protected void reset(int type, int lineNr, int colNr)
62-
{
58+
protected void reset(int type, int lineNr, int colNr) {
6359
_type = type;
6460
_index = -1;
6561
_lineNr = lineNr;
@@ -83,9 +79,7 @@ public static JsonReadContext createRootContext(int lineNr, int colNr) {
8379
return createRootContext(lineNr, colNr, null);
8480
}
8581

86-
public static JsonReadContext createRootContext(int lineNr, int colNr,
87-
DupDetector dups)
88-
{
82+
public static JsonReadContext createRootContext(int lineNr, int colNr, DupDetector dups) {
8983
return new JsonReadContext(null, dups, TYPE_ROOT, lineNr, colNr);
9084
}
9185

@@ -98,26 +92,22 @@ public static JsonReadContext createRootContext(DupDetector dups) {
9892
return new JsonReadContext(null, dups, TYPE_ROOT, 1, 0);
9993
}
10094

101-
public JsonReadContext createChildArrayContext(int lineNr, int colNr)
102-
{
95+
public JsonReadContext createChildArrayContext(int lineNr, int colNr) {
10396
JsonReadContext ctxt = _child;
10497
if (ctxt == null) {
10598
_child = ctxt = new JsonReadContext(this,
106-
(_dups == null) ? null : _dups.child(),
107-
TYPE_ARRAY, lineNr, colNr);
99+
(_dups == null) ? null : _dups.child(), TYPE_ARRAY, lineNr, colNr);
108100
} else {
109101
ctxt.reset(TYPE_ARRAY, lineNr, colNr);
110102
}
111103
return ctxt;
112104
}
113105

114-
public JsonReadContext createChildObjectContext(int lineNr, int colNr)
115-
{
106+
public JsonReadContext createChildObjectContext(int lineNr, int colNr) {
116107
JsonReadContext ctxt = _child;
117108
if (ctxt == null) {
118109
_child = ctxt = new JsonReadContext(this,
119-
(_dups == null) ? null : _dups.child(),
120-
TYPE_OBJECT, lineNr, colNr);
110+
(_dups == null) ? null : _dups.child(), TYPE_OBJECT, lineNr, colNr);
121111
return ctxt;
122112
}
123113
ctxt.reset(TYPE_OBJECT, lineNr, colNr);
@@ -130,11 +120,8 @@ public JsonReadContext createChildObjectContext(int lineNr, int colNr)
130120
/**********************************************************
131121
*/
132122

133-
@Override
134-
public String getCurrentName() { return _currentName; }
135-
136-
@Override
137-
public JsonReadContext getParent() { return _parent; }
123+
@Override public String getCurrentName() { return _currentName; }
124+
@Override public JsonReadContext getParent() { return _parent; }
138125

139126
/*
140127
/**********************************************************
@@ -146,13 +133,9 @@ public JsonReadContext createChildObjectContext(int lineNr, int colNr)
146133
* @return Location pointing to the point where the context
147134
* start marker was found
148135
*/
149-
public JsonLocation getStartLocation(Object srcRef)
150-
{
151-
/* We don't keep track of offsets at this level (only
152-
* reader does)
153-
*/
136+
public JsonLocation getStartLocation(Object srcRef) {
137+
// We don't keep track of offsets at this level (only reader does)
154138
long totalChars = -1L;
155-
156139
return new JsonLocation(srcRef, totalChars, _lineNr, _columnNr);
157140
}
158141

@@ -162,8 +145,7 @@ public JsonLocation getStartLocation(Object srcRef)
162145
/**********************************************************
163146
*/
164147

165-
public boolean expectComma()
166-
{
148+
public boolean expectComma() {
167149
/* Assumption here is that we will be getting a value (at least
168150
* before calling this method again), and
169151
* so will auto-increment index to avoid having to do another call
@@ -172,16 +154,12 @@ public boolean expectComma()
172154
return (_type != TYPE_ROOT && ix > 0);
173155
}
174156

175-
public void setCurrentName(String name) throws JsonProcessingException
176-
{
157+
public void setCurrentName(String name) throws JsonProcessingException {
177158
_currentName = name;
178-
if (_dups != null) {
179-
_checkDup(_dups, name);
180-
}
159+
if (_dups != null) { _checkDup(_dups, name); }
181160
}
182161

183-
private void _checkDup(DupDetector dd, String name) throws JsonProcessingException
184-
{
162+
private void _checkDup(DupDetector dd, String name) throws JsonProcessingException {
185163
if (dd.isDup(name)) {
186164
throw new JsonParseException("Duplicate field '"+name+"'", dd.findLocation());
187165
}
@@ -198,8 +176,7 @@ private void _checkDup(DupDetector dd, String name) throws JsonProcessingExcepti
198176
* of the context.
199177
*/
200178
@Override
201-
public String toString()
202-
{
179+
public String toString() {
203180
StringBuilder sb = new StringBuilder(64);
204181
switch (_type) {
205182
case TYPE_ROOT:

src/main/java/com/fasterxml/jackson/core/json/JsonWriteContext.java

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
* core methods needed, and also exposes
88
* more complete API to generator implementation classes.
99
*/
10-
public class JsonWriteContext
11-
extends JsonStreamContext
10+
public class JsonWriteContext extends JsonStreamContext
1211
{
1312
// // // Return values for writeValue()
1413

@@ -56,9 +55,7 @@ public class JsonWriteContext
5655
/**********************************************************
5756
*/
5857

59-
protected JsonWriteContext(int type, JsonWriteContext parent,
60-
DupDetector dups)
61-
{
58+
protected JsonWriteContext(int type, JsonWriteContext parent, DupDetector dups) {
6259
super();
6360
_type = type;
6461
_parent = parent;
@@ -71,9 +68,7 @@ protected JsonWriteContext reset(int type) {
7168
_index = -1;
7269
_currentName = null;
7370
_gotName = false;
74-
if (_dups != null) {
75-
_dups.reset();
76-
}
71+
if (_dups != null) { _dups.reset(); }
7772
return this;
7873
}
7974

@@ -83,43 +78,32 @@ protected JsonWriteContext reset(int type) {
8378
* @deprecated Since 2.3; use method that takes argument
8479
*/
8580
@Deprecated
86-
public static JsonWriteContext createRootContext() {
87-
return createRootContext(null);
88-
}
81+
public static JsonWriteContext createRootContext() { return createRootContext(null); }
8982

90-
public static JsonWriteContext createRootContext(DupDetector dd) {
91-
return new JsonWriteContext(TYPE_ROOT, null, dd);
92-
}
83+
public static JsonWriteContext createRootContext(DupDetector dd) { return new JsonWriteContext(TYPE_ROOT, null, dd); }
9384

94-
public JsonWriteContext createChildArrayContext()
95-
{
85+
public JsonWriteContext createChildArrayContext() {
9686
JsonWriteContext ctxt = _child;
9787
if (ctxt == null) {
98-
_child = ctxt = new JsonWriteContext(TYPE_ARRAY, this,
99-
(_dups == null) ? null : _dups.child());
88+
_child = ctxt = new JsonWriteContext(TYPE_ARRAY, this, (_dups == null) ? null : _dups.child());
10089
return ctxt;
10190
}
10291
return ctxt.reset(TYPE_ARRAY);
10392
}
10493

105-
public JsonWriteContext createChildObjectContext()
106-
{
94+
public JsonWriteContext createChildObjectContext() {
10795
JsonWriteContext ctxt = _child;
10896
if (ctxt == null) {
109-
_child = ctxt = new JsonWriteContext(TYPE_OBJECT, this,
110-
(_dups == null) ? null : _dups.child());
97+
_child = ctxt = new JsonWriteContext(TYPE_OBJECT, this, (_dups == null) ? null : _dups.child());
11198
return ctxt;
11299
}
113100
return ctxt.reset(TYPE_OBJECT);
114101
}
115102

116103
// // // Shared API
117104

118-
@Override
119-
public final JsonWriteContext getParent() { return _parent; }
120-
121-
@Override
122-
public final String getCurrentName() { return _currentName; }
105+
@Override public final JsonWriteContext getParent() { return _parent; }
106+
@Override public final String getCurrentName() { return _currentName; }
123107

124108
// // // API sub-classes are to implement
125109

@@ -128,25 +112,18 @@ public JsonWriteContext createChildObjectContext()
128112
*
129113
* @return Index of the field entry (0-based)
130114
*/
131-
public final int writeFieldName(String name) throws JsonProcessingException
132-
{
115+
public final int writeFieldName(String name) throws JsonProcessingException {
133116
_gotName = true;
134117
_currentName = name;
135-
if (_dups != null) {
136-
_checkDup(_dups, name);
137-
}
118+
if (_dups != null) { _checkDup(_dups, name); }
138119
return (_index < 0) ? STATUS_OK_AS_IS : STATUS_OK_AFTER_COMMA;
139120
}
140121

141-
private void _checkDup(DupDetector dd, String name) throws JsonProcessingException
142-
{
143-
if (dd.isDup(name)) {
144-
throw new JsonGenerationException("Duplicate field '"+name+"'");
145-
}
122+
private void _checkDup(DupDetector dd, String name) throws JsonProcessingException {
123+
if (dd.isDup(name)) { throw new JsonGenerationException("Duplicate field '"+name+"'"); }
146124
}
147125

148-
public final int writeValue()
149-
{
126+
public final int writeValue() {
150127
// Most likely, object:
151128
if (_type == TYPE_OBJECT) {
152129
_gotName = false;
@@ -169,8 +146,7 @@ public final int writeValue()
169146

170147
// // // Internally used abstract methods
171148

172-
protected final void appendDesc(StringBuilder sb)
173-
{
149+
protected final void appendDesc(StringBuilder sb) {
174150
if (_type == TYPE_OBJECT) {
175151
sb.append('{');
176152
if (_currentName != null) {
@@ -198,9 +174,7 @@ protected final void appendDesc(StringBuilder sb)
198174
* Overridden to provide developer writeable "JsonPath" representation
199175
* of the context.
200176
*/
201-
@Override
202-
public final String toString()
203-
{
177+
@Override public final String toString() {
204178
StringBuilder sb = new StringBuilder(64);
205179
appendDesc(sb);
206180
return sb.toString();

0 commit comments

Comments
 (0)