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

Last change on this file since 9379 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: 5.4 KB
Line 
1/*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright (c) 2012-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 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 * <a id="JsonReaderExample1"/>
54 * The following example demonstrates how to read an empty JSON array from
55 * a string:
56 * <pre>
57 * <code>
58 * JsonReader jsonReader = Json.createReader(new StringReader("[]"));
59 * JsonArray array = jsonReader.readArray();
60 * jsonReader.close();
61 * </code>
62 * </pre>
63 *
64 * <p>
65 * The class {@link JsonReaderFactory} also contains methods to create
66 * {@code JsonReader} instances. A factory instance can be used to create
67 * multiple reader instances with the same configuration. This the preferred
68 * way to create multiple instances. A sample usage is shown in the following
69 * example:
70 * <pre>
71 * <code>
72 * JsonReaderFactory factory = Json.createReaderFactory(config);
73 * JsonReader reader1 = factory.createReader(...);
74 * JsonReader reader2 = factory.createReader(...);
75 * </code>
76 * </pre>
77 *
78 * @author Jitendra Kotamraju
79 */
80public interface JsonReader extends /*Auto*/Closeable {
81
82 /**
83 * Returns a JSON array or object that is represented in
84 * the input source. This method needs to be called
85 * only once for a reader instance.
86 *
87 * @return a JSON object or array
88 * @throws JsonException if a JSON object or array cannot
89 * be created due to i/o error (IOException would be
90 * cause of JsonException)
91 * @throws javax.json.stream.JsonParsingException if a JSON object or array
92 * cannot be created due to incorrect representation
93 * @throws IllegalStateException if read, readObject, readArray or
94 * close method is already called
95 */
96 JsonStructure read();
97
98 /**
99 * Returns a JSON object that is represented in
100 * the input source. This method needs to be called
101 * only once for a reader instance.
102 *
103 * @return a JSON object
104 * @throws JsonException if a JSON object cannot
105 * be created due to i/o error (IOException would be
106 * cause of JsonException)
107 * @throws javax.json.stream.JsonParsingException if a JSON object cannot
108 * be created due to incorrect representation
109 * @throws IllegalStateException if read, readObject, readArray or
110 * close method is already called
111 */
112 JsonObject readObject();
113
114 /**
115 * Returns a JSON array that is represented in
116 * the input source. This method needs to be called
117 * only once for a reader instance.
118 *
119 * @return a JSON array
120 * @throws JsonException if a JSON array cannot
121 * be created due to i/o error (IOException would be
122 * cause of JsonException)
123 * @throws javax.json.stream.JsonParsingException if a JSON array cannot
124 * be created due to incorrect representation
125 * @throws IllegalStateException if read, readObject, readArray or
126 * close method is already called
127 */
128 JsonArray readArray();
129
130 /**
131 * Closes this reader and frees any resources associated with the
132 * reader. This method closes the underlying input source.
133 *
134 * @throws JsonException if an i/o error occurs (IOException would be
135 * cause of JsonException)
136 */
137 @Override
138 void close();
139
140}
Note: See TracBrowser for help on using the repository browser.