1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.johnzon.core; |
20 | |
|
21 | |
import java.io.InputStream; |
22 | |
import java.io.Reader; |
23 | |
import java.io.Serializable; |
24 | |
import java.nio.charset.Charset; |
25 | |
import java.util.Collections; |
26 | |
import java.util.HashMap; |
27 | |
import java.util.Map; |
28 | |
|
29 | |
import javax.json.JsonReader; |
30 | |
import javax.json.JsonReaderFactory; |
31 | |
|
32 | |
class JsonReaderFactoryImpl implements JsonReaderFactory, Serializable { |
33 | 45 | private final Map<String, Object> internalConfig = new HashMap<String, Object>(); |
34 | 1 | private static final String[] SUPPORTED_CONFIG_KEYS = new String[] { |
35 | |
JsonParserFactoryImpl.BUFFER_STRATEGY, JsonParserFactoryImpl.MAX_STRING_LENGTH, JsonParserFactoryImpl.BUFFER_LENGTH |
36 | |
}; |
37 | |
private final JsonParserFactoryImpl parserFactory; |
38 | |
|
39 | 45 | JsonReaderFactoryImpl(final Map<String, ?> config) { |
40 | |
|
41 | 45 | if(config != null) { |
42 | |
|
43 | 176 | for (String configKey : SUPPORTED_CONFIG_KEYS) { |
44 | 132 | if(config.containsKey(configKey)) { |
45 | 44 | internalConfig.put(configKey, config.get(configKey)); |
46 | |
} |
47 | |
} |
48 | |
|
49 | 44 | this.parserFactory = new JsonParserFactoryImpl(internalConfig); |
50 | |
|
51 | |
} else { |
52 | 1 | this.parserFactory = new JsonParserFactoryImpl(null); |
53 | |
} |
54 | |
|
55 | 44 | } |
56 | |
|
57 | |
@Override |
58 | |
public JsonReader createReader(final Reader reader) { |
59 | 7 | return new JsonReaderImpl(parserFactory.createInternalParser(reader)); |
60 | |
} |
61 | |
|
62 | |
@Override |
63 | |
public JsonReader createReader(final InputStream in) { |
64 | 84 | return new JsonReaderImpl(parserFactory.createInternalParser(in)); |
65 | |
} |
66 | |
|
67 | |
@Override |
68 | |
public JsonReader createReader(final InputStream in, final Charset charset) { |
69 | 54 | return new JsonReaderImpl(parserFactory.createInternalParser(in, charset)); |
70 | |
} |
71 | |
|
72 | |
@Override |
73 | |
public Map<String, ?> getConfigInUse() { |
74 | 0 | return Collections.unmodifiableMap(internalConfig); |
75 | |
} |
76 | |
} |