Skip to content

Commit 7403cdd

Browse files
committed
Start work on #433
1 parent 4694a80 commit 7403cdd

File tree

93 files changed

+430
-30
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+430
-30
lines changed

src/main/java/com/fasterxml/jackson/core/JsonGenerator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import com.fasterxml.jackson.core.JsonParser.NumberType;
1212
import com.fasterxml.jackson.core.io.CharacterEscapes;
13+
import com.fasterxml.jackson.core.json.JsonFactory;
1314
import com.fasterxml.jackson.core.type.WritableTypeId;
1415
import com.fasterxml.jackson.core.type.WritableTypeId.Inclusion;
1516
import com.fasterxml.jackson.core.util.VersionUtil;

src/main/java/com/fasterxml/jackson/core/JsonParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.math.BigInteger;
1111

1212
import com.fasterxml.jackson.core.async.NonBlockingInputFeeder;
13+
import com.fasterxml.jackson.core.json.JsonFactory;
1314
import com.fasterxml.jackson.core.sym.FieldNameMatcher;
1415
import com.fasterxml.jackson.core.type.ResolvedType;
1516
import com.fasterxml.jackson.core.type.TypeReference;
@@ -524,7 +525,7 @@ public NonBlockingInputFeeder getNonBlockingInputFeeder() {
524525
* {@link Feature#AUTO_CLOSE_SOURCE} is enabled.
525526
* Whether parser owns the input source depends on factory
526527
* method that was used to construct instance (so check
527-
* {@link com.fasterxml.jackson.core.JsonFactory} for details,
528+
* {@link com.fasterxml.jackson.core.json.JsonFactory} for details,
528529
* but the general
529530
* idea is that if caller passes in closable resource (such
530531
* as {@link InputStream} or {@link Reader}) parser does NOT

src/main/java/com/fasterxml/jackson/core/TokenStreamFactory.java

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.List;
1111

1212
import com.fasterxml.jackson.core.io.*;
13+
import com.fasterxml.jackson.core.json.JsonFactory;
1314
import com.fasterxml.jackson.core.sym.FieldNameMatcher;
1415
import com.fasterxml.jackson.core.sym.SimpleNameMatcher;
1516
import com.fasterxml.jackson.core.util.BufferRecycler;
@@ -137,6 +138,139 @@ public static int collectDefaults() {
137138
public int getMask() { return (1 << ordinal()); }
138139
}
139140

141+
/**
142+
* Since factory instances are immutable, a Builder class is needed for creating
143+
* configurations for differently configured factory instances.
144+
*
145+
* @since 3.0
146+
*/
147+
public abstract static class TSFBuilder<F extends TokenStreamFactory,
148+
T extends TSFBuilder<F,T>>
149+
{
150+
/**
151+
* Set of {@link TokenStreamFactory.Feature}s enabled, as bitmask.
152+
*/
153+
protected int _factoryFeatures;
154+
155+
/**
156+
* Set of {@link JsonParser.Feature}s enabled, as bitmask.
157+
*/
158+
protected int _parserFeatures;
159+
160+
/**
161+
* Set of {@link JsonGenerator.Feature}s enabled, as bitmask.
162+
*/
163+
protected int _generatorFeatures;
164+
165+
// // // Construction
166+
167+
protected TSFBuilder() {
168+
_factoryFeatures = DEFAULT_FACTORY_FEATURE_FLAGS;
169+
_parserFeatures = DEFAULT_PARSER_FEATURE_FLAGS;
170+
_generatorFeatures = DEFAULT_GENERATOR_FEATURE_FLAGS;
171+
}
172+
173+
protected TSFBuilder(TokenStreamFactory base)
174+
{
175+
this(base._factoryFeatures,
176+
base.getParserFeatures(), base.getGeneratorFeatures());
177+
}
178+
179+
protected TSFBuilder(int factoryFeatures,
180+
int parserFeatures, int generatorFeatures)
181+
{
182+
_factoryFeatures = factoryFeatures;
183+
_parserFeatures = parserFeatures;
184+
_generatorFeatures = generatorFeatures;
185+
}
186+
187+
// // // Accessors
188+
189+
public int factoryFeaturesMask() { return _factoryFeatures; }
190+
public int parserFeaturesMask() { return _parserFeatures; }
191+
public int generatorFeaturesMask() { return _generatorFeatures; }
192+
193+
// // // Factory features
194+
195+
public T with(TokenStreamFactory.Feature f) {
196+
_factoryFeatures |= f.getMask();
197+
return _this();
198+
}
199+
200+
public T without(TokenStreamFactory.Feature f) {
201+
_factoryFeatures &= ~f.getMask();
202+
return _this();
203+
}
204+
205+
// // // Parser features
206+
207+
public T with(JsonParser.Feature f) {
208+
_parserFeatures |= f.getMask();
209+
return _this();
210+
}
211+
212+
public T with(JsonParser.Feature first, JsonParser.Feature... other) {
213+
_parserFeatures |= first.getMask();
214+
for (JsonParser.Feature f : other) {
215+
_parserFeatures |= f.getMask();
216+
}
217+
return _this();
218+
}
219+
220+
public T without(JsonParser.Feature f) {
221+
_parserFeatures &= ~f.getMask();
222+
return _this();
223+
}
224+
225+
public T without(JsonParser.Feature first, JsonParser.Feature... other) {
226+
_parserFeatures &= ~first.getMask();
227+
for (JsonParser.Feature f : other) {
228+
_parserFeatures &= ~f.getMask();
229+
}
230+
return _this();
231+
}
232+
233+
// // // Generator features
234+
235+
public T with(JsonGenerator.Feature f) {
236+
_generatorFeatures |= f.getMask();
237+
return _this();
238+
}
239+
240+
public T with(JsonGenerator.Feature first, JsonGenerator.Feature... other) {
241+
_generatorFeatures |= first.getMask();
242+
for (JsonGenerator.Feature f : other) {
243+
_parserFeatures |= f.getMask();
244+
}
245+
return _this();
246+
}
247+
248+
public T without(JsonGenerator.Feature f) {
249+
_generatorFeatures &= ~f.getMask();
250+
return _this();
251+
}
252+
253+
public T without(JsonGenerator.Feature first, JsonGenerator.Feature... other) {
254+
_generatorFeatures &= ~first.getMask();
255+
for (JsonGenerator.Feature f : other) {
256+
_generatorFeatures &= ~f.getMask();
257+
}
258+
return _this();
259+
}
260+
261+
// // // Other methods
262+
263+
/**
264+
* Method for constructing actual {@link TokenStreamFactory} instance, given
265+
* configuration.
266+
*/
267+
protected abstract F build();
268+
269+
// silly convenience cast method we need
270+
@SuppressWarnings("unchecked")
271+
protected final T _this() { return (T) this; }
272+
}
273+
140274
/*
141275
/**********************************************************
142276
/* Constants
@@ -199,6 +333,22 @@ public static int collectDefaults() {
199333
*/
200334
public TokenStreamFactory() { }
201335

336+
/**
337+
* Constructors used by {@link TSFBuilder} for instantiation. Base builder is
338+
* passed as-is to try to make interface between base types and implementations
339+
* less likely to change (given that sub-classing is a fragile way to do it):
340+
* if and when new general-purpose properties are added, implementation classes
341+
* do not have to use different constructors.
342+
*
343+
* @since 3.0
344+
*/
345+
protected TokenStreamFactory(TSFBuilder<?,?> baseBuilder)
346+
{
347+
_factoryFeatures = baseBuilder.factoryFeaturesMask();
348+
_parserFeatures = baseBuilder.parserFeaturesMask();
349+
_generatorFeatures = baseBuilder.generatorFeaturesMask();
350+
}
351+
202352
/**
203353
* Constructor used when copy()ing a factory instance.
204354
*/
@@ -217,6 +367,14 @@ protected TokenStreamFactory(TokenStreamFactory src)
217367
*/
218368
public abstract TokenStreamFactory copy();
219369

370+
/**
371+
* Method that can be used to create differently configured stream factories.
372+
*
373+
* @since 3.0
374+
*/
375+
public abstract TSFBuilder<?,?> rebuild();
376+
// public abstract <F extends TokenStreamFactory, T extends TSFBuilder<F,T>> TSFBuilder<F,T> rebuild();
377+
220378
/*
221379
/**********************************************************
222380
/* Capability introspection
@@ -600,46 +758,73 @@ public abstract JsonParser createParser(ObjectReadContext readCtxt,
600758
/**********************************************************
601759
*/
602760

761+
/**
762+
* @deprecated Since 3.0 use {@link #createParser(ObjectReadContext,java.io.File)}
763+
*/
603764
@Deprecated
604765
public JsonParser createParser(File src) throws IOException {
605766
return createParser(ObjectReadContext.empty(), src);
606767
}
607768

769+
/**
770+
* @deprecated Since 3.0 use {@link #createParser(ObjectReadContext,java.net.URL)}
771+
*/
608772
@Deprecated
609773
public JsonParser createParser(URL src) throws IOException {
610774
return createParser(ObjectReadContext.empty(), src);
611775
}
612776

777+
/**
778+
* @deprecated Since 3.0 use {@link #createParser(ObjectReadContext,java.io.InputStream)}
779+
*/
613780
@Deprecated
614781
public JsonParser createParser(InputStream in) throws IOException {
615782
return createParser(ObjectReadContext.empty(), in);
616783
}
617784

785+
/**
786+
* @deprecated Since 3.0 use {@link #createParser(ObjectReadContext,java.io.Reader)}
787+
*/
618788
@Deprecated
619789
public JsonParser createParser(Reader r) throws IOException {
620790
return createParser(ObjectReadContext.empty(), r);
621791
}
622792

793+
/**
794+
* @deprecated Since 3.0 use {@link #createParser(ObjectReadContext,byte[])}
795+
*/
623796
@Deprecated
624797
public JsonParser createParser(byte[] data) throws IOException {
625798
return createParser(ObjectReadContext.empty(), data, 0, data.length);
626799
}
627800

801+
/**
802+
* @deprecated Since 3.0 use {@link #createParser(ObjectReadContext,byte[],int,int)}
803+
*/
628804
@Deprecated
629805
public JsonParser createParser(byte[] data, int offset, int len) throws IOException {
630806
return createParser(ObjectReadContext.empty(), data, offset, len);
631807
}
632808

809+
/**
810+
* @deprecated Since 3.0 use {@link #createParser(ObjectReadContext,String)}
811+
*/
633812
@Deprecated
634813
public JsonParser createParser(String content) throws IOException {
635814
return createParser(ObjectReadContext.empty(), content);
636815
}
637816

817+
/**
818+
* @deprecated Since 3.0 use {@link #createParser(ObjectReadContext,char[])}
819+
*/
638820
@Deprecated
639821
public JsonParser createParser(char[] content) throws IOException {
640822
return createParser(ObjectReadContext.empty(), content, 0, content.length);
641823
}
642824

825+
/**
826+
* @deprecated Since 3.0 use {@link #createParser(ObjectReadContext,char[],int,int)}
827+
*/
643828
@Deprecated
644829
public JsonParser createParser(char[] content, int offset, int len) throws IOException {
645830
return createParser(ObjectReadContext.empty(), content, offset, len);

src/main/java/com/fasterxml/jackson/core/async/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Package that contains abstractions needed to support optional
33
* non-blocking decoding (parsing) functionality.
44
* Although parsers are constructed normally via
5-
* {@link com.fasterxml.jackson.core.JsonFactory}
5+
* {@link com.fasterxml.jackson.core.json.JsonFactory}
66
* (and are, in fact, sub-types of {@link com.fasterxml.jackson.core.JsonParser}),
77
* the way input is provided differs.
88
*

src/main/java/com/fasterxml/jackson/core/base/BinaryTSFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ public abstract class BinaryTSFactory extends DecorableTSFactory
2121

2222
protected BinaryTSFactory() { super(); }
2323

24+
/**
25+
* Constructors used by builders for instantiation.
26+
*
27+
* @since 3.0
28+
*/
29+
protected BinaryTSFactory(DecorableTSFBuilder<?,?> baseBuilder)
30+
{
31+
super(baseBuilder);
32+
}
33+
2434
/**
2535
* Constructor used when copy()ing a factory instance.
2636
*/

0 commit comments

Comments
 (0)