Debian Codegraph @

src/jakarta/json/stream/JsonGeneratorFactory.java

raw symbols SCIP
1 /*
2 * Copyright (c) 2011, 2021 Oracle and/or its affiliates. All rights reserved.
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v. 2.0, which is available at
6 * http://www.eclipse.org/legal/epl-2.0.
7 *
8 * This Source Code may also be made available under the following Secondary
9 * Licenses when the conditions for such availability set forth in the
10 * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11 * version 2 with the GNU Classpath Exception, which is available at
12 * https://www.gnu.org/software/classpath/license.html.
13 *
14 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15 */
16
17 package jakarta.json.stream;
18
19 import java.io.OutputStream;
20 import java.io.Writer;
21 import java.nio.charset.Charset;
22 import java.util.Map;
23
24 /**
25 * Factory to create {@link JsonGenerator} instances. If a factory
26 * instance is configured with some configuration, the configuration applies
27 * to all generator instances created using that factory instance.
28 *
29 * <p>
30 * The class {@link jakarta.json.Json Json} also provides methods to create
31 * {@link JsonGenerator} instances, but using {@code JsonGeneratorFactory} is
32 * preferred when creating multiple generator instances as shown in the
33 * following example:
34 *
35 * <pre>
36 * <code>
37 * JsonGeneratorFactory factory = Json.createGeneratorFactory();
38 * JsonGenerator generator1 = factory.createGenerator(...);
39 * JsonGenerator generator2 = factory.createGenerator(...);
40 * </code>
41 * </pre>
42 *
43 * <p> All the methods in this class are safe for use by multiple concurrent
44 * threads.
45 */
46 public interface JsonGeneratorFactory {
47
48 /**
49 * Creates a JSON generator to write JSON text to a character stream.
50 * The generator is configured with the factory configuration.
51 *
52 * @param writer i/o writer to which JSON is written
53 * @return the created JSON generator
54 */
55 JsonGenerator createGenerator(Writer writer);
56
57 /**
58 * Creates a JSON generator to write JSON text to a byte stream. Characters
59 * written to the stream are encoded into bytes using UTF-8 encoding.
60 * The generator is configured with the factory's configuration.
61 *
62 * @param out i/o stream to which JSON is written
63 * @return the created JSON generator
64 */
65 JsonGenerator createGenerator(OutputStream out);
66
67 /**
68 * Creates a JSON generator to write JSON text to a byte stream. Characters
69 * written to the stream are encoded into bytes using the specified charset.
70 * The generator is configured with the factory's configuration.
71 *
72 * @param out i/o stream to which JSON is written
73 * @param charset a charset
74 * @return the created JSON generator
75 */
76 JsonGenerator createGenerator(OutputStream out, Charset charset);
77
78 /**
79 * Returns a read-only map of supported provider specific configuration
80 * properties that are used to configure the JSON generators.
81 * If there are any specified configuration properties that are not
82 * supported by the provider, they won't be part of the returned map.
83 *
84 * @return a map of supported provider specific properties that are used
85 * to configure the created generators. The map may be empty but not null
86 */
87 Map<String, ?> getConfigInUse();
88
89 }