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.Collection; |
26 | |
import java.util.Collections; |
27 | |
import java.util.HashMap; |
28 | |
import java.util.Map; |
29 | |
import java.util.logging.Logger; |
30 | |
|
31 | |
import javax.json.JsonReader; |
32 | |
import javax.json.JsonReaderFactory; |
33 | |
|
34 | |
import static java.util.Arrays.asList; |
35 | |
|
36 | |
class JsonReaderFactoryImpl implements JsonReaderFactory, Serializable { |
37 | 1 | private static final Logger LOGGER = Logger.getLogger(JsonReaderFactoryImpl.class.getName()); |
38 | |
|
39 | 46 | private final Map<String, Object> internalConfig = new HashMap<String, Object>(); |
40 | 1 | private static final Collection<String> SUPPORTED_CONFIG_KEYS = asList( |
41 | |
JsonParserFactoryImpl.BUFFER_STRATEGY, JsonParserFactoryImpl.MAX_STRING_LENGTH, |
42 | |
JsonParserFactoryImpl.BUFFER_LENGTH, JsonParserFactoryImpl.SUPPORTS_COMMENTS |
43 | |
); |
44 | |
private final JsonParserFactoryImpl parserFactory; |
45 | |
|
46 | 46 | JsonReaderFactoryImpl(final Map<String, ?> config) { |
47 | |
|
48 | 46 | if(config != null) { |
49 | |
|
50 | 45 | for (String configKey : config.keySet()) { |
51 | 45 | if(SUPPORTED_CONFIG_KEYS.contains(configKey)) { |
52 | 45 | internalConfig.put(configKey, config.get(configKey)); |
53 | |
} else { |
54 | 0 | LOGGER.warning(configKey + " not supported by " + getClass().getName()); |
55 | |
} |
56 | 45 | } |
57 | |
|
58 | 45 | this.parserFactory = new JsonParserFactoryImpl(internalConfig); |
59 | |
|
60 | |
} else { |
61 | 1 | this.parserFactory = new JsonParserFactoryImpl(null); |
62 | |
} |
63 | |
|
64 | 45 | } |
65 | |
|
66 | |
@Override |
67 | |
public JsonReader createReader(final Reader reader) { |
68 | 7 | return new JsonReaderImpl(parserFactory.createInternalParser(reader)); |
69 | |
} |
70 | |
|
71 | |
@Override |
72 | |
public JsonReader createReader(final InputStream in) { |
73 | 85 | return new JsonReaderImpl(parserFactory.createInternalParser(in)); |
74 | |
} |
75 | |
|
76 | |
@Override |
77 | |
public JsonReader createReader(final InputStream in, final Charset charset) { |
78 | 54 | return new JsonReaderImpl(parserFactory.createInternalParser(in, charset)); |
79 | |
} |
80 | |
|
81 | |
@Override |
82 | |
public Map<String, ?> getConfigInUse() { |
83 | 0 | return Collections.unmodifiableMap(internalConfig); |
84 | |
} |
85 | |
} |