source: josm/trunk/src/javax/json/Json.java@ 10464

Last change on this file since 10464 was 6756, checked in by Don-vip, 11 years ago

fix #9590 - replace org.json with GPL-compliant jsonp + remove mention of old world image removed in r1680

File size: 10.6 KB
Line 
1/*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright (c) 2011-2013 Oracle and/or its affiliates. All rights reserved.
5 *
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common Development
8 * and Distribution License("CDDL") (collectively, the "License"). You
9 * may not use this file except in compliance with the License. You can
10 * obtain a copy of the License at
11 * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
12 * or packager/legal/LICENSE.txt. See the License for the specific
13 * language governing permissions and limitations under the License.
14 *
15 * When distributing the software, include this License Header Notice in each
16 * file and include the License file at packager/legal/LICENSE.txt.
17 *
18 * GPL Classpath Exception:
19 * Oracle designates this particular file as subject to the "Classpath"
20 * exception as provided by Oracle in the GPL Version 2 section of the License
21 * file that accompanied this code.
22 *
23 * Modifications:
24 * If applicable, add the following below the License Header, with the fields
25 * enclosed by brackets [] replaced by your own identifying information:
26 * "Portions Copyright [year] [name of copyright owner]"
27 *
28 * Contributor(s):
29 * If you wish your version of this file to be governed by only the CDDL or
30 * only the GPL Version 2, indicate your decision by adding "[Contributor]
31 * elects to include this software in this distribution under the [CDDL or GPL
32 * Version 2] license." If you don't indicate a single choice of license, a
33 * recipient has the option to distribute your version of this file under
34 * either the CDDL, the GPL Version 2 or to extend the choice of license to
35 * its licensees as provided above. However, if you add GPL Version 2 code
36 * and therefore, elected the GPL Version 2 license, then the option applies
37 * only if the new code is made subject to such option by the copyright
38 * holder.
39 */
40
41package javax.json;
42
43import javax.json.spi.JsonProvider;
44import javax.json.stream.JsonGenerator;
45import javax.json.stream.JsonGeneratorFactory;
46import javax.json.stream.JsonParser;
47import javax.json.stream.JsonParserFactory;
48import java.io.*;
49import java.util.Map;
50
51/**
52 * Factory class for creating JSON processing objects.
53 * This class provides the most commonly used methods for creating these
54 * objects and their corresponding factories. The factory classes provide
55 * all the various ways to create these objects.
56 *
57 * <p>
58 * The methods in this class locate a provider instance using the method
59 * {@link JsonProvider#provider()}. This class uses the provider instance
60 * to create JSON processing objects.
61 *
62 * <p>
63 * The following example shows how to create a JSON parser to parse
64 * an empty array:
65 * <pre>
66 * <code>
67 * StringReader reader = new StringReader("[]");
68 * JsonParser parser = Json.createParser(reader);
69 * </code>
70 * </pre>
71 *
72 * <p>
73 * All the methods in this class are safe for use by multiple concurrent
74 * threads.
75 *
76 * @author Jitendra Kotamraju
77 */
78public class Json {
79
80 private Json() {
81 }
82
83 /**
84 * Creates a JSON parser from a character stream.
85 *
86 * @param reader i/o reader from which JSON is to be read
87 * @return a JSON parser
88 */
89 public static JsonParser createParser(Reader reader) {
90 return JsonProvider.provider().createParser(reader);
91 }
92
93 /**
94 * Creates a JSON parser from a byte stream.
95 * The character encoding of the stream is determined as specified in
96 * <a href="http://tools.ietf.org/rfc/rfc4627.txt">RFC 4627</a>.
97 *
98 * @param in i/o stream from which JSON is to be read
99 * @throws JsonException if encoding cannot be determined
100 * or i/o error (IOException would be cause of JsonException)
101 * @return a JSON parser
102 */
103 public static JsonParser createParser(InputStream in) {
104 return JsonProvider.provider().createParser(in);
105 }
106
107 /**
108 * Creates a JSON generator for writing JSON to a character stream.
109 *
110 * @param writer a i/o writer to which JSON is written
111 * @return a JSON generator
112 */
113 public static JsonGenerator createGenerator(Writer writer) {
114 return JsonProvider.provider().createGenerator(writer);
115 }
116
117 /**
118 * Creates a JSON generator for writing JSON to a byte stream.
119 *
120 * @param out i/o stream to which JSON is written
121 * @return a JSON generator
122 */
123 public static JsonGenerator createGenerator(OutputStream out) {
124 return JsonProvider.provider().createGenerator(out);
125 }
126
127 /**
128 * Creates a parser factory for creating {@link JsonParser} objects.
129 *
130 * @return JSON parser factory.
131 *
132 public static JsonParserFactory createParserFactory() {
133 return JsonProvider.provider().createParserFactory();
134 }
135 */
136
137 /**
138 * Creates a parser factory for creating {@link JsonParser} objects.
139 * The factory is configured with the specified map of provider specific
140 * configuration properties. Provider implementations should ignore any
141 * unsupported configuration properties specified in the map.
142 *
143 * @param config a map of provider specific properties to configure the
144 * JSON parsers. The map may be empty or null
145 * @return JSON parser factory
146 */
147 public static JsonParserFactory createParserFactory(Map<String, ?> config) {
148 return JsonProvider.provider().createParserFactory(config);
149 }
150
151 /**
152 * Creates a generator factory for creating {@link JsonGenerator} objects.
153 *
154 * @return JSON generator factory
155 *
156 public static JsonGeneratorFactory createGeneratorFactory() {
157 return JsonProvider.provider().createGeneratorFactory();
158 }
159 */
160
161 /**
162 * Creates a generator factory for creating {@link JsonGenerator} objects.
163 * The factory is configured with the specified map of provider specific
164 * configuration properties. Provider implementations should ignore any
165 * unsupported configuration properties specified in the map.
166 *
167 * @param config a map of provider specific properties to configure the
168 * JSON generators. The map may be empty or null
169 * @return JSON generator factory
170 */
171 public static JsonGeneratorFactory createGeneratorFactory(
172 Map<String, ?> config) {
173 return JsonProvider.provider().createGeneratorFactory(config);
174 }
175
176 /**
177 * Creates a JSON writer to write a
178 * JSON {@link JsonObject object} or {@link JsonArray array}
179 * structure to the specified character stream.
180 *
181 * @param writer to which JSON object or array is written
182 * @return a JSON writer
183 */
184 public static JsonWriter createWriter(Writer writer) {
185 return JsonProvider.provider().createWriter(writer);
186 }
187
188 /**
189 * Creates a JSON writer to write a
190 * JSON {@link JsonObject object} or {@link JsonArray array}
191 * structure to the specified byte stream. Characters written to
192 * the stream are encoded into bytes using UTF-8 encoding.
193 *
194 * @param out to which JSON object or array is written
195 * @return a JSON writer
196 */
197 public static JsonWriter createWriter(OutputStream out) {
198 return JsonProvider.provider().createWriter(out);
199 }
200
201 /**
202 * Creates a JSON reader from a character stream.
203 *
204 * @param reader a reader from which JSON is to be read
205 * @return a JSON reader
206 */
207 public static JsonReader createReader(Reader reader) {
208 return JsonProvider.provider().createReader(reader);
209 }
210
211 /**
212 * Creates a JSON reader from a byte stream. The character encoding of
213 * the stream is determined as described in
214 * <a href="http://tools.ietf.org/rfc/rfc4627.txt">RFC 4627</a>.
215 *
216 * @param in a byte stream from which JSON is to be read
217 * @return a JSON reader
218 */
219 public static JsonReader createReader(InputStream in) {
220 return JsonProvider.provider().createReader(in);
221 }
222
223 /**
224 * Creates a reader factory for creating {@link JsonReader} objects.
225 * The factory is configured with the specified map of provider specific
226 * configuration properties. Provider implementations should ignore any
227 * unsupported configuration properties specified in the map.
228 *
229 * @param config a map of provider specific properties to configure the
230 * JSON readers. The map may be empty or null
231 * @return a JSON reader factory
232 */
233 public static JsonReaderFactory createReaderFactory(Map<String, ?> config) {
234 return JsonProvider.provider().createReaderFactory(config);
235 }
236
237 /**
238 * Creates a writer factory for creating {@link JsonWriter} objects.
239 * The factory is configured with the specified map of provider specific
240 * configuration properties. Provider implementations should ignore any
241 * unsupported configuration properties specified in the map.
242 *
243 * @param config a map of provider specific properties to configure the
244 * JSON writers. The map may be empty or null
245 * @return a JSON writer factory
246 */
247 public static JsonWriterFactory createWriterFactory(Map<String, ?> config) {
248 return JsonProvider.provider().createWriterFactory(config);
249 }
250
251 /**
252 * Creates a JSON array builder
253 *
254 * @return a JSON array builder
255 */
256 public static JsonArrayBuilder createArrayBuilder() {
257 return JsonProvider.provider().createArrayBuilder();
258 }
259
260 /**
261 * Creates a JSON object builder
262 *
263 * @return a JSON object builder
264 */
265 public static JsonObjectBuilder createObjectBuilder() {
266 return JsonProvider.provider().createObjectBuilder();
267 }
268
269 /**
270 * Creates a builder factory for creating {@link JsonArrayBuilder}
271 * and {@link JsonObjectBuilder} objects.
272 * The factory is configured with the specified map of provider specific
273 * configuration properties. Provider implementations should ignore any
274 * unsupported configuration properties specified in the map.
275 *
276 * @param config a map of provider specific properties to configure the
277 * JSON builders. The map may be empty or null
278 * @return a JSON builder factory
279 */
280 public static JsonBuilderFactory createBuilderFactory(
281 Map<String, ?> config) {
282 return JsonProvider.provider().createBuilderFactory(config);
283 }
284
285}
Note: See TracBrowser for help on using the repository browser.