| 1 | /* |
| 2 | * Copyright (c) 2013, 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; |
| 18 | |
| 19 | import java.io.InputStream; |
| 20 | import java.io.Reader; |
| 21 | import java.nio.charset.Charset; |
| 22 | import java.util.Map; |
| 23 | |
| 24 | /** |
| 25 | * Factory to create {@link jakarta.json.JsonReader} instances. If a factory |
| 26 | * instance is configured with some configuration, that would be |
| 27 | * used to configure the created reader instances. |
| 28 | * |
| 29 | * <p> |
| 30 | * {@link jakarta.json.JsonReader} can also be created using {@link Json}'s |
| 31 | * {@code createReader} methods. If multiple reader instances are created, |
| 32 | * then creating them using a reader factory is preferred. |
| 33 | * |
| 34 | * <p> |
| 35 | * <b>For example:</b> |
| 36 | * <pre> |
| 37 | * <code> |
| 38 | * JsonReaderFactory factory = Json.createReaderFactory(...); |
| 39 | * JsonReader reader1 = factory.createReader(...); |
| 40 | * JsonReader reader2 = factory.createReader(...); |
| 41 | * </code> |
| 42 | * </pre> |
| 43 | * |
| 44 | * <p> All the methods in this class are safe for use by multiple concurrent |
| 45 | * threads. |
| 46 | */ |
| 47 | public interface JsonReaderFactory { |
| 48 | |
| 49 | /** |
| 50 | * Creates a JSON reader from a character stream. The reader is configured |
| 51 | * with the factory configuration. |
| 52 | * |
| 53 | * @param reader a reader from which JSON is to be read |
| 54 | * @return a JSON reader |
| 55 | */ |
| 56 | JsonReader createReader(Reader reader); |
| 57 | |
| 58 | /** |
| 59 | * Creates a JSON reader from a byte stream. The character encoding of |
| 60 | * the stream is determined as described in |
| 61 | * <a href="http://tools.ietf.org/rfc/rfc7159.txt">RFC 7159</a>. |
| 62 | * The reader is configured with the factory configuration. |
| 63 | * |
| 64 | * @param in a byte stream from which JSON is to be read |
| 65 | * @return a JSON reader |
| 66 | */ |
| 67 | JsonReader createReader(InputStream in); |
| 68 | |
| 69 | /** |
| 70 | * Creates a JSON reader from a byte stream. The bytes of the stream |
| 71 | * are decoded to characters using the specified charset. The reader is |
| 72 | * configured with the factory configuration. |
| 73 | * |
| 74 | * @param in a byte stream from which JSON is to be read |
| 75 | * @param charset a charset |
| 76 | * @return a JSON reader |
| 77 | */ |
| 78 | JsonReader createReader(InputStream in, Charset charset); |
| 79 | |
| 80 | /** |
| 81 | * Returns read-only map of supported provider specific configuration |
| 82 | * properties that are used to configure the created JSON readers. |
| 83 | * If there are any specified configuration properties that are not |
| 84 | * supported by the provider, they won't be part of the returned map. |
| 85 | * |
| 86 | * @return a map of supported provider specific properties that are used |
| 87 | * to configure the readers. The map be empty but not null. |
| 88 | */ |
| 89 | Map<String, ?> getConfigInUse(); |
| 90 | |
| 91 | } |