source: josm/trunk/src/javax/json/JsonReader.java@ 13611

Last change on this file since 13611 was 13231, checked in by Don-vip, 7 years ago

see #15682 - upgrade to JSR 374 (JSON Processing) API 1.1.2

File size: 5.9 KB
Line 
1/*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright (c) 2012-2017 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://oss.oracle.com/licenses/CDDL+GPL-1.1
12 * or 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 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 java.io.Closeable;
44
45/**
46 * Reads a JSON {@link JsonObject object} or an {@link JsonArray array}
47 * structure from an input source.
48 *
49 * <p>The class {@link javax.json.Json} contains methods to create readers from
50 * input sources ({@link java.io.InputStream} and {@link java.io.Reader}).
51 *
52 * <p>
53 * The following example demonstrates how to read an empty JSON array from
54 * a string:
55 * <pre>
56 * <code>
57 * JsonReader jsonReader = Json.createReader(new StringReader("[]"));
58 * JsonArray array = jsonReader.readArray();
59 * jsonReader.close();
60 * </code>
61 * </pre>
62 *
63 * <p>
64 * The class {@link JsonReaderFactory} also contains methods to create
65 * {@code JsonReader} instances. A factory instance can be used to create
66 * multiple reader instances with the same configuration. This the preferred
67 * way to create multiple instances. A sample usage is shown in the following
68 * example:
69 * <pre>
70 * <code>
71 * JsonReaderFactory factory = Json.createReaderFactory(config);
72 * JsonReader reader1 = factory.createReader(...);
73 * JsonReader reader2 = factory.createReader(...);
74 * </code>
75 * </pre>
76 */
77public interface JsonReader extends /*Auto*/Closeable {
78
79 /**
80 * Returns a JSON array or object that is represented in
81 * the input source. This method needs to be called
82 * only once for a reader instance.
83 *
84 * @return a JSON object or array
85 * @throws JsonException if a JSON object or array cannot
86 * be created due to i/o error (IOException would be
87 * cause of JsonException)
88 * @throws javax.json.stream.JsonParsingException if a JSON object or array
89 * cannot be created due to incorrect representation
90 * @throws IllegalStateException if read, readObject, readArray,
91 * readValue or close method is already called
92 */
93 JsonStructure read();
94
95 /**
96 * Returns a JSON object that is represented in
97 * the input source. This method needs to be called
98 * only once for a reader instance.
99 *
100 * @return a JSON object
101 * @throws JsonException if a JSON object cannot
102 * be created due to i/o error (IOException would be
103 * cause of JsonException)
104 * @throws javax.json.stream.JsonParsingException if a JSON object cannot
105 * be created due to incorrect representation
106 * @throws IllegalStateException if read, readObject, readArray,
107 * readValue or close method is already called
108 */
109 JsonObject readObject();
110
111 /**
112 * Returns a JSON array that is represented in
113 * the input source. This method needs to be called
114 * only once for a reader instance.
115 *
116 * @return a JSON array
117 * @throws JsonException if a JSON array cannot
118 * be created due to i/o error (IOException would be
119 * cause of JsonException)
120 * @throws javax.json.stream.JsonParsingException if a JSON array cannot
121 * be created due to incorrect representation
122 * @throws IllegalStateException if read, readObject, readArray,
123 * readValue or close method is already called
124 */
125 JsonArray readArray();
126
127 /**
128 * Returns a JSON value that is represented in
129 * the input source. This method needs to be called
130 * only once for a reader instance.
131 *
132 * @return a JSON value
133 * @throws JsonException if a JSON value
134 * be created due to i/o error (IOException would be
135 * cause of JsonException)
136 * @throws javax.json.stream.JsonParsingException if a JSON value
137 * cannot be created due to incorrect representation
138 * @throws IllegalStateException if read, readObject, readArray,
139 * readValue or close method is already called
140 *
141 * @since 1.1
142 */
143 default JsonValue readValue() {
144 throw new UnsupportedOperationException();
145 }
146
147 /**
148 * Closes this reader and frees any resources associated with the
149 * reader. This method closes the underlying input source.
150 *
151 * @throws JsonException if an i/o error occurs (IOException would be
152 * cause of JsonException)
153 */
154 @Override
155 void close();
156
157}
Note: See TracBrowser for help on using the repository browser.