| 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 jakarta.json.JsonArray; |
| 20 | import jakarta.json.JsonObject; |
| 21 | import java.io.InputStream; |
| 22 | import java.io.Reader; |
| 23 | import java.nio.charset.Charset; |
| 24 | import java.util.Map; |
| 25 | |
| 26 | /** |
| 27 | * Factory for creating {@link JsonParser} instances. If a factory |
| 28 | * instance is configured with a configuration, the configuration applies |
| 29 | * to all parser instances created using that factory instance. |
| 30 | * |
| 31 | * <p> |
| 32 | * The class {@link jakarta.json.Json Json} also provides methods to create |
| 33 | * {@link JsonParser} instances, but using {@code JsonParserFactory} is |
| 34 | * preferred when creating multiple parser instances as shown in the following |
| 35 | * example: |
| 36 | * |
| 37 | * <pre> |
| 38 | * <code> |
| 39 | * JsonParserFactory factory = Json.createParserFactory(); |
| 40 | * JsonParser parser1 = factory.createParser(...); |
| 41 | * JsonParser parser2 = factory.createParser(...); |
| 42 | * </code> |
| 43 | * </pre> |
| 44 | * |
| 45 | * <p> All the methods in this class are safe for use by multiple concurrent |
| 46 | * threads. |
| 47 | */ |
| 48 | public interface JsonParserFactory { |
| 49 | |
| 50 | /** |
| 51 | * Creates a JSON parser from a character stream. |
| 52 | * |
| 53 | * @param reader a i/o reader from which JSON is to be read |
| 54 | * @return the created JSON parser |
| 55 | */ |
| 56 | JsonParser createParser(Reader reader); |
| 57 | |
| 58 | /** |
| 59 | * Creates a JSON parser from the specified byte stream. |
| 60 | * The character encoding of the stream is determined |
| 61 | * as specified in <a href="http://tools.ietf.org/rfc/rfc7159.txt">RFC 7159</a>. |
| 62 | * |
| 63 | * @param in i/o stream from which JSON is to be read |
| 64 | * @return the created JSON parser |
| 65 | * @throws jakarta.json.JsonException if encoding cannot be determined |
| 66 | * or i/o error (IOException would be cause of JsonException) |
| 67 | */ |
| 68 | JsonParser createParser(InputStream in); |
| 69 | |
| 70 | /** |
| 71 | * Creates a JSON parser from the specified byte stream. |
| 72 | * The bytes of the stream are decoded to characters using the |
| 73 | * specified charset. |
| 74 | * |
| 75 | * @param in i/o stream from which JSON is to be read |
| 76 | * @param charset a charset |
| 77 | * @return the created JSON parser |
| 78 | */ |
| 79 | JsonParser createParser(InputStream in, Charset charset); |
| 80 | |
| 81 | /** |
| 82 | * Creates a JSON parser from the specified JSON object. |
| 83 | * |
| 84 | * @param obj a JSON object |
| 85 | * @return the created JSON parser |
| 86 | */ |
| 87 | JsonParser createParser(JsonObject obj); |
| 88 | |
| 89 | /** |
| 90 | * Creates a JSON parser from the specified JSON array. |
| 91 | * |
| 92 | * @param array a JSON array |
| 93 | * @return the created JSON parser |
| 94 | */ |
| 95 | JsonParser createParser(JsonArray array); |
| 96 | |
| 97 | /** |
| 98 | * Returns a read-only map of supported provider specific configuration |
| 99 | * properties that are used to configure the JSON parsers. |
| 100 | * If there are any specified configuration properties that are not |
| 101 | * supported by the provider, they won't be part of the returned map. |
| 102 | * |
| 103 | * @return a map of supported provider specific properties that are used |
| 104 | * to configure the created parsers. The map may be empty but not null |
| 105 | */ |
| 106 | Map<String, ?> getConfigInUse(); |
| 107 | |
| 108 | } |