Changeset 13231 in josm


Ignore:
Timestamp:
2017-12-23T02:40:43+01:00 (7 years ago)
Author:
Don-vip
Message:

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

Location:
trunk
Files:
16 added
49 edited

Legend:

Unmodified
Added
Removed
  • trunk/CONTRIBUTION

    r12909 r13231  
    6363is from Johan Montagnat and licensed with GPL.
    6464
    65 The JSON code (https://java.net/projects/jsonp/)
    66 is from Oracle (RI for JSR 353: Java API for JSON Processing)
     65The JSON code (https://javaee.github.io/jsonp/)
     66is from Oracle (RI for JSR 374: Java API for JSON Processing)
    6767and licensed with GPL / classpath exception.
    6868
  • trunk/src/javax/json/Json.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2011-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2011-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    4141package javax.json;
    4242
     43import java.io.InputStream;
     44import java.io.OutputStream;
     45import java.io.Reader;
     46import java.io.Writer;
     47import java.math.BigDecimal;
     48import java.math.BigInteger;
     49import java.util.Collection;
     50import java.util.Map;
     51import java.util.Optional;
    4352import javax.json.spi.JsonProvider;
    4453import javax.json.stream.JsonGenerator;
     
    4655import javax.json.stream.JsonParser;
    4756import javax.json.stream.JsonParserFactory;
    48 import java.io.*;
    49 import java.util.Map;
    5057
    5158/**
     
    7380 * All the methods in this class are safe for use by multiple concurrent
    7481 * threads.
    75  *
    76  * @author Jitendra Kotamraju
    7782 */
    78 public class Json {
     83public final class Json {
    7984
    8085    private Json() {
     
    9398    /**
    9499     * Creates a JSON parser from a byte stream.
    95      * The character encoding of the stream is determined as specified in 
    96      * <a href="http://tools.ietf.org/rfc/rfc4627.txt">RFC 4627</a>.
     100     * The character encoding of the stream is determined as specified in
     101     * <a href="http://tools.ietf.org/rfc/rfc7159.txt">RFC 7159</a>.
    97102     *
    98103     * @param in i/o stream from which JSON is to be read
     
    212217     * Creates a JSON reader from a byte stream. The character encoding of
    213218     * the stream is determined as described in
    214      * <a href="http://tools.ietf.org/rfc/rfc4627.txt">RFC 4627</a>.
     219     * <a href="http://tools.ietf.org/rfc/rfc7159.txt">RFC 7159</a>.
    215220     *
    216221     * @param in a byte stream from which JSON is to be read
     
    259264
    260265    /**
     266     * Creates a JSON array builder, initialized with the specified array
     267     *
     268     * @param array the initial array in the builder
     269     * @return a JSON array builder
     270     *
     271     * @since 1.1
     272     */
     273    public static JsonArrayBuilder createArrayBuilder(JsonArray array) {
     274        return JsonProvider.provider().createArrayBuilder(array);
     275    }
     276
     277    /**
     278     * Creates a JSON array builder, initialized with the content of specified {@code collection}.
     279     * If the @{code collection} contains {@link Optional}s then resulting JSON array builder
     280     * contains the value from the {@code collection} only if the {@link Optional} is not empty.
     281     *
     282     * @param collection the initial data for the builder
     283     * @return a JSON array builder
     284     * @exception IllegalArgumentException if the value from the {@code collection} cannot be converted
     285     *            to the corresponding {@link JsonValue}
     286     *
     287     * @since 1.1
     288     */
     289    public static JsonArrayBuilder createArrayBuilder(Collection<?> collection) {
     290        return JsonProvider.provider().createArrayBuilder(collection);
     291    }
     292
     293    /**
    261294     * Creates a JSON object builder
    262295     *
     
    265298    public static JsonObjectBuilder createObjectBuilder() {
    266299        return JsonProvider.provider().createObjectBuilder();
     300    }
     301
     302    /**
     303     * Creates a JSON object builder, initialized with the specified object.
     304     *
     305     * @param object the initial object in the builder
     306     * @return a JSON object builder
     307     *
     308     * @since 1.1
     309     */
     310    public static JsonObjectBuilder createObjectBuilder(JsonObject object) {
     311        return JsonProvider.provider().createObjectBuilder(object);
     312    }
     313
     314    /**
     315     * Creates a JSON object builder, initialized with the data from specified {@code map}.
     316     * If the @{code map} contains {@link Optional}s then resulting JSON object builder
     317     * contains the key from the {@code map} only if the {@link Optional} is not empty.
     318     *
     319     * @param map the initial object in the builder
     320     * @return a JSON object builder
     321     * @exception IllegalArgumentException if the value from the {@code map} cannot be converted
     322     *            to the corresponding {@link JsonValue}
     323     *
     324     * @since 1.1
     325     */
     326    public static JsonObjectBuilder createObjectBuilder(Map<String, Object> map) {
     327        return JsonProvider.provider().createObjectBuilder(map);
     328    }
     329
     330    /**
     331     * Creates JSON Pointer (<a href="http://tools.ietf.org/html/rfc6901">RFC 6901</a>)
     332     * from given {@code jsonPointer} string.
     333     * <ul>
     334     *     <li>An empty {@code jsonPointer} string defines a reference to the target itself.</li>
     335     *     <li>If the {@code jsonPointer} string is non-empty, it must be a sequence of '{@code /}' prefixed tokens.</li>
     336     * </ul>
     337     *
     338     * @param jsonPointer the valid escaped JSON Pointer string
     339     * @throws NullPointerException if {@code jsonPointer} is {@code null}
     340     * @throws JsonException if {@code jsonPointer} is not a valid JSON Pointer
     341     * @return a JSON Pointer
     342     *
     343     * @since 1.1
     344     */
     345    public static JsonPointer createPointer(String jsonPointer) {
     346        return JsonProvider.provider().createPointer(jsonPointer);
     347    }
     348
     349    /**
     350     * Creates a JSON Patch builder (<a href="http://tools.ietf.org/html/rfc6902">RFC 6902</a>).
     351     *
     352     * @return a JSON Patch builder
     353     *
     354     * @since 1.1
     355     */
     356    public static JsonPatchBuilder createPatchBuilder() {
     357        return JsonProvider.provider().createPatchBuilder();
     358    }
     359
     360    /**
     361     * Creates a JSON Patch builder
     362     * (<a href="http://tools.ietf.org/html/rfc6902">RFC 6902</a>),
     363     * initialized with the specified operations.
     364     *
     365     * @param array the initial patch operations
     366     * @return a JSON Patch builder
     367     *
     368     * @since 1.1
     369     */
     370    public static JsonPatchBuilder createPatchBuilder(JsonArray array) {
     371        return JsonProvider.provider().createPatchBuilder(array);
     372    }
     373
     374    /**
     375     * Creates a JSON Patch (<a href="http://tools.ietf.org/html/rfc6902">RFC 6902</a>)
     376     * from the specified operations.
     377     *
     378     * @param array patch operations
     379     * @return a JSON Patch
     380     *
     381     * @since 1.1
     382     */
     383    public static JsonPatch createPatch(JsonArray array) {
     384        return JsonProvider.provider().createPatch(array);
     385    }
     386
     387    /**
     388     * Generates a JSON Patch (<a href="http://tools.ietf.org/html/rfc6902">RFC 6902</a>)
     389     * from the source and target {@code JsonStructure}.
     390     * The generated JSON Patch need not be unique.
     391     *
     392     * @param source the source
     393     * @param target the target, must be the same type as the source
     394     * @return a JSON Patch which when applied to the source, yields the target
     395     *
     396     * @since 1.1
     397     */
     398    public static JsonPatch createDiff(JsonStructure source, JsonStructure target) {
     399        return JsonProvider.provider().createDiff(source, target);
     400    }
     401
     402    /**
     403     * Creates JSON Merge Patch (<a href="http://tools.ietf.org/html/rfc7396">RFC 7396</a>)
     404     * from specified {@code JsonValue}.
     405     *
     406     * @param patch the patch
     407     * @return a JSON Merge Patch
     408     *
     409     * @since 1.1
     410     */
     411    public static JsonMergePatch createMergePatch(JsonValue patch) {
     412        return JsonProvider.provider().createMergePatch(patch);
     413    }
     414
     415    /**
     416     * Generates a JSON Merge Patch (<a href="http://tools.ietf.org/html/rfc7396">RFC 7396</a>)
     417     * from the source and target {@code JsonValue}s
     418     * which when applied to the {@code source}, yields the {@code target}.
     419     *
     420     * @param source the source
     421     * @param target the target
     422     * @return a JSON Merge Patch
     423     *
     424     * @since 1.1
     425     */
     426    public static JsonMergePatch createMergeDiff(JsonValue source, JsonValue target) {
     427        return JsonProvider.provider().createMergeDiff(source, target);
    267428    }
    268429
     
    283444    }
    284445
     446    /**
     447     * Creates a JsonString.
     448     *
     449     * @param value a JSON string
     450     * @return the JsonString for the string
     451     *
     452     * @since 1.1
     453     */
     454    public static JsonString createValue(String value) {
     455        return JsonProvider.provider().createValue(value);
     456    }
     457
     458    /**
     459     * Creates a JsonNumber.
     460     *
     461     * @param value a JSON number
     462     * @return the JsonNumber for the number
     463     *
     464     * @since 1.1
     465     */
     466    public static JsonNumber createValue(int value) {
     467        return JsonProvider.provider().createValue(value);
     468    }
     469
     470    /**
     471     * Creates a JsonNumber.
     472     *
     473     * @param value a JSON number
     474     * @return the JsonNumber for the number
     475     *
     476     * @since 1.1
     477     */
     478    public static JsonNumber createValue(long value) {
     479        return JsonProvider.provider().createValue(value);
     480    }
     481
     482    /**
     483     * Creates a JsonNumber.
     484     *
     485     * @param value a JSON number
     486     * @return the JsonNumber for the number
     487     *
     488     * @since 1.1
     489     */
     490    public static JsonNumber createValue(double value) {
     491        return JsonProvider.provider().createValue(value);
     492    }
     493
     494    /**
     495     * Creates a JsonNumber.
     496     *
     497     * @param value a JSON number
     498     * @return the JsonNumber for the number
     499     *
     500     * @since 1.1
     501     */
     502    public static JsonNumber createValue(BigDecimal value) {
     503        return JsonProvider.provider().createValue(value);
     504    }
     505
     506    /**
     507     * Creates a JsonNumber.
     508     *
     509     * @param value a JSON number
     510     * @return the JsonNumber for the number
     511     *
     512     * @since 1.1
     513     */
     514    public static JsonNumber createValue(BigInteger value) {
     515        return JsonProvider.provider().createValue(value);
     516    }
     517
     518    /**
     519     * Encodes (escapes) a passed string as defined by <a href="http://tools.ietf.org/html/rfc6901">RFC 6901</a>.
     520     * This method doesn't validate the passed JSON-pointer string.
     521     *
     522     * @param pointer the JSON-pointer string to encode
     523     * @return encoded JSON-pointer string
     524     *
     525     * @since 1.1
     526     */
     527    public static String encodePointer(String pointer) {
     528        return pointer.replace("~", "~0").replace("/", "~1");
     529    }
     530
     531    /**
     532     * Decodes a passed JSON-pointer string as defined by <a href="http://tools.ietf.org/html/rfc6901">RFC 6901</a>.
     533     * This method doesn't validate the passed JSON-pointer string.
     534     *
     535     * @param escaped the JSON-pointer string to decode
     536     * @return decoded JSON-pointer string
     537     *     
     538     * @since 1.1
     539     */
     540    public static String decodePointer(String escaped) {
     541        return escaped.replace("~1", "/").replace("~0", "~");
     542    }
     543
    285544}
  • trunk/src/javax/json/JsonArray.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2011-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2011-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    4242
    4343import java.util.List;
     44import java.util.function.Function;
     45import java.util.stream.Collectors;
     46import java.util.stream.Stream;
    4447
    4548/**
     
    111114 * whether directly or using its collection views, results in an
    112115 * {@code UnsupportedOperationException}.
    113  *
    114  * @author Jitendra Kotamraju
    115116 */
    116117public interface JsonArray extends JsonStructure, List<JsonValue> {
     
    165166
    166167    /**
    167      * Returns a list a view of the specified type for the array. This method
     168     * Returns a list view of the specified type for the array. This method
    168169     * does not verify if there is a value of wrong type in the array. Providing
    169170     * this typesafe view dynamically may cause a program fail with a
     
    172173     * method returns.
    173174     *
     175     * @param <T> The type of the List for the array
    174176     * @param clazz a JsonValue type
    175      * @return a list view of the  specified type
     177     * @return a list view of the specified type
    176178     */
    177179    <T extends JsonValue> List<T> getValuesAs(Class<T> clazz);
     180
     181    /**
     182     * Returns a list view for the array. The value and the type of the elements
     183     * in the list is specified by the {@code func} argument.
     184     * <p>This method can be used to obtain a list of the unwrapped types, such as
     185     * <pre>{@code
     186     *     List<String> strings = ary1.getValuesAs(JsonString::getString);
     187     *     List<Integer> ints = ary2.getValuesAs(JsonNumber::intValue);
     188     * } </pre>
     189     * or a list of simple projections, such as
     190     * <pre> {@code
     191     *     List<Integer> stringsizes = ary1.getValueAs((JsonString v)->v.getString().length();
     192     * } </pre>
     193     * @param <K> The element type (must be a subtype of JsonValue) of this JsonArray.
     194     * @param <T> The element type of the returned List
     195     * @param func The function that maps the elements of this JsonArray to the target elements.
     196     * @return A List of the specified values and type.
     197     * @throws ClassCastException if the {@code JsonArray} contains a value of wrong type
     198     *
     199     * @since 1.1
     200     */
     201    default <T, K extends JsonValue> List<T> getValuesAs(Function<K, T> func) {
     202        @SuppressWarnings("unchecked")
     203        Stream<K> stream = (Stream<K>) stream();
     204        return stream.map(func).collect(Collectors.toList());
     205    }
    178206
    179207    /**
     
    195223     * the specified default value is returned.
    196224     *
    197      * @param index index of the JsonString value
     225     * @param index index of the {@code JsonString} value
     226     * @param defaultValue the String to return if the {@code JsonValue} at the
     227     *    specified position is not a {@code JsonString}
    198228     * @return the String value at the specified position in this array,
    199229     * or the specified default value
     
    220250     *
    221251     * @param index index of the {@code JsonNumber} value
     252     * @param defaultValue the int value to return if the {@code JsonValue} at
     253     *     the specified position is not a {@code JsonNumber}
    222254     * @return the int value at the specified position in this array,
    223255     * or the specified default value
     
    247279     *
    248280     * @param index index of the JSON boolean value
     281     * @param defaultValue the boolean value to return if the {@code JsonValue}
     282     *    at the specified position is neither TRUE nor FALSE
    249283     * @return the boolean value at the specified position,
    250284     * or the specified default value
     
    258292     * @param index index of the JSON null value
    259293     * @return return true if the value at the specified location is
    260      * {@code JsonValue.NUL}, otherwise false
     294     * {@code JsonValue.NULL}, otherwise false
    261295     * @throws IndexOutOfBoundsException if the index is out of range
    262296     */
    263297    boolean isNull(int index);
    264 
    265298}
  • trunk/src/javax/json/JsonArrayBuilder.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    4545
    4646/**
    47  * A builder for creating {@link JsonArray} models from scratch. This
    48  * interface initializes an empty JSON array model and provides methods to add
    49  * values to the array model and to return the resulting array. The methods
    50  * in this class can be chained to add multiple values to the array.
     47 * A builder for creating {@link JsonArray} models from scratch, and for
     48 * modifying a existing {@code JsonArray}.
     49 * <p>A {@code JsonArrayBuilder} can start with an empty or a non-empty
     50 * JSON array model. This interface provides methods to add, insert, remove
     51 * and replace values in the JSON array model.</p>
     52 * <p>Methods in this class can be chained to perform multiple values to
     53 * the array.</p>
    5154 *
    5255 * <p>The class {@link javax.json.Json} contains methods to create the builder
     
    6467 * way to create multiple instances.
    6568 *
    66  * <a id="JsonArrayBuilderExample1"/>
    6769 * The example code below shows how to build a {@code JsonArray} object
    6870 * that represents the following JSON array:
     
    165167     * @param value the number value
    166168     * @return this array builder
    167      * @throws NumberFormatException if the value is Not-a-Number(NaN) or
     169     * @throws NumberFormatException if the value is Not-a-Number (NaN) or
    168170     *      infinity
    169171     *
     
    207209
    208210    /**
     211     * Adds all elements of the array in the specified array builder to the array.
     212     *
     213     * @param builder the array builder
     214     * @return this array builder
     215     * @throws NullPointerException if the specified builder is null
     216     *
     217     @since 1.1
     218     */
     219    default JsonArrayBuilder addAll(JsonArrayBuilder builder) {
     220        throw new UnsupportedOperationException();
     221    }
     222
     223    /**
     224     * Inserts a value to the array at the specified position. Shifts the value
     225     * currently at that position (if any) and any subsequent values to the right
     226     * (adds one to their indices).  Index starts with 0.
     227     *
     228     * @param index the position in the array
     229     * @param value the JSON value
     230     * @return this array builder
     231     * @throws NullPointerException if the specified value is null
     232     * @throws IndexOutOfBoundsException if the index is out of range
     233     *   {@code (index < 0 || index > array size)}
     234     *
     235     * @since 1.1
     236     */
     237    default JsonArrayBuilder add(int index, JsonValue value) {
     238        throw new UnsupportedOperationException();
     239    }
     240
     241    /**
     242     * Adds a value to the array as a {@link JsonString} at the specified position.
     243     * Shifts the value currently at that position (if any) and any subsequent values
     244     * to the right (adds one to their indices).  Index starts with 0.
     245     *
     246     * @param index the position in the array
     247     * @param value the string value
     248     * @return this array builder
     249     * @throws NullPointerException if the specified value is null
     250     * @throws IndexOutOfBoundsException if the index is out of range
     251     *   {@code (index < 0 || index > array size)}
     252     *
     253     * @since 1.1
     254     */
     255    default JsonArrayBuilder add(int index, String value) {
     256        throw new UnsupportedOperationException();
     257    }
     258
     259    /**
     260     * Adds a value to the array as a {@link JsonNumber} at the specified position.
     261     * Shifts the value currently at that position (if any) and any subsequent values
     262     * to the right (adds one to their indices).  Index starts with 0.
     263     *
     264     * @param index the position in the array
     265     * @param value the number value
     266     * @return this array builder
     267     * @throws NullPointerException if the specified value is null
     268     * @throws IndexOutOfBoundsException if the index is out of range
     269     *   {@code (index < 0 || index > array size)}
     270     *
     271     * @see JsonNumber
     272     *
     273     * @since 1.1
     274     */
     275    default JsonArrayBuilder add(int index, BigDecimal value) {
     276        throw new UnsupportedOperationException();
     277    }
     278
     279    /**
     280     * Adds a value to the array as a {@link JsonNumber} at the specified position.
     281     * Shifts the value currently at that position (if any) and any subsequent values
     282     * to the right (adds one to their indices).  Index starts with 0.
     283     *
     284     * @param index the position in the array
     285     * @param value the number value
     286     * @return this array builder
     287     * @throws NullPointerException if the specified value is null
     288     * @throws IndexOutOfBoundsException if the index is out of range
     289     *   {@code (index < 0 || index > array size)}
     290     *
     291     * @see JsonNumber
     292     *
     293     * @since 1.1
     294     */
     295    default JsonArrayBuilder add(int index, BigInteger value) {
     296        throw new UnsupportedOperationException();
     297    }
     298
     299    /**
     300     * Adds a value to the array as a {@link JsonNumber} at the specified position.
     301     * Shifts the value currently at that position (if any) and any subsequent values
     302     * to the right (adds one to their indices).  Index starts with 0.
     303     *
     304     * @param index the position in the array
     305     * @param value the number value
     306     * @return this array builder
     307     * @throws IndexOutOfBoundsException if the index is out of range
     308     *   {@code (index < 0 || index > array size)}
     309     *
     310     * @see JsonNumber
     311     *
     312     * @since 1.1
     313     */
     314    default JsonArrayBuilder add(int index, int value) {
     315        throw new UnsupportedOperationException();
     316    }
     317
     318    /**
     319     * Adds a value to the array as a {@link JsonNumber} at the specified position.
     320     * Shifts the value currently at that position (if any) and any subsequent values
     321     * to the right (adds one to their indices).  Index starts with 0.
     322     *
     323     * @param index the position in the array
     324     * @param value the number value
     325     * @return this array builder
     326     * @throws IndexOutOfBoundsException if the index is out of range
     327     *   {@code (index < 0 || index > array size)}
     328     *
     329     * @see JsonNumber
     330     *
     331     * @since 1.1
     332     */
     333    default JsonArrayBuilder add(int index, long value) {
     334        throw new UnsupportedOperationException();
     335    }
     336
     337    /**
     338     * Adds a value to the array as a {@link JsonNumber} at the specified position.
     339     * Shifts the value currently at that position (if any) and any subsequent values
     340     * to the right (adds one to their indices).  Index starts with 0.
     341     *
     342     * @param index the position in the array
     343     * @param value the number value
     344     * @return this array builder
     345     * @throws NumberFormatException if the value is Not-a-Number (NaN) or
     346     *      infinity
     347     * @throws IndexOutOfBoundsException if the index is out of range
     348     *   {@code (index < 0 || index > array size)}
     349     *
     350     * @see JsonNumber
     351     *
     352     * @since 1.1
     353     */
     354    default JsonArrayBuilder add(int index, double value) {
     355        throw new UnsupportedOperationException();
     356    }
     357
     358    /**
     359     * Adds a {@link JsonValue#TRUE}  or {@link JsonValue#FALSE} value to the
     360     * array at the specified position.
     361     * Shifts the value currently at that position (if any) and any subsequent values
     362     * to the right (adds one to their indices).  Index starts with 0.
     363     *
     364     * @param index the position in the array
     365     * @param value the boolean value
     366     * @return this array builder
     367     * @throws IndexOutOfBoundsException if the index is out of range
     368     *   {@code (index < 0 || index > array size)}
     369     *
     370     * @since 1.1
     371     */
     372    default JsonArrayBuilder add(int index, boolean value) {
     373        throw new UnsupportedOperationException();
     374    }
     375
     376    /**
     377     * Adds a {@link JsonValue#NULL} value to the array at the specified position.
     378     * Shifts the value currently at that position (if any) and any subsequent values
     379     * to the right (adds one to their indices).  Index starts with 0.
     380     *
     381     * @param index the position in the array
     382     * @return this array builder
     383     * @throws IndexOutOfBoundsException if the index is out of range
     384     *   {@code (index < 0 || index > array size)}
     385     *
     386     * @since 1.1
     387     */
     388    default JsonArrayBuilder addNull(int index) {
     389        return add(index, JsonValue.NULL);
     390    }
     391
     392    /**
     393     * Adds a {@link JsonObject} from an object builder to the array at the specified position.
     394     * Shifts the value currently at that position (if any) and any subsequent values
     395     * to the right (adds one to their indices).  Index starts with 0.
     396     *
     397     * @param index the position in the array
     398     * @param builder the object builder
     399     * @return this array builder
     400     * @throws NullPointerException if the specified builder is null
     401     * @throws IndexOutOfBoundsException if the index is out of range
     402     *   {@code (index < 0 || index > array size)}
     403     *
     404     * @since 1.1
     405     */
     406    default JsonArrayBuilder add(int index, JsonObjectBuilder builder) {
     407        throw new UnsupportedOperationException();
     408    }
     409
     410    /**
     411     * Adds a {@link JsonArray} from an array builder to the array at the specified position.
     412     * Shifts the value currently at that position (if any) and any subsequent values
     413     * to the right (adds one to their indices).  Index starts with 0.
     414     *
     415     * @param index the position in the array
     416     * @param builder the array builder
     417     * @return this array builder
     418     * @throws NullPointerException if the specified builder is null
     419     * @throws IndexOutOfBoundsException if the index is out of range
     420     *   {@code (index < 0 || index > array size)}
     421     *
     422     * @since 1.1
     423     */
     424    default JsonArrayBuilder add(int index, JsonArrayBuilder builder) {
     425        throw new UnsupportedOperationException();
     426    }
     427
     428    /**
     429     * Replaces a value in the array with the specified value at the
     430     * specified position.
     431     *
     432     * @param index the position in the array
     433     * @param value the JSON value
     434     * @return this array builder
     435     * @throws NullPointerException if the specified value is null
     436     * @throws IndexOutOfBoundsException if the index is out of range
     437     *   {@code (index < 0 || index >= array size)}
     438     *
     439     * @since 1.1
     440     */
     441    default JsonArrayBuilder set(int index, JsonValue value) {
     442        throw new UnsupportedOperationException();
     443    }
     444
     445    /**
     446     * Replaces a value in the array with the specified value as a
     447     * {@link JsonString} at the specified position.
     448     *
     449     * @param index the position in the array
     450     * @param value the string value
     451     * @return this array builder
     452     * @throws NullPointerException if the specified value is null
     453     * @throws IndexOutOfBoundsException if the index is out of range
     454     *   {@code (index < 0 || index >= array size)}
     455     *
     456     * @since 1.1
     457     */
     458    default JsonArrayBuilder set(int index, String value) {
     459        throw new UnsupportedOperationException();
     460    }
     461
     462    /**
     463     * Replaces a value in the array with the specified value as a
     464     * {@link JsonNumber} at the specified position.
     465     *
     466     * @param index the position in the array
     467     * @param value the number value
     468     * @return this array builder
     469     * @throws NullPointerException if the specified value is null
     470     * @throws IndexOutOfBoundsException if the index is out of range
     471     *   {@code (index < 0 || index >= array size)}
     472     *
     473     * @see JsonNumber
     474     *
     475     * @since 1.1
     476     */
     477    default JsonArrayBuilder set(int index, BigDecimal value) {
     478        throw new UnsupportedOperationException();
     479    }
     480
     481    /**
     482     * Replaces a value in the array with the specified value as a
     483     * {@link JsonNumber} at the specified position.
     484     *
     485     * @param index the position in the array
     486     * @param value the number value
     487     * @return this array builder
     488     * @throws NullPointerException if the specified value is null
     489     * @throws IndexOutOfBoundsException if the index is out of range
     490     *   {@code (index < 0 || index >= array size)}
     491     *
     492     * @see JsonNumber
     493     *
     494     * @since 1.1
     495     */
     496    default JsonArrayBuilder set(int index, BigInteger value) {
     497        throw new UnsupportedOperationException();
     498    }
     499
     500    /**
     501     * Replaces a value in the array with the specified value as a
     502     * {@link JsonNumber} at the specified position.
     503     *
     504     * @param index the position in the array
     505     * @param value the number value
     506     * @return this array builder
     507     * @throws IndexOutOfBoundsException if the index is out of range
     508     *   {@code (index < 0 || index >= array size)}
     509     *
     510     * @see JsonNumber
     511     *
     512     * @since 1.1
     513     */
     514    default JsonArrayBuilder set(int index, int value) {
     515        throw new UnsupportedOperationException();
     516    }
     517
     518    /**
     519     * Replaces a value in the array with the specified value as a
     520     * {@link JsonNumber} at the specified position.
     521     *
     522     * @param index the position in the array
     523     * @param value the number value
     524     * @return this array builder
     525     * @throws IndexOutOfBoundsException if the index is out of range
     526     *   {@code (index < 0 || index >= array size)}
     527     *
     528     * @see JsonNumber
     529     *
     530     * @since 1.1
     531     */
     532    default JsonArrayBuilder set(int index, long value) {
     533        throw new UnsupportedOperationException();
     534    }
     535
     536    /**
     537     * Replaces a value in the array with the specified value as a
     538     * {@link JsonNumber} at the specified position.
     539     *
     540     * @param index the position in the array
     541     * @param value the number value
     542     * @return this array builder
     543     * @throws NumberFormatException if the value is Not-a-Number (NaN) or
     544     *      infinity
     545     * @throws IndexOutOfBoundsException if the index is out of range
     546     *   {@code (index < 0 || index >= array size)}
     547     *
     548     * @see JsonNumber
     549     *
     550     * @since 1.1
     551     */
     552    default JsonArrayBuilder set(int index, double value) {
     553        throw new UnsupportedOperationException();
     554    }
     555
     556    /**
     557     * Replaces a value in the array with
     558     * a {@link JsonValue#TRUE}  or {@link JsonValue#FALSE} value
     559     * at the specified position.
     560     *
     561     * @param index the position in the array
     562     * @param value the boolean value
     563     * @return this array builder
     564     * @throws IndexOutOfBoundsException if the index is out of range
     565     *   {@code (index < 0 || index >= array size)}
     566     *
     567     * @since 1.1
     568     */
     569    default JsonArrayBuilder set(int index, boolean value) {
     570        throw new UnsupportedOperationException();
     571    }
     572
     573    /**
     574     * Replaces a value in the array with
     575     * a {@link JsonValue#NULL} value at the specified position.
     576     *
     577     * @param index the position in the array
     578     * @return this array builder
     579     * @throws IndexOutOfBoundsException if the index is out of range
     580     *   {@code (index < 0 || index >= array size)}
     581     *
     582     * @since 1.1
     583     */
     584    default JsonArrayBuilder setNull(int index) {
     585        return set(index, JsonValue.NULL);
     586    }
     587
     588    /**
     589     * Replaces a value in the array with the specified value as a
     590     * {@link JsonObject} from an object builder at the specified position.
     591     *
     592     * @param index the position in the array
     593     * @param builder the object builder
     594     * @return this array builder
     595     * @throws NullPointerException if the specified builder is null
     596     * @throws IndexOutOfBoundsException if the index is out of range
     597     *   {@code (index < 0 || index >= array size)}
     598     *
     599     * @since 1.1
     600     */
     601    default JsonArrayBuilder set(int index, JsonObjectBuilder builder) {
     602        throw new UnsupportedOperationException();
     603    }
     604
     605    /**
     606     * Replaces a value in the array with the specified value as a
     607     * {@link JsonArray} from an array builder at the specified position.
     608     *
     609     * @param index the position in the array
     610     * @param builder the array builder
     611     * @return this array builder
     612     * @throws NullPointerException if the specified builder is null
     613     * @throws IndexOutOfBoundsException if the index is out of range
     614     *   {@code (index < 0 || index >= array size)}
     615     *
     616     * @since 1.1
     617     */
     618    default JsonArrayBuilder set(int index, JsonArrayBuilder builder) {
     619        throw new UnsupportedOperationException();
     620    }
     621
     622    /**
     623     * Remove the value in the array at the specified position.
     624     * Shift any subsequent values to the left (subtracts one from their
     625     * indices.
     626     *
     627     * @param index the position in the array
     628     * @return this array builder
     629     * @throws IndexOutOfBoundsException if the index is out of range
     630     *   {@code (index < 0 || index >= array size)}
     631     *
     632     * @since 1.1
     633     */
     634    default JsonArrayBuilder remove(int index) {
     635        throw new UnsupportedOperationException();
     636    }
     637
     638    /**
    209639     * Returns the current array.
    210640     *
  • trunk/src/javax/json/JsonBuilderFactory.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    4141package javax.json;
    4242
     43import java.util.Collection;
    4344import java.util.Map;
    4445
     
    7172 * <p> All the methods in this class are safe for use by multiple concurrent
    7273 * threads.
    73  *
    74  * @author Jitendra Kotamraju
    7574 */
    7675public interface JsonBuilderFactory {
     
    8584
    8685    /**
     86     * Creates a {@code JsonObjectBuilder} instance, initialized with an object.
     87     *
     88     * @param object the initial object in the builder
     89     * @return a JSON object builder
     90     * @throws NullPointerException if specified object is {@code null}
     91     *
     92     * @since 1.1
     93     */
     94    default JsonObjectBuilder createObjectBuilder(JsonObject object) {
     95        throw new UnsupportedOperationException();
     96    }
     97
     98    /**
     99     * Creates a {@code JsonObjectBuilder} instance, initialized with the specified object.
     100     *
     101     * @param object the initial object in the builder
     102     * @return a JSON object builder
     103     * @throws NullPointerException if specified object is {@code null}
     104     *
     105     * @since 1.1
     106     */
     107    default JsonObjectBuilder createObjectBuilder(Map<String, Object> object) {
     108        throw new UnsupportedOperationException();
     109    }
     110
     111    /**
    87112     * Creates a {@code JsonArrayBuilder} instance that is used to build
    88113     * {@link JsonArray}
     
    91116     */
    92117    JsonArrayBuilder createArrayBuilder();
     118
     119    /**
     120     * Creates a {@code JsonArrayBuilder} instance, initialized with an array.
     121     *
     122     * @param array the initial array in the builder
     123     * @return a JSON array builder
     124     * @throws NullPointerException if specified array is {@code null}
     125     *
     126     * @since 1.1
     127     */
     128    default JsonArrayBuilder createArrayBuilder(JsonArray array) {
     129        throw new UnsupportedOperationException();
     130    }
     131
     132    /**
     133     * Creates a {@code JsonArrayBuilder} instance,
     134     * initialized with the content of specified collection.
     135     *
     136     * @param collection the initial data for the builder
     137     * @return a JSON array builder
     138     * @throws NullPointerException if specified collection is {@code null}
     139     *
     140     * @since 1.1
     141     */
     142    default JsonArrayBuilder createArrayBuilder(Collection<?> collection) {
     143        throw new UnsupportedOperationException();
     144    }
    93145
    94146    /**
  • trunk/src/javax/json/JsonException.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2011-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2011-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    4444 * <code>JsonException</code> indicates that some exception happened during
    4545 * JSON processing.
    46  *
    47  * @author Jitendra Kotamraju
    4846 */
    4947public class JsonException extends RuntimeException {
  • trunk/src/javax/json/JsonNumber.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2011-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2011-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    5151 * value internally.
    5252 * The {@code BigDecimal} object can be constructed from the following types:
    53  * {@link BigDecimal#BigDecimal(int) <code>int</code>},
    54  * {@link BigDecimal#BigDecimal(long) <code>long</code>},
    55  * {@link BigDecimal#BigDecimal(BigInteger) <code>BigInteger</code>},
    56  * {@link BigDecimal#valueOf(double) <code>double</code>}, and
    57  * {@link BigDecimal#BigDecimal(String) <code>String</code>}.
     53 * <code>int</code> {@link BigDecimal#BigDecimal(int)},
     54 * <code>long</code> {@link BigDecimal#BigDecimal(long)},
     55 * <code>BigInteger</code> {@link BigDecimal#BigDecimal(BigInteger)},
     56 * <code>double</code> {@link BigDecimal#valueOf(double)}, and
     57 * <code>String</code> {@link BigDecimal#BigDecimal(String)}.
    5858 * Some of the method semantics in this class are defined using the
    5959 * {@code BigDecimal} semantics.
    60  *
    61  * @author Jitendra Kotamraju
    6260 */
    6361public interface JsonNumber extends JsonValue {
     
    138136
    139137    /**
    140      * Returns this JSON number as a {@link BigDecimal} object. This is a
     138     * Returns this JSON number as a {@link BigInteger} object. This is a
    141139     * convenience method for {@code bigDecimalValue().toBigIntegerExact()}.
    142140     *
     
    167165
    168166    /**
     167     * Returns this JSON number as a {@link Number} object.
     168     *
     169     * @return a {@link Number} representation of the JSON number
     170     *
     171     * @since 1.1
     172     */
     173    default Number numberValue() {
     174        throw new UnsupportedOperationException();
     175    }
     176
     177    /**
    169178     * Returns a JSON text representation of the JSON number. The
    170179     * representation is equivalent to {@link BigDecimal#toString()}.
     
    181190     * objects are <i>equal</i>
    182191     *
    183      * @param obj the object to be compared for equality with 
     192     * @param obj the object to be compared for equality with
    184193     *      this {@code JsonNumber}
    185      * @return {@code true} if the specified object is equal to this 
     194     * @return {@code true} if the specified object is equal to this
    186195     *      {@code JsonNumber}
    187196     */
  • trunk/src/javax/json/JsonObject.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2011-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2011-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    125125 * name/value pairs are added to the corresponding builder or the order
    126126 * in which name/value pairs appear in the corresponding stream.
    127  *
    128  * @author Jitendra Kotamraju
    129127 */
    130128public interface JsonObject extends JsonStructure, Map<String, JsonValue> {
     
    266264     *
    267265     * @param name name whose associated value is checked
    268      * @return return true if the associated value is {@code JsonValue.NUL},
     266     * @return return true if the associated value is {@code JsonValue.NULL},
    269267     * otherwise false
    270268     * @throws NullPointerException if the specified name doesn't have any
  • trunk/src/javax/json/JsonObjectBuilder.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    6565 * way to create multiple instances.
    6666 *
    67  * <a id="JsonObjectBuilderExample1"/>
    6867 * The example code below shows how to build a {@code JsonObject} model that
    6968 * represents the following JSON object:
     
    207206     * @param value value in the name/value pair
    208207     * @return this object builder
    209      * @throws NumberFormatException if the value is Not-a-Number(NaN) or
     208     * @throws NumberFormatException if the value is Not-a-Number (NaN) or
    210209     * infinity
    211210     * @throws NullPointerException if the specified name is null
     
    269268
    270269    /**
     270     * Adds all name/value pairs in the JSON object associated with the specified
     271     * object builder to the JSON object associated with this object builder.
     272     * The newly added name/value pair will replace any existing name/value pair with
     273     * the same name.
     274     *
     275     * @param builder the specified object builder
     276     * @return this object builder
     277     * @throws NullPointerException if the specified builder is null
     278     * @since 1.1
     279     */
     280    default JsonObjectBuilder addAll(JsonObjectBuilder builder) {
     281        throw new UnsupportedOperationException();
     282    }
     283
     284    /**
     285     * Remove the name/value pair from the JSON object associated with this
     286     * object builder if it is present.
     287     *
     288     * @param name the name in the name/value pair to be removed
     289     * @return this object builder
     290     * @throws NullPointerException if the specified name is null
     291     * @since 1.1
     292     */
     293    default JsonObjectBuilder remove(String name) {
     294        throw new UnsupportedOperationException();
     295    }
     296
     297    /**
    271298     * Returns the JSON object associated with this object builder.
    272299     * The iteration order for the {@code JsonObject} is based
  • trunk/src/javax/json/JsonReader.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    5151 *
    5252 * <p>
    53  * <a id="JsonReaderExample1"/>
    5453 * The following example demonstrates how to read an empty JSON array from
    5554 * a string:
     
    7574 * </code>
    7675 * </pre>
    77  *
    78  * @author Jitendra Kotamraju
    7976 */
    8077public interface JsonReader extends  /*Auto*/Closeable {
     
    9188     * @throws javax.json.stream.JsonParsingException if a JSON object or array
    9289     *     cannot be created due to incorrect representation
    93      * @throws IllegalStateException if read, readObject, readArray or
    94      *     close method is already called
     90     * @throws IllegalStateException if read, readObject, readArray,
     91     *     readValue or close method is already called
    9592     */
    9693    JsonStructure read();
     
    107104     * @throws javax.json.stream.JsonParsingException if a JSON object cannot
    108105     *     be created due to incorrect representation
    109      * @throws IllegalStateException if read, readObject, readArray or
    110      *     close method is already called
     106     * @throws IllegalStateException if read, readObject, readArray,
     107     *     readValue or close method is already called
    111108     */
    112109    JsonObject readObject();
     
    123120     * @throws javax.json.stream.JsonParsingException if a JSON array cannot
    124121     *     be created due to incorrect representation
    125      * @throws IllegalStateException if read, readObject, readArray or
    126      *     close method is already called
     122     * @throws IllegalStateException if read, readObject, readArray,
     123     *     readValue or close method is already called
    127124     */
    128125    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    }
    129146
    130147    /**
  • trunk/src/javax/json/JsonReaderFactory.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    6868 * <p> All the methods in this class are safe for use by multiple concurrent
    6969 * threads.
    70  *
    71  * @author Jitendra Kotamraju
    7270 */
    7371public interface JsonReaderFactory {
     
    8583     * Creates a JSON reader from a byte stream. The character encoding of
    8684     * the stream is determined as described in
    87      * <a href="http://tools.ietf.org/rfc/rfc4627.txt">RFC 4627</a>.
     85     * <a href="http://tools.ietf.org/rfc/rfc7159.txt">RFC 7159</a>.
    8886     * The reader is configured with the factory configuration.
    8987     *
  • trunk/src/javax/json/JsonString.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2011-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2011-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    4343/**
    4444 * An immutable JSON string value.
    45  *
    46  * @author Jitendra Kotamraju
    4745 */
    4846public interface JsonString extends JsonValue {
  • trunk/src/javax/json/JsonStructure.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    4444 * Super type for the two structured types in JSON ({@link JsonObject object}s
    4545 * and {@link JsonArray array}s).
    46  *
    47  * @author Jitendra Kotamraju
    4846 */
    4947public interface JsonStructure extends JsonValue {
     48
     49    /**
     50     * Get the value referenced by the provided JSON Pointer in the JsonStructure.
     51     *
     52     * @param jsonPointer the JSON Pointer
     53     * @return the {@code JsonValue} at the referenced location
     54     * @throws JsonException if the JSON Pointer is malformed, or if it references
     55     *     a non-existing member or value.
     56     *
     57     * @since 1.1
     58     */
     59    default public JsonValue getValue(String jsonPointer) {
     60        return Json.createPointer(jsonPointer).getValue(this);
     61    }
    5062}
  • trunk/src/javax/json/JsonValue.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2011-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2011-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    4444 * <code>JsonValue</code> represents an immutable JSON value.
    4545 *
    46  * 
     46 *
    4747 * <p>A JSON value is one of the following:
    4848 * an object ({@link JsonObject}), an array ({@link JsonArray}),
    4949 * a number ({@link JsonNumber}), a string ({@link JsonString}),
    50  * {@code true} ({@link JsonValue#TRUE JsonValue.TRUE}), {@code false} 
     50 * {@code true} ({@link JsonValue#TRUE JsonValue.TRUE}), {@code false}
    5151 * ({@link JsonValue#FALSE JsonValue.FALSE}),
    5252 * or {@code null} ({@link JsonValue#NULL JsonValue.NULL}).
    53  *
    54  * @author Jitendra Kotamraju
    5553 */
    5654public interface JsonValue {
     55
     56    /**
     57     * The empty JSON object.
     58     *
     59     * @since 1.1
     60     */
     61    static final JsonObject EMPTY_JSON_OBJECT = new EmptyObject();
     62
     63    /**
     64     * The empty JSON array.
     65     *
     66     * @since 1.1
     67     */
     68    static final JsonArray EMPTY_JSON_ARRAY = new EmptyArray();
    5769
    5870    /**
     
    99111     * JSON null value.
    100112     */
    101     static final JsonValue NULL = new JsonValue() {
    102         @Override
    103         public ValueType getValueType() {
    104             return ValueType.NULL;
    105         }
    106 
    107         /**
    108          * Compares the specified object with this {@link JsonValue#NULL}
    109          * object for equality. Returns {@code true} if and only if the
    110          * specified object is also a {@code JsonValue}, and their
    111          * {@link #getValueType()} objects are <i>equal</i>.
    112          *
    113          * @param obj the object to be compared for equality with this
    114          *      {@code JsonValue}
    115          * @return {@code true} if the specified object is equal to this
    116          *      {@code JsonValue}
    117          */
    118         @Override
    119         public boolean equals(Object obj) {
    120             if (obj instanceof JsonValue) {
    121                 return getValueType().equals(((JsonValue)obj).getValueType());
    122             }
    123             return false;
    124         }
    125 
    126         /**
    127          * Returns the hash code value for this {@link JsonValue#NULL} object.
    128          * The hash code of the {@link JsonValue#NULL} object is defined to be
    129          * its {@link #getValueType()} object's hash code.
    130          *
    131          * @return the hash code value for this JsonString object
    132          */
    133         @Override
    134         public int hashCode() {
    135             return ValueType.NULL.hashCode();
    136         }
    137 
    138         /**
    139          * Returns a "null" string.
    140          *
    141          * @return "null"
    142          */
    143         @Override
    144         public String toString() {
    145             return "null";
    146         }
    147     };
     113    static final JsonValue NULL = new JsonValueImpl(ValueType.NULL);
    148114
    149115    /**
    150116     * JSON true value.
    151117     */
    152     static final JsonValue TRUE = new JsonValue() {
    153         @Override
    154         public ValueType getValueType() {
    155             return ValueType.TRUE;
    156         }
    157 
    158         /**
    159          * Compares the specified object with this {@link JsonValue#TRUE}
    160          * object for equality. Returns {@code true} if and only if the
    161          * specified object is also a JsonValue, and their
    162          * {@link #getValueType()} objects are <i>equal</i>.
    163          *
    164          * @param obj the object to be compared for equality with this JsonValue.
    165          * @return {@code true} if the specified object is equal to this JsonValue.
    166          */
    167         @Override
    168         public boolean equals(Object obj) {
    169             if (obj instanceof JsonValue) {
    170                 return getValueType().equals(((JsonValue)obj).getValueType());
    171             }
    172             return false;
    173         }
    174 
    175         /**
    176          * Returns the hash code value for this {@link JsonValue#TRUE} object.
    177          * The hash code of the {@link JsonValue#TRUE} object is defined to be
    178          * its {@link #getValueType()} object's hash code.
    179          *
    180          * @return the hash code value for this JsonString object
    181          */
    182         @Override
    183         public int hashCode() {
    184             return ValueType.TRUE.hashCode();
    185         }
    186 
    187         /**
    188          * Returns "true" string
    189          *
    190          * @return "true"
    191          */
    192         @Override
    193         public String toString() {
    194             return "true";
    195         }
    196     };
     118    static final JsonValue TRUE = new JsonValueImpl(ValueType.TRUE);
    197119
    198120    /**
    199      * JSON false value
     121     * JSON false value.
    200122     */
    201     static final JsonValue FALSE = new JsonValue() {
    202         @Override
    203         public ValueType getValueType() {
    204             return ValueType.FALSE;
    205         }
    206 
    207         /**
    208          * Compares the specified object with this {@link JsonValue#FALSE}
    209          * object for equality. Returns {@code true} if and only if the
    210          * specified object is also a JsonValue, and their
    211          * {@link #getValueType()} objects are <i>equal</i>.
    212          *
    213          * @param obj the object to be compared for equality with this JsonValue
    214          * @return {@code true} if the specified object is equal to this JsonValue
    215          */
    216         @Override
    217         public boolean equals(Object obj) {
    218             if (obj instanceof JsonValue) {
    219                 return getValueType().equals(((JsonValue)obj).getValueType());
    220             }
    221             return false;
    222         }
    223 
    224         /**
    225          * Returns the hash code value for this {@link JsonValue#FALSE} object.
    226          * The hash code of the {@link JsonValue#FALSE} object is defined to be
    227          * its {@link #getValueType()} object's hash code.
    228          *
    229          * @return the hash code value for this JsonString object
    230          */
    231         @Override
    232         public int hashCode() {
    233             return ValueType.FALSE.hashCode();
    234         }
    235 
    236         /**
    237          * Returns "false" string
    238          *
    239          * @return "false"
    240          */
    241         @Override
    242         public String toString() {
    243             return "false";
    244         }
    245     };
     123    static final JsonValue FALSE = new JsonValueImpl(ValueType.FALSE);
    246124
    247125    /**
     
    251129     */
    252130    ValueType getValueType();
     131
     132    /**
     133     * Return the JsonValue as a JsonObject
     134     *
     135     * @return the JsonValue as a JsonObject
     136     * @throws ClassCastException if the JsonValue is not a JsonObject
     137     *
     138     * @since 1.1
     139     */
     140    default JsonObject asJsonObject() {
     141        return JsonObject.class.cast(this);
     142    }
     143
     144    /**
     145     * Return the JsonValue as a JsonArray
     146     *
     147     * @return the JsonValue as a JsonArray
     148     * @throws ClassCastException if the JsonValue is not a JsonArray
     149     *
     150     * @since 1.1
     151     */
     152    default JsonArray asJsonArray() {
     153        return JsonArray.class.cast(this);
     154    }
    253155
    254156    /**
  • trunk/src/javax/json/JsonWriter.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    5151 *
    5252 * <p>
    53  * <a id="JsonWriterExample1"/>
    5453 * The following example demonstrates how write an empty JSON object:
    5554 * <pre>
     
    7473 * </code>
    7574 * </pre>
    76  *
    77  * @author Jitendra Kotamraju
    7875 */
    7976public interface JsonWriter extends  /*Auto*/Closeable {
     
    126123     * cause of JsonException)
    127124     */
     125
     126    /**
     127     * Writes the specified {@link JsonValue} to the output source.
     128     * method needs to be called only once for a write instance.
     129     *
     130     * @param value a {@code JsonValue} to be written to the output
     131     *              source
     132     * @throws JsonException if the specified JSON object cannot be
     133     *     written due to i/o error (IOException would be cause of
     134     *     JsonException)
     135     * @throws IllegalStateException if writeArray, writeObject, write
     136     *     or close method is already called
     137     *
     138     * @since 1.1
     139     */
     140    default void write(JsonValue value) {
     141        throw new UnsupportedOperationException();
     142    }
     143
    128144    @Override
    129145    void close();
  • trunk/src/javax/json/JsonWriterFactory.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    6868 * <p> All the methods in this class are safe for use by multiple concurrent
    6969 * threads.
    70  *
    71  * @author Jitendra Kotamraju
    7270 */
    7371public interface JsonWriterFactory {
  • trunk/src/javax/json/package-info.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2011-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2011-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    5151 * ordered sequence of zero or more values from the model.
    5252 *
    53  * <p>The object model API uses builder patterns to create these object models.
    54  * The classes {@link javax.json.JsonObjectBuilder} and
    55  * {@link javax.json.JsonArrayBuilder} provide methods to create models
     53 * <p>The object model API uses builder patterns to create and modify
     54 * these object models. The classes {@link javax.json.JsonObjectBuilder} and
     55 * {@link javax.json.JsonArrayBuilder} provide methods to create and modify models
    5656 * of type {@code JsonObject} and {@code JsonArray} respectively.
    5757 *
     
    5959 * the class {@link javax.json.JsonReader}. Similarly, these object models
    6060 * can be written to an output source using the class {@link javax.json.JsonWriter}.
    61  *
    62  * @since JSON Processing 1.0
    63  * @author Jitendra Kotamraju
     61 * <p>
     62 * This package includes several classes that implement other JSON related
     63 * standards: <a href="http://tools.ietf.org/html/rfc6901">JSON Pointer</a>,
     64 * <a Href="http://tools.ietf.org/html/rfc6902">JSON Patch</a>, and
     65 * <a Href="http://tools.ietf.org/html/rfc7396">JSON Merge Patch</a>.
     66 * They can be used to retrieve, transform or manipulate values in an
     67 * object model.
    6468 */
    6569package javax.json;
  • trunk/src/javax/json/spi/JsonProvider.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2011-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2011-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    5050import java.io.Reader;
    5151import java.io.Writer;
     52import java.util.Collection;
    5253import java.util.Iterator;
    5354import java.util.Map;
    5455import java.util.ServiceLoader;
     56import java.math.BigDecimal;
     57import java.math.BigInteger;
     58import java.util.Optional;
    5559
    5660/**
     
    6165 *
    6266 * @see ServiceLoader
    63  * @author Jitendra Kotamraju
    6467 */
    6568public abstract class JsonProvider {
     
    7679
    7780    /**
    78      *
    7981     * Creates a JSON provider object. The provider is loaded using the
    8082     * {@link ServiceLoader#load(Class)} method. If there are no available
    8183     * service providers, this method returns the default service provider.
     84     * Users are recommended to cache the result of this method.
    8285     *
    8386     * @see ServiceLoader
     
    9093            return it.next();
    9194        }
    92 
    9395        try {
    9496            Class<?> clazz = Class.forName(DEFAULT_PROVIDER);
    95             return (JsonProvider)clazz.newInstance();
     97            return (JsonProvider) clazz.newInstance();
    9698        } catch (ClassNotFoundException x) {
    9799            throw new JsonException(
     
    115117     * Creates a JSON parser from the specified byte stream.
    116118     * The character encoding of the stream is determined
    117      * as defined in <a href="http://tools.ietf.org/rfc/rfc4627.txt">RFC 4627
     119     * as defined in <a href="http://tools.ietf.org/rfc/rfc7159.txt">RFC 7159
    118120     * </a>.
    119121     *
     
    193195     * Creates a JSON reader from a byte stream. The character encoding of
    194196     * the stream is determined as described in
    195      * <a href="http://tools.ietf.org/rfc/rfc4627.txt">RFC 4627</a>.
     197     * <a href="http://tools.ietf.org/rfc/rfc7159.txt">RFC 7159</a>.
    196198     *
    197199     * @param in a byte stream from which JSON is to be read
     
    246248
    247249    /**
    248      * Creates a JSON object builder
     250     * Creates a JSON object builder.
    249251     *
    250252     * @return a JSON object builder
     
    253255
    254256    /**
    255      * Creates a JSON array builder
     257     * Creates a JSON object builder, initialized with the specified object.
     258     *
     259     * @param object the initial JSON object in the builder
     260     * @return a JSON object builder
     261     *
     262     * @since 1.1
     263     */
     264    public JsonObjectBuilder createObjectBuilder(JsonObject object) {
     265        throw new UnsupportedOperationException();
     266    }
     267
     268    /**
     269     * Creates a JSON object builder, initialized with the data from specified {@code map}.
     270     * If the @{code map} contains {@link Optional}s then resulting JSON object builder
     271     * contains the key from the {@code map} only if the {@link Optional} is not empty.
     272     *
     273     * @param map the initial object in the builder
     274     * @return a JSON object builder
     275     * @exception IllegalArgumentException if the value from the {@code map} cannot be converted
     276     *            to the corresponding {@link JsonValue}
     277     *
     278     * @since 1.1
     279     */
     280    public JsonObjectBuilder createObjectBuilder(Map<String, Object> map) {
     281        throw new UnsupportedOperationException();
     282    }
     283
     284    /**
     285     * Creates a JSON array builder.
    256286     *
    257287     * @return a JSON array builder
    258288     */
    259289    public abstract JsonArrayBuilder createArrayBuilder();
     290
     291    /**
     292     * Creates a JSON array builder, initialized with the specified array.
     293     *
     294     * @param array the initial JSON array in the builder
     295     * @return a JSON array builder
     296     *
     297     * @since 1.1
     298     */
     299    public JsonArrayBuilder createArrayBuilder(JsonArray array) {
     300        throw new UnsupportedOperationException();
     301    }
     302
     303    /**
     304     * Creates JSON Pointer (<a href="http://tools.ietf.org/html/rfc6901">RFC 6901</a>)
     305     * from given {@code jsonPointer} string.
     306     * <ul>
     307     *     <li>An empty {@code jsonPointer} string defines a reference to the target itself.</li>
     308     *     <li>If the {@code jsonPointer} string is non-empty, it must be a sequence of '{@code /}' prefixed tokens.</li>
     309     * </ul>
     310     *
     311     * @param jsonPointer the JSON Pointer string
     312     * @throws NullPointerException if {@code jsonPointer} is {@code null}
     313     * @throws JsonException if {@code jsonPointer} is not a valid JSON Pointer
     314     * @return a JSON Pointer
     315     *
     316     * @since 1.1
     317     */
     318    public JsonPointer createPointer(String jsonPointer) {
     319        throw new UnsupportedOperationException();
     320    }
     321
     322    /**
     323     * Creates a JSON Patch builder (<a href="http://tools.ietf.org/html/rfc6902">RFC 6902</a>).
     324     *
     325     * @return a JSON Patch builder
     326     *
     327     * @since 1.1
     328     */
     329    public JsonPatchBuilder createPatchBuilder() {
     330        throw new UnsupportedOperationException();
     331    }
     332
     333    /**
     334     * Creates a JSON Patch builder
     335     * (<a href="http://tools.ietf.org/html/rfc6902">RFC 6902</a>),
     336     * initialized with the specified operations.
     337     *
     338     * @param array the initial patch operations
     339     * @return a JSON Patch builder
     340     *
     341     * @since 1.1
     342     */
     343    public JsonPatchBuilder createPatchBuilder(JsonArray array) {
     344        throw new UnsupportedOperationException();
     345    }
     346
     347    /**
     348     * Creates a JSON Patch (<a href="http://tools.ietf.org/html/rfc6902">RFC 6902</a>)
     349     * from the specified operations.
     350     *
     351     * @param array patch operations
     352     * @return a JSON Patch
     353     *
     354     * @since 1.1
     355     */
     356    public JsonPatch createPatch(JsonArray array) {
     357        throw new UnsupportedOperationException();
     358    }
     359
     360    /**
     361     * Generates a JSON Patch (<a href="http://tools.ietf.org/html/rfc6902">RFC 6902</a>)
     362     * from the source and target {@code JsonStructure}.
     363     * The generated JSON Patch need not be unique.
     364     *
     365     * @param source the source
     366     * @param target the target, must be the same type as the source
     367     * @return a JSON Patch which when applied to the source, yields the target
     368     *
     369     * @since 1.1
     370     */
     371    public JsonPatch createDiff(JsonStructure source, JsonStructure target) {
     372        throw new UnsupportedOperationException();
     373    }
     374
     375    /**
     376     * Creates JSON Merge Patch (<a href="http://tools.ietf.org/html/rfc7396">RFC 7396</a>)
     377     * from specified {@code JsonValue}.
     378     *
     379     * @param patch the patch
     380     * @return a JSON Merge Patch
     381     *
     382     * @since 1.1
     383     */
     384    public JsonMergePatch createMergePatch(JsonValue patch) {
     385        throw new UnsupportedOperationException();
     386    }
     387
     388    /**
     389     * Generates a JSON Merge Patch (<a href="http://tools.ietf.org/html/rfc7396">RFC 7396</a>)
     390     * from the source and target {@code JsonValue}s
     391     * which when applied to the {@code source}, yields the {@code target}.
     392     *
     393     * @param source the source
     394     * @param target the target
     395     * @return a JSON Merge Patch
     396     *
     397     * @since 1.1
     398     */
     399    public JsonMergePatch createMergeDiff(JsonValue source, JsonValue target) {
     400        throw new UnsupportedOperationException();
     401    }
     402
     403    /**
     404     * Creates a JSON array builder, initialized with the content of specified {@code collection}.
     405     * If the @{code collection} contains {@link Optional}s then resulting JSON array builder
     406     * contains the value from the {@code collection} only if the {@link Optional} is not empty.
     407     *
     408     * @param collection the initial data for the builder
     409     * @return a JSON array builder
     410     * @exception IllegalArgumentException if the value from the {@code collection} cannot be converted
     411     *            to the corresponding {@link JsonValue}
     412     *
     413     * @since 1.1
     414     */
     415    public JsonArrayBuilder createArrayBuilder(Collection<?> collection) {
     416        throw new UnsupportedOperationException();
     417    }
     418
    260419
    261420    /**
     
    272431    public abstract JsonBuilderFactory createBuilderFactory(Map<String,?> config);
    273432
     433    /**
     434     * Creates a JsonString.
     435     *
     436     * @param value a JSON string
     437     * @return the JsonString for the string
     438     *
     439     * @since 1.1
     440     */
     441    public JsonString createValue(String value) {
     442        throw new UnsupportedOperationException();
     443    }
     444
     445    /**
     446     * Creates a JsonNumber.
     447     *
     448     * @param value a JSON number
     449     * @return the JsonNumber for the number
     450     *
     451     * @since 1.1
     452     */
     453    public JsonNumber createValue(int value) {
     454        throw new UnsupportedOperationException();
     455    }
     456
     457    /**
     458     * Creates a JsonNumber.
     459     *
     460     * @param value a JSON number
     461     * @return the JsonNumber for the number
     462     *
     463     * @since 1.1
     464     */
     465    public JsonNumber createValue(long value) {
     466        throw new UnsupportedOperationException();
     467    }
     468
     469    /**
     470     * Creates a JsonNumber.
     471     *
     472     * @param value a JSON number
     473     * @return the JsonNumber for the number
     474     *
     475     * @since 1.1
     476     */
     477    public JsonNumber createValue(double value) {
     478        throw new UnsupportedOperationException();
     479    }
     480
     481    /**
     482     * Creates a JsonNumber.
     483     *
     484     * @param value a JSON number
     485     * @return the JsonNumber for the number
     486     *
     487     * @since 1.1
     488     */
     489    public JsonNumber createValue(BigDecimal value) {
     490        throw new UnsupportedOperationException();
     491    }
     492
     493    /**
     494     * Creates a JsonNumber.
     495     *
     496     * @param value a JSON number
     497     * @return the JsonNumber for the number
     498     *
     499     * @since 1.1
     500     */
     501    public JsonNumber createValue(BigInteger value) {
     502        throw new UnsupportedOperationException();
     503    }
    274504}
  • trunk/src/javax/json/spi/package-info.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    5353 *
    5454 * @since JSON Processing 1.0
    55  * @author Jitendra Kotamraju
    5655 */
    5756package javax.json.spi;
  • trunk/src/javax/json/stream/JsonGenerationException.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    4646 * {@code JsonGenerationException} indicates an incorrect JSON is
    4747 * being generated.
    48  *
    49  * @author Jitendra Kotamraju
    5048 */
    5149public class JsonGenerationException extends JsonException {
  • trunk/src/javax/json/stream/JsonGenerator.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2011-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2011-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    9898 * </pre>
    9999 *
     100 * <p>
     101 * Other JSON values (that are not JSON objects or arrays) can be created
     102 * by calling the appropiate {@code write} methods.
     103 * <p>
     104 * The following example shows how to generate a JSON string:
     105 * <pre><code>
     106 * JsonGenerator generator = ...;
     107 * generator.write("message").close();
     108 * </code></pre>
     109 *
    100110 * {@code JsonGenerator} methods can be chained as in the following example:
    101  * <p>
    102  * <a id="JsonGeneratorExample3"/>
    103111 * <pre>
    104112 * <code>
     
    130138 *
    131139 * The example code above generates the following JSON (or equivalent):
    132  * <p>
    133140 * <pre>
    134141 * <code>
     
    150157 *
    151158 * The generated JSON text must strictly conform to the grammar defined in
    152  * <a href="http://www.ietf.org/rfc/rfc4627.txt">RFC 4627</a>.
     159 * <a href="http://www.ietf.org/rfc/rfc7159.txt">RFC 7159</a>.
    153160 *
    154161 * @see javax.json.Json
    155162 * @see JsonGeneratorFactory
    156  * @author Jitendra Kotamraju
    157163 */
    158164public interface JsonGenerator extends Flushable, /*Auto*/Closeable {
     
    167173     * Writes the JSON start object character. It starts a new child object
    168174     * context within which JSON name/value pairs can be written to the object.
    169      * This method is valid only in an array context or in no context (when a
     175     * This method is valid only in an array context, field context or in no context (when a
    170176     * context is not yet started). This method can only be called once in
    171177     * no context.
     
    174180     * @throws javax.json.JsonException if an i/o error occurs (IOException
    175181     * would be cause of JsonException)
    176      * @throws JsonGenerationException if this method is called within an 
     182     * @throws JsonGenerationException if this method is called within an
    177183     *      object context or if it is called more than once in no context.
    178184     */
     
    188194     * @throws javax.json.JsonException if an i/o error occurs (IOException
    189195     * would be cause of JsonException)
    190      * @throws JsonGenerationException if this method is not called within an 
     196     * @throws JsonGenerationException if this method is not called within an
    191197     *     object context
    192198     */
    193199    JsonGenerator writeStartObject(String name);
     200
     201    /**
     202     * Writes the JSON name with a colon. It starts a field context, in which valid
     203     * options are writing a value, starting an object or an array.
     204     *
     205     * Writing value closes field context, if object or array is started after field name,
     206     * field context will be closed after object/array close.
     207     *
     208     * @param name name of json field
     209     * @return this generator
     210     * @throws javax.json.JsonException if an i/o error occurs (IOException
     211     * would be cause of JsonException)
     212     * @throws JsonGenerationException if this method is not called within an
     213     *     object context
     214     *
     215     * @since 1.1
     216     */
     217    JsonGenerator writeKey(String name);
    194218
    195219    /**
    196220     * Writes the JSON start array character. It starts a new child array
    197221     * context within which JSON values can be written to the array. This
    198      * method is valid only in an array context or in no context (when a
     222     * method is valid only in an array context, field context or in no context (when a
    199223     * context is not yet started). This method can only be called once in
    200224     * no context.
     
    203227     * @throws javax.json.JsonException if an i/o error occurs (IOException
    204228     * would be cause of JsonException)
    205      * @throws JsonGenerationException if this method is called within an 
     229     * @throws JsonGenerationException if this method is called within an
    206230     *      object context or if called more than once in no context
    207231     */
     
    217241     * @throws javax.json.JsonException if an i/o error occurs (IOException
    218242     * would be cause of JsonException)
    219      * @throws JsonGenerationException if this method is not called within 
     243     * @throws JsonGenerationException if this method is not called within
    220244     *      an object context
    221245     */
     
    232256     * @throws javax.json.JsonException if an i/o error occurs (IOException
    233257     * would be cause of JsonException)
    234      * @throws JsonGenerationException if this method is not called within an 
     258     * @throws JsonGenerationException if this method is not called within an
    235259     *      object context
    236260     */
     
    248272     * @throws javax.json.JsonException if an i/o error occurs (IOException
    249273     * would be cause of JsonException)
    250      * @throws JsonGenerationException if this method is not called within an 
     274     * @throws JsonGenerationException if this method is not called within an
    251275     *      object context
    252276     */
     
    266290     * @throws javax.json.JsonException if an i/o error occurs (IOException
    267291     * would be cause of JsonException)
    268      * @throws JsonGenerationException if this method is not called within an 
     292     * @throws JsonGenerationException if this method is not called within an
    269293     *      object context.
    270294     */
     
    283307     * @throws javax.json.JsonException if an i/o error occurs (IOException
    284308     * would be cause of JsonException)
    285      * @throws JsonGenerationException if this method is not called within an 
     309     * @throws JsonGenerationException if this method is not called within an
    286310     *      object context.
    287311     */
     
    301325     * @throws javax.json.JsonException if an i/o error occurs (IOException
    302326     * would be cause of JsonException)
    303      * @throws JsonGenerationException if this method is not called within an 
     327     * @throws JsonGenerationException if this method is not called within an
    304328     *      object context.
    305329     */
     
    319343     * @throws javax.json.JsonException if an i/o error occurs (IOException
    320344     * would be cause of JsonException)
    321      * @throws JsonGenerationException if this method is not called within an 
     345     * @throws JsonGenerationException if this method is not called within an
    322346     *      object context.
    323347     */
     
    337361     * @throws javax.json.JsonException if an i/o error occurs (IOException
    338362     * would be cause of JsonException)
    339      * @throws NumberFormatException if the value is Not-a-Number(NaN) or infinity.
     363     * @throws NumberFormatException if the value is Not-a-Number (NaN) or infinity.
    340364     * @throws JsonGenerationException if this method is not called within an
    341365     *      object context
     
    345369    /**
    346370     * Writes a JSON name/boolean value pair in the current object context.
    347      * If value is true, it writes the JSON {@code true} value, otherwise 
     371     * If value is true, it writes the JSON {@code true} value, otherwise
    348372     * it writes the JSON {@code false} value.
    349373     *
     
    369393     * @throws javax.json.JsonException if an i/o error occurs (IOException
    370394     * would be cause of JsonException)
    371      * @throws JsonGenerationException if this method is not called within an 
     395     * @throws JsonGenerationException if this method is not called within an
    372396     *      object context
    373397     */
     
    376400    /**
    377401     * Writes the end of the current context. If the current context is
    378      * an array context, this method writes the end-of-array character (']'). 
     402     * an array context, this method writes the end-of-array character (']').
    379403     * If the current context is an object context, this method writes the
    380404     * end-of-object character ('}'). After writing the end of the current
    381405     * context, the parent context becomes the new current context.
     406     * If parent context is field context, it is closed.
    382407     *
    383408     * @return this generator
     
    390415    /**
    391416     * Writes the specified value as a JSON value within
    392      * the current array context.
    393      *
    394      * @param value a value to be written in current JSON array
    395      * @return this generator
    396      * @throws javax.json.JsonException if an i/o error occurs (IOException
    397      * would be cause of JsonException)
    398      * @throws JsonGenerationException if this method is not called within an 
    399      *      array context.
     417     * the current array, field or root context.
     418     *
     419     * @param value a value to be written in current JSON array
     420     * @return this generator
     421     * @throws javax.json.JsonException if an i/o error occurs (IOException
     422     * would be cause of JsonException)
     423     * @throws JsonGenerationException if this method is not called within an
     424     *      array or root context.
    400425     */
    401426    JsonGenerator write(JsonValue value);
     
    403428    /**
    404429     * Writes the specified value as a JSON string value within
    405      * the current array context.
    406      *
    407      * @param value a value to be written in current JSON array
    408      * @return this generator
    409      * @throws javax.json.JsonException if an i/o error occurs (IOException
    410      * would be cause of JsonException)
    411      * @throws JsonGenerationException if this method is not called within an 
    412      *      array context
     430     * the current array, field or root context.
     431     *
     432     * @param value a value to be written in current JSON array
     433     * @return this generator
     434     * @throws javax.json.JsonException if an i/o error occurs (IOException
     435     * would be cause of JsonException)
     436     * @throws JsonGenerationException if this method is not called within an
     437     *      array or root context.
    413438     */
    414439    JsonGenerator write(String value);
     
    416441    /**
    417442     * Writes the specified value as a JSON number value within
    418      * the current array context. The specified value's {@code toString()}
     443     * the current array, field or root context. The specified value's {@code toString()}
    419444     * is used as the the text value for writing.
    420445     *
     
    423448     * @throws javax.json.JsonException if an i/o error occurs (IOException
    424449     * would be cause of JsonException)
    425      * @throws JsonGenerationException if this method is not called within an 
    426      *      array context
     450     * @throws JsonGenerationException if this method is not called within an
     451     *      array or root context.
    427452     *
    428453     * @see javax.json.JsonNumber
     
    432457    /**
    433458     * Writes the specified value as a JSON number value within
    434      * the current array context. The string {@code new BigDecimal(value).toString()}
     459     * the current array, field or root context. The string {@code new BigDecimal(value).toString()}
    435460     * is used as the text value for writing.
    436461     *
     
    439464     * @throws javax.json.JsonException if an i/o error occurs (IOException
    440465     * would be cause of JsonException)
    441      * @throws JsonGenerationException if this method is not called within an 
    442      *      array context
     466     * @throws JsonGenerationException if this method is not called within an
     467     *      array or root context.
    443468     *
    444469     * @see javax.json.JsonNumber
     
    448473    /**
    449474     * Writes the specified value as a JSON number value within
    450      * the current array context. The string {@code new BigDecimal(value).toString()}
     475     * the current array, field or root context. The string {@code new BigDecimal(value).toString()}
    451476     * is used as the text value for writing.
    452477     *
     
    455480     * @throws javax.json.JsonException if an i/o error occurs (IOException
    456481     * would be cause of JsonException)
    457      * @throws JsonGenerationException if this method is not called within an 
    458      *      array context
     482     * @throws JsonGenerationException if this method is not called within an
     483     *      array or root context.
    459484     */
    460485    JsonGenerator write(int value);
     
    462487    /**
    463488     * Writes the specified value as a JSON number value within
    464      * the current array context. The string {@code new BigDecimal(value).toString()}
     489     * the current array, field or root context. The string {@code new BigDecimal(value).toString()}
    465490     * is used as the text value for writing.
    466491     *
     
    469494     * @throws javax.json.JsonException if an i/o error occurs (IOException
    470495     * would be cause of JsonException)
    471      * @throws JsonGenerationException if this method is not called within an 
    472      *      array context
     496     * @throws JsonGenerationException if this method is not called within an
     497     *      array or root context.
    473498     */
    474499    JsonGenerator write(long value);
     
    476501    /**
    477502     * Writes the specified value as a JSON number value within the current
    478      * array context. The string {@code BigDecimal.valueOf(value).toString()}
     503     * array, field or root context. The string {@code BigDecimal.valueOf(value).toString()}
    479504     * is used as the text value for writing.
    480505     *
     
    483508     * @throws javax.json.JsonException if an i/o error occurs (IOException
    484509     * would be cause of JsonException)
    485      * @throws JsonGenerationException if this method is not called within an 
    486      *      array context
    487      * @throws NumberFormatException if the value is Not-a-Number(NaN) or infinity.
     510     * @throws JsonGenerationException if this method is not called within an
     511     *      array or root context.
     512     * @throws NumberFormatException if the value is Not-a-Number (NaN) or infinity.
    488513     */
    489514    JsonGenerator write(double value);
    490515
    491516    /**
    492      * Writes a JSON true or false value within the current array context.
    493      * If value is true, this method writes the JSON {@code true} value, 
     517     * Writes a JSON true or false value within the current array, field or root context.
     518     * If value is true, this method writes the JSON {@code true} value,
    494519     * otherwise it writes the JSON {@code false} value.
    495520     *
     
    498523     * @throws javax.json.JsonException if an i/o error occurs (IOException
    499524     * would be cause of JsonException)
    500      * @throws JsonGenerationException if this method is not called within an 
    501      *      array context.
     525     * @throws JsonGenerationException if this method is not called within an
     526     *      array or root context.
    502527     */
    503528    JsonGenerator write(boolean value);
    504529
    505530    /**
    506      * Writes a JSON null value within the current array context.
    507      *
    508      * @return this generator
    509      * @throws javax.json.JsonException if an i/o error occurs (IOException
    510      * would be cause of JsonException)
    511      * @throws JsonGenerationException if this method is not called within an 
    512      *      array context
     531     * Writes a JSON null value within the current array, field or root context.
     532     *
     533     * @return this generator
     534     * @throws javax.json.JsonException if an i/o error occurs (IOException
     535     * would be cause of JsonException)
     536     * @throws JsonGenerationException if this method is not called within an
     537     *      array or root context.
    513538     */
    514539    JsonGenerator writeNull();
    515540
    516541    /**
    517      * Closes this generator and frees any resources associated with it. 
     542     * Closes this generator and frees any resources associated with it.
    518543     * This method closes the underlying output source.
    519544     *
  • trunk/src/javax/json/stream/JsonGeneratorFactory.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2011-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2011-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    6767 * <p> All the methods in this class are safe for use by multiple concurrent
    6868 * threads.
    69  *
    70  * @author Jitendra Kotamraju
    7169 */
    7270public interface JsonGeneratorFactory {
     
    7775     *
    7876     * @param writer i/o writer to which JSON is written
     77     * @return the created JSON generator
    7978     */
    8079    JsonGenerator createGenerator(Writer writer);
     
    8685     *
    8786     * @param out i/o stream to which JSON is written
     87     * @return the created JSON generator
    8888     */
    8989    JsonGenerator createGenerator(OutputStream out);
     
    9696     * @param out i/o stream to which JSON is written
    9797     * @param charset a charset
     98     * @return the created JSON generator
    9899     */
    99100    JsonGenerator createGenerator(OutputStream out, Charset charset);
  • trunk/src/javax/json/stream/JsonLocation.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    5252 * {@link javax.json.JsonArray JsonArray} input source, all the methods in
    5353 * this class return -1.
    54  *
    55  * @author Jitendra Kotamraju
    5654 * @see JsonParser
    5755 * @see JsonParsingException
     
    6058
    6159    /**
    62      * Return the line number for the current JSON event in the input source.
     60     * Return the line number (starts with 1 for the first line) for the current JSON event in the input source.
    6361     *
    64      * @return the line number or -1 if none is available
     62     * @return the line number (starts with 1 for the first line) or -1 if none is available
    6563     */
    6664    long getLineNumber();
    6765
    6866    /**
    69      * Return the column number for the current JSON event in the input source.
     67     * Return the column number (starts with 1 for the first column) for the current JSON event in the input source.
    7068     *
    71      * @return the column number or -1 if none is available
     69     * @return the column number (starts with 1 for the first column) or -1 if none is available
    7270     */
    7371    long getColumnNumber();
  • trunk/src/javax/json/stream/JsonParser.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2011-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2011-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    4444import java.io.Closeable;
    4545import java.math.BigDecimal;
     46import java.util.stream.Stream;
     47import java.util.Map;
     48
     49import javax.json.JsonValue;
     50import javax.json.JsonObject;
     51import javax.json.JsonArray;
    4652
    4753/**
    4854 * Provides forward, read-only access to JSON data in a streaming way. This
    49  * is the most efficient way for reading JSON data. The class
     55 * is the most efficient way for reading JSON data.
     56 * This is the only way to parse and process JSON data that are too big to be loaded in memory.
     57 * <p>The class
    5058 * {@link javax.json.Json} contains methods to create parsers from input
    5159 * sources ({@link java.io.InputStream} and {@link java.io.Reader}).
     
    97105 *
    98106 * <p>
    99  * <a id="JsonParserExample2"/>
    100  * <p>
    101107 * <b>For example</b>, for the following JSON:
    102108 * <pre>
     
    113119 * locations below (marked in bold):
    114120 *
    115  * <p>
    116121 * <pre>
    117122 * {<B>START_OBJECT</B>
     
    124129 * </pre>
    125130 *
    126  * <p>
    127  * The methods {@code next()} and {@code hasNext()} enable iteration over
     131 * The methods {@link #next()} and {@link #hasNext()} enable iteration over
    128132 * parser events to process JSON data. {@code JsonParser} provides get methods
    129133 * to obtain the value at the current state of the parser. For example, the
    130134 * following code shows how to obtain the value "John" from the JSON above:
    131135 *
    132  * <p>
    133136 * <pre>
    134137 * <code>
     
    140143 * </pre>
    141144 *
     145 * Starting in version 1.1, it is possible to build a partial JSON object
     146 * model from the stream, at the current parser position.
     147 * The methods {@link #getArray} and {@link #getObject} can be used to read in
     148 * a {@code JsonArray} or {@code JsonObject}.  For example, the following code
     149 * shows how to obtain the phoneNumber in a JsonArray, from the JSON above:
     150 *
     151 * <pre><code>
     152 * while (parser.hasNext() {
     153 *     Event event = parser.next();
     154 *     if (event == JsonParser.Event.KEY_NAME ) {
     155 *         String key = getString();
     156 *         event = parser.next();
     157 *         if (key.equals("phoneNumber") {
     158 *             JsonArray phones = parser.getArray();
     159 *         }
     160 *     }
     161 * }
     162 * </code></pre>
     163 *
     164 * The methods {@link #getArrayStream} and {@link #getObjectStream} can be used
     165 * to get a stream of the elements of a {@code JsonArray} or {@code JsonObject}.
     166 * For example, the following code shows another way to obtain John's phoneNumber
     167 * in a {@code JsonArray} :
     168 *
     169 * <pre>{@code
     170 * Event event = parser.next(); // START_OBJECT
     171 * JsonArray phones = (JsonArray)
     172 *     parser.getObjectStream().filter(e->e.getKey().equals("phoneNumber"))
     173 *                             .map(e->e.getValue())
     174 *                             .findFirst()
     175 *                             .get();
     176 * }</pre>
     177 *
     178 * The methods {@link #skipArray} and {@link #skipObject} can be used to
     179 * skip tokens and position the parser to {@code END_ARRAY} or
     180 * {@code END_OBJECT}.
     181 * <p>
     182 * {@code JsonParser} can be used to parse sequence of JSON values that are not
     183 * enclosed in a JSON array, e.g. { } { }. The following code demonstrates how
     184 * to parse such sequence.
     185 * <pre><code>
     186 * JsonParser parser = Json.createParser(...);
     187 * while (parser.hasNext) {
     188 *     parser.next(); // advance parser state
     189 *     JsonValue value = parser.getValue();
     190 * }
     191 * </code></pre>
     192 *
    142193 * @see javax.json.Json
    143194 * @see JsonParserFactory
    144  * @author Jitendra Kotamraju
    145195 */
    146196public interface JsonParser extends /*Auto*/Closeable {
     
    223273     * @throws java.util.NoSuchElementException if there are no more parsing
    224274     * states.
     275     * @return the event for the next parsing state
    225276     */
    226277    Event next();
     
    319370
    320371    /**
    321      * getJsonValue(JsonObject.class) is valid in the START_OBJECT state and
    322      * moves the cursor to END_OBJECT.
    323      *
    324      * getJsonValue(JsonArray.class) is valid in the START_ARRAY state
    325      * and moves the cursor to END_ARRAY.
    326      *
    327      * getJsonValue(JsonString.class) is valid in the VALUE_STRING state.
    328      *
    329      * getJsonValue(JsonNumber.class) is valid in the VALUE_NUMBER state.
    330      *
    331      * @param clazz
    332      * @return
    333      *
    334     public <T extends JsonValue> T getJsonValue(Class<T> clazz);
    335      */
     372     * Returns a {@code JsonObject} and advances the parser to the
     373     * corresponding {@code END_OBJECT}.
     374     *
     375     * @return the {@code JsonObject} at the current parser position
     376     *
     377     * @throws IllegalStateException when the parser state is not
     378     *     {@code START_OBJECT}
     379     *
     380     * @since 1.1
     381     */
     382    default public JsonObject getObject() {
     383        throw new UnsupportedOperationException();
     384    }
     385
     386    /**
     387     * Returns a {@code JsonValue} at the current parser position.
     388     * If the parser state is {@code START_ARRAY}, the behavior is
     389     * the same as {@link #getArray}. If the parser state is
     390     * {@code START_OBJECT}, the behavior is the same as
     391     * {@link #getObject}. For all other cases, if applicable, the JSON value is
     392     * read and returned.
     393     *
     394     * @return the {@code JsonValue} at the current parser position.
     395     * @throws IllegalStateException when the parser state is
     396     *     {@code END_OBJECT} or {@code END_ARRAY}
     397     *
     398     * @since 1.1
     399     */
     400    default public JsonValue getValue() {
     401        throw new UnsupportedOperationException();
     402    }
     403
     404    /**
     405     * Returns a {@code JsonArray} and advance the parser to the
     406     * the corresponding {@code END_ARRAY}.
     407     *
     408     * @return the {@code JsonArray} at the current parser position
     409     *
     410     * @throws IllegalStateException when the parser state is not
     411     *     {@code START_ARRAY}
     412     *
     413     * @since 1.1
     414     */
     415    default public JsonArray getArray() {
     416        throw new UnsupportedOperationException();
     417    }
     418
     419    /**
     420     * Returns a stream of the {@code JsonArray} elements.
     421     * The parser state must be {@code START_ARRAY}.
     422     * The elements are read lazily, on an as-needed basis, as
     423     * required by the stream operations.
     424     * If the stream operations do not consume
     425     * all of the array elements, {@link skipArray} can be used to
     426     * skip the unprocessed array elements.
     427     *
     428     * @return a stream of elements of the {@code JsonArray}
     429     *
     430     * @throws IllegalStateException when the parser state is not
     431     *     {@code START_ARRAY}
     432     *
     433     * @since 1.1
     434     */
     435    default public Stream<JsonValue> getArrayStream() {
     436        throw new UnsupportedOperationException();
     437    }
     438
     439    /**
     440     * Returns a stream of the {@code JsonObject}'s
     441     * name/value pairs. The parser state must be {@code START_OBJECT}.
     442     * The name/value pairs are read lazily, on an as-needed basis, as
     443     * required by the stream operations.
     444     * If the stream operations do not consume
     445     * all of the object's name/value pairs, {@link skipObject} can be
     446     * used to skip the unprocessed elements.
     447     *
     448     * @return a stream of name/value pairs of the {@code JsonObject}
     449     *
     450     * @throws IllegalStateException when the parser state is not
     451     *     {@code START_OBJECT}
     452     *
     453     * @since 1.1
     454     */
     455    default public Stream<Map.Entry<String,JsonValue>> getObjectStream() {
     456        throw new UnsupportedOperationException();
     457    }
     458
     459    /**
     460     * Returns a stream of {@code JsonValue} from a sequence of
     461     * JSON values. The values are read lazily, on an as-needed basis,
     462     * as needed by the stream operations.
     463     *
     464     * @return a Stream of {@code JsonValue}
     465     *
     466     * @throws IllegalStateException if the parser is in an array or object.
     467     *
     468     * @since 1.1
     469     */
     470    default public Stream<JsonValue> getValueStream() {
     471        throw new UnsupportedOperationException();
     472    }
     473
     474    /**
     475     * Advance the parser to {@code END_ARRAY}.
     476     * If the parser is in array context, i.e. it has previously
     477     * encountered a {@code START_ARRAY} without encountering the
     478     * corresponding {@code END_ARRAY}, the parser is advanced to
     479     * the corresponding {@code END_ARRAY}.
     480     * If the parser is not in any array context, nothing happens.
     481     *
     482     * @since 1.1
     483     */
     484    default public void skipArray() {
     485        throw new UnsupportedOperationException();
     486    }
     487
     488    /**
     489     * Advance the parser to {@code END_OBJECT}.
     490     * If the parser is in object context, i.e. it has previously
     491     * encountered a {@code START_OBJECT} without encountering the
     492     * corresponding {@code END_OBJECT}, the parser is advanced to
     493     * the corresponding {@code END_OBJECT}.
     494     * If the parser is not in any object context, nothing happens.
     495     *
     496     * @since 1.1
     497     */
     498    default public void skipObject() {
     499        throw new UnsupportedOperationException();
     500    }
    336501
    337502    /**
     
    344509    @Override
    345510    void close();
    346 
    347511}
  • trunk/src/javax/json/stream/JsonParserFactory.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2011-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2011-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    6969 * <p> All the methods in this class are safe for use by multiple concurrent
    7070 * threads.
    71  *
    72  * @author Jitendra Kotamraju
    7371 */
    7472public interface JsonParserFactory {
     
    7876     *
    7977     * @param reader a i/o reader from which JSON is to be read
     78     * @return the created JSON parser
    8079     */
    8180    JsonParser createParser(Reader reader);
     
    8483     * Creates a JSON parser from the specified byte stream.
    8584     * The character encoding of the stream is determined
    86      * as specified in <a href="http://tools.ietf.org/rfc/rfc4627.txt">RFC 4627</a>.
     85     * as specified in <a href="http://tools.ietf.org/rfc/rfc7159.txt">RFC 7159</a>.
    8786     *
    8887     * @param in i/o stream from which JSON is to be read
     88     * @return the created JSON parser
    8989     * @throws javax.json.JsonException if encoding cannot be determined
    9090     *         or i/o error (IOException would be cause of JsonException)
     
    9999     * @param in i/o stream from which JSON is to be read
    100100     * @param charset a charset
     101     * @return the created JSON parser
    101102     */
    102103    JsonParser createParser(InputStream in, Charset charset);
     
    106107     *
    107108     * @param obj a JSON object
     109     * @return the created JSON parser
    108110     */
    109111    JsonParser createParser(JsonObject obj);
     
    113115     *
    114116     * @param array a JSON array
     117     * @return the created JSON parser
    115118     */
    116119    JsonParser createParser(JsonArray array);
  • trunk/src/javax/json/stream/JsonParsingException.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    4646 * {@code JsonParsingException} is used when an incorrect JSON is
    4747 * being parsed.
    48  *
    49  * @author Jitendra Kotamraju
    5048 */
    5149public class JsonParsingException extends JsonException {
  • trunk/src/javax/json/stream/package-info.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    6868 *
    6969 * @since JSON Processing 1.0
    70  * @author Jitendra Kotamraju
    7170 */
    7271package javax.json.stream;
  • trunk/src/org/glassfish/json/BufferPoolImpl.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    8282
    8383        // overwrite the queue
    84         ConcurrentLinkedQueue<char[]> d = new ConcurrentLinkedQueue<char[]>();
    85         queue = new WeakReference<ConcurrentLinkedQueue<char[]>>(d);
     84        ConcurrentLinkedQueue<char[]> d = new ConcurrentLinkedQueue<>();
     85        queue = new WeakReference<>(d);
    8686
    8787        return d;
  • trunk/src/org/glassfish/json/JsonArrayBuilderImpl.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    4949import java.util.AbstractList;
    5050import java.util.ArrayList;
     51import java.util.Collection;
    5152import java.util.Collections;
    5253import java.util.List;
     54import java.util.Optional;
    5355
    5456/**
    55  * JsonArrayBuilder impl
     57 * JsonArrayBuilder implementation
    5658 *
    5759 * @author Jitendra Kotamraju
     60 * @author Kin-man Chung
    5861 */
     62
    5963class JsonArrayBuilderImpl implements JsonArrayBuilder {
    6064    private ArrayList<JsonValue> valueList;
     
    6569    }
    6670
     71    JsonArrayBuilderImpl(JsonArray array, BufferPool bufferPool) {
     72        this.bufferPool = bufferPool;
     73        valueList = new ArrayList<>();
     74        valueList.addAll(array);
     75    }
     76
     77    JsonArrayBuilderImpl(Collection<?> collection, BufferPool bufferPool) {
     78        this.bufferPool = bufferPool;
     79        valueList = new ArrayList<>();
     80        populate(collection);
     81    }
     82
     83    @Override
    6784    public JsonArrayBuilder add(JsonValue value) {
    6885        validateValue(value);
     
    7188    }
    7289
     90    @Override
    7391    public JsonArrayBuilder add(String value) {
    7492        validateValue(value);
     
    7795    }
    7896
     97    @Override
    7998    public JsonArrayBuilder add(BigDecimal value) {
    8099        validateValue(value);
     
    83102    }
    84103
     104    @Override
    85105    public JsonArrayBuilder add(BigInteger value) {
    86106        validateValue(value);
     
    89109    }
    90110
     111    @Override
    91112    public JsonArrayBuilder add(int value) {
    92113        addValueList(JsonNumberImpl.getJsonNumber(value));
     
    94115    }
    95116
     117    @Override
    96118    public JsonArrayBuilder add(long value) {
    97119        addValueList(JsonNumberImpl.getJsonNumber(value));
     
    99121    }
    100122
     123    @Override
    101124    public JsonArrayBuilder add(double value) {
    102125        addValueList(JsonNumberImpl.getJsonNumber(value));
     
    104127    }
    105128
     129    @Override
    106130    public JsonArrayBuilder add(boolean value) {
    107131        addValueList(value ? JsonValue.TRUE : JsonValue.FALSE);
     
    109133    }
    110134
     135    @Override
    111136    public JsonArrayBuilder addNull() {
    112137        addValueList(JsonValue.NULL);
     
    114139    }
    115140
     141    @Override
    116142    public JsonArrayBuilder add(JsonObjectBuilder builder) {
    117143        if (builder == null) {
     
    122148    }
    123149
     150    @Override
    124151    public JsonArrayBuilder add(JsonArrayBuilder builder) {
    125152        if (builder == null) {
     
    130157    }
    131158
     159    @Override
     160    public JsonArrayBuilder addAll(JsonArrayBuilder builder) {
     161        if (builder == null) {
     162            throw new NullPointerException(JsonMessages.ARRBUILDER_ARRAY_BUILDER_NULL());
     163        }
     164        if (valueList == null) {
     165            valueList = new ArrayList<>();
     166        }
     167        valueList.addAll(builder.build());
     168        return this;
     169    }
     170
     171    @Override
     172    public JsonArrayBuilder add(int index, JsonValue value) {
     173        validateValue(value);
     174        addValueList(index, value);
     175        return this;
     176    }
     177
     178    @Override
     179    public JsonArrayBuilder add(int index, String value) {
     180        validateValue(value);
     181        addValueList(index, new JsonStringImpl(value));
     182        return this;
     183    }
     184
     185    @Override
     186    public JsonArrayBuilder add(int index, BigDecimal value) {
     187        validateValue(value);
     188        addValueList(index, JsonNumberImpl.getJsonNumber(value));
     189        return this;
     190    }
     191
     192    @Override
     193    public JsonArrayBuilder add(int index, BigInteger value) {
     194        validateValue(value);
     195        addValueList(index, JsonNumberImpl.getJsonNumber(value));
     196        return this;
     197    }
     198
     199    @Override
     200    public JsonArrayBuilder add(int index, int value) {
     201        addValueList(index, JsonNumberImpl.getJsonNumber(value));
     202        return this;
     203    }
     204
     205    @Override
     206    public JsonArrayBuilder add(int index, long value) {
     207        addValueList(index, JsonNumberImpl.getJsonNumber(value));
     208        return this;
     209    }
     210
     211    @Override
     212    public JsonArrayBuilder add(int index, double value) {
     213        addValueList(index, JsonNumberImpl.getJsonNumber(value));
     214        return this;
     215    }
     216
     217    @Override
     218    public JsonArrayBuilder add(int index, boolean value) {
     219        addValueList(index, value ? JsonValue.TRUE : JsonValue.FALSE);
     220        return this;
     221    }
     222
     223    @Override
     224    public JsonArrayBuilder addNull(int index) {
     225        addValueList(index, JsonValue.NULL);
     226        return this;
     227    }
     228
     229    @Override
     230    public JsonArrayBuilder add(int index, JsonObjectBuilder builder) {
     231        if (builder == null) {
     232            throw new NullPointerException(JsonMessages.ARRBUILDER_OBJECT_BUILDER_NULL());
     233        }
     234        addValueList(index, builder.build());
     235        return this;
     236    }
     237
     238    @Override
     239    public JsonArrayBuilder add(int index, JsonArrayBuilder builder) {
     240        if (builder == null) {
     241            throw new NullPointerException(JsonMessages.ARRBUILDER_OBJECT_BUILDER_NULL());
     242        }
     243        addValueList(index, builder.build());
     244        return this;
     245    }
     246
     247    @Override
     248    public JsonArrayBuilder set(int index, JsonValue value) {
     249        validateValue(value);
     250        setValueList(index, value);
     251        return this;
     252    }
     253
     254    @Override
     255    public JsonArrayBuilder set(int index, String value) {
     256        validateValue(value);
     257        setValueList(index, new JsonStringImpl(value));
     258        return this;
     259    }
     260
     261    @Override
     262    public JsonArrayBuilder set(int index, BigDecimal value) {
     263        validateValue(value);
     264        setValueList(index, JsonNumberImpl.getJsonNumber(value));
     265        return this;
     266    }
     267
     268    @Override
     269    public JsonArrayBuilder set(int index, BigInteger value) {
     270        validateValue(value);
     271        setValueList(index, JsonNumberImpl.getJsonNumber(value));
     272        return this;
     273    }
     274
     275    @Override
     276    public JsonArrayBuilder set(int index, int value) {
     277        setValueList(index, JsonNumberImpl.getJsonNumber(value));
     278        return this;
     279    }
     280
     281    @Override
     282    public JsonArrayBuilder set(int index, long value) {
     283        setValueList(index, JsonNumberImpl.getJsonNumber(value));
     284        return this;
     285    }
     286
     287    @Override
     288    public JsonArrayBuilder set(int index, double value) {
     289        setValueList(index, JsonNumberImpl.getJsonNumber(value));
     290        return this;
     291    }
     292
     293    @Override
     294    public JsonArrayBuilder set(int index, boolean value) {
     295        setValueList(index, value ? JsonValue.TRUE : JsonValue.FALSE);
     296        return this;
     297    }
     298
     299    @Override
     300    public JsonArrayBuilder setNull(int index) {
     301        setValueList(index, JsonValue.NULL);
     302        return this;
     303    }
     304
     305    @Override
     306    public JsonArrayBuilder set(int index, JsonObjectBuilder builder) {
     307        if (builder == null) {
     308            throw new NullPointerException(JsonMessages.ARRBUILDER_OBJECT_BUILDER_NULL());
     309        }
     310        setValueList(index, builder.build());
     311        return this;
     312    }
     313
     314    @Override
     315    public JsonArrayBuilder set(int index, JsonArrayBuilder builder) {
     316        if (builder == null) {
     317            throw new NullPointerException(JsonMessages.ARRBUILDER_OBJECT_BUILDER_NULL());
     318        }
     319        setValueList(index, builder.build());
     320        return this;
     321    }
     322
     323    @Override
     324    public JsonArrayBuilder remove(int index) {
     325        if (valueList == null) {
     326            throw new IndexOutOfBoundsException(JsonMessages.ARRBUILDER_VALUELIST_NULL(index, 0));
     327        }
     328        valueList.remove(index);
     329        return this;
     330    }
     331
     332    @Override
    132333    public JsonArray build() {
    133334        List<JsonValue> snapshot;
     
    143344    }
    144345
     346    private void populate(Collection<?> collection) {
     347        for (Object value : collection) {
     348            if (value != null && value instanceof Optional) {
     349                ((Optional<?>) value).ifPresent(v ->
     350                        this.valueList.add(MapUtil.handle(v, bufferPool)));
     351            } else {
     352                this.valueList.add(MapUtil.handle(value, bufferPool));
     353            }
     354        }
     355    }
     356
    145357    private void addValueList(JsonValue value) {
    146358        if (valueList == null) {
    147             valueList = new ArrayList<JsonValue>();
     359            valueList = new ArrayList<>();
    148360        }
    149361        valueList.add(value);
     362    }
     363
     364    private void addValueList(int index, JsonValue value) {
     365        if (valueList == null) {
     366            valueList = new ArrayList<>();
     367        }
     368        valueList.add(index, value);
     369    }
     370
     371    private void setValueList(int index, JsonValue value) {
     372        if (valueList == null) {
     373            throw new IndexOutOfBoundsException(JsonMessages.ARRBUILDER_VALUELIST_NULL(index, 0));
     374        }
     375        valueList.set(index, value);
    150376    }
    151377
     
    263489        public String toString() {
    264490            StringWriter sw = new StringWriter();
    265             JsonWriter jw = new JsonWriterImpl(sw, bufferPool);
    266             jw.write(this);
    267             jw.close();
     491            try (JsonWriter jw = new JsonWriterImpl(sw, bufferPool)) {
     492                jw.write(this);
     493            }
    268494            return sw.toString();
    269495        }
    270     }
    271 
     496
     497        @Override
     498        public JsonArray asJsonArray() {
     499            return this;
     500        }
     501    }
    272502}
    273503
    274 
    275 
  • trunk/src/org/glassfish/json/JsonBuilderFactoryImpl.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    4141package org.glassfish.json;
    4242
     43import java.util.Collection;
    4344import org.glassfish.json.api.BufferPool;
    4445
     46import javax.json.JsonObject;
     47import javax.json.JsonArray;
    4548import javax.json.JsonArrayBuilder;
    4649import javax.json.JsonBuilderFactory;
     
    6568        return new JsonObjectBuilderImpl(bufferPool);
    6669    }
     70 
     71    @Override
     72    public JsonObjectBuilder createObjectBuilder(JsonObject object) {
     73        return new JsonObjectBuilderImpl(object, bufferPool);
     74    }
     75
     76    @Override
     77    public JsonObjectBuilder createObjectBuilder(Map<String, Object> object) {
     78        return new JsonObjectBuilderImpl(object, bufferPool);
     79    }
    6780
    6881    @Override
     
    7285
    7386    @Override
     87    public JsonArrayBuilder createArrayBuilder(JsonArray array) {
     88        return new JsonArrayBuilderImpl(array, bufferPool);
     89    }
     90
     91    @Override
     92    public JsonArrayBuilder createArrayBuilder(Collection<?> collection) {
     93        return new JsonArrayBuilderImpl(collection, bufferPool);
     94    }
     95
     96    @Override
    7497    public Map<String, ?> getConfigInUse() {
    7598        return config;
  • trunk/src/org/glassfish/json/JsonGeneratorFactoryImpl.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
  • trunk/src/org/glassfish/json/JsonGeneratorImpl.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    5050import java.math.BigInteger;
    5151import java.nio.charset.Charset;
     52import java.nio.charset.StandardCharsets;
    5253import java.util.ArrayDeque;
    5354import java.util.Deque;
     
    5859 */
    5960class JsonGeneratorImpl implements JsonGenerator {
    60     private static final Charset UTF_8 = Charset.forName("UTF-8");
    6161
    6262    private static final char[] INT_MIN_VALUE_CHARS = "-2147483648".toCharArray();
     
    101101        IN_NONE,
    102102        IN_OBJECT,
     103        IN_FIELD,
    103104        IN_ARRAY
    104105    }
     
    107108    private final Writer writer;
    108109    private Context currentContext = new Context(Scope.IN_NONE);
    109     private final Deque<Context> stack = new ArrayDeque<Context>();
     110    private final Deque<Context> stack = new ArrayDeque<>();
    110111
    111112    // Using own buffering mechanism as JDK's BufferedWriter uses synchronized
     
    122123
    123124    JsonGeneratorImpl(OutputStream out, BufferPool bufferPool) {
    124         this(out, UTF_8, bufferPool);
     125        this(out, StandardCharsets.UTF_8, bufferPool);
    125126    }
    126127
     
    170171        writeComma();
    171172        writeEscapedString(name);
    172         writeChar(':');
     173        writeColon();
    173174        return this;
    174175    }
     
    267268    @Override
    268269    public JsonGenerator write(JsonValue value) {
    269         if (currentContext.scope != Scope.IN_ARRAY) {
    270             throw new JsonGenerationException(
    271                     JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope));
    272         }
     270        checkContextForValue();
     271
    273272        switch (value.getValueType()) {
    274273            case ARRAY:
     
    295294                JsonNumber number = (JsonNumber)value;
    296295                writeValue(number.toString());
     296                popFieldContext();
    297297                break;
    298298            case TRUE:
     
    382382    }
    383383
     384    @Override
    384385    public JsonGenerator write(String value) {
    385         if (currentContext.scope != Scope.IN_ARRAY) {
    386             throw new JsonGenerationException(
    387                     JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope));
    388         }
     386        checkContextForValue();
    389387        writeComma();
    390388        writeEscapedString(value);
    391         return this;
    392     }
    393 
    394 
     389        popFieldContext();
     390        return this;
     391    }
     392
     393
     394    @Override
    395395    public JsonGenerator write(int value) {
    396         if (currentContext.scope != Scope.IN_ARRAY) {
    397             throw new JsonGenerationException(
    398                     JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope));
    399         }
     396        checkContextForValue();
    400397        writeComma();
    401398        writeInt(value);
     399        popFieldContext();
    402400        return this;
    403401    }
     
    405403    @Override
    406404    public JsonGenerator write(long value) {
    407         if (currentContext.scope != Scope.IN_ARRAY) {
    408             throw new JsonGenerationException(
    409                     JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope));
    410         }
     405        checkContextForValue();
    411406        writeValue(String.valueOf(value));
     407        popFieldContext();
    412408        return this;
    413409    }
     
    415411    @Override
    416412    public JsonGenerator write(double value) {
    417         if (currentContext.scope != Scope.IN_ARRAY) {
    418             throw new JsonGenerationException(
    419                     JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope));
    420         }
     413        checkContextForValue();
    421414        if (Double.isInfinite(value) || Double.isNaN(value)) {
    422415            throw new NumberFormatException(JsonMessages.GENERATOR_DOUBLE_INFINITE_NAN());
    423416        }
    424417        writeValue(String.valueOf(value));
     418        popFieldContext();
    425419        return this;
    426420    }
     
    428422    @Override
    429423    public JsonGenerator write(BigInteger value) {
    430         if (currentContext.scope != Scope.IN_ARRAY) {
    431             throw new JsonGenerationException(
    432                     JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope));
    433         }
     424        checkContextForValue();
    434425        writeValue(value.toString());
    435         return this;
     426        popFieldContext();
     427        return this;
     428    }
     429
     430    private void checkContextForValue() {
     431        if ((!currentContext.first && currentContext.scope != Scope.IN_ARRAY && currentContext.scope != Scope.IN_FIELD)
     432                || (currentContext.first && currentContext.scope == Scope.IN_OBJECT)) {
     433            throw new JsonGenerationException(
     434                    JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope));
     435        }
    436436    }
    437437
    438438    @Override
    439439    public JsonGenerator write(BigDecimal value) {
    440         if (currentContext.scope != Scope.IN_ARRAY) {
    441             throw new JsonGenerationException(
    442                     JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope));
    443         }
     440        checkContextForValue();
    444441        writeValue(value.toString());
    445         return this;
    446     }
    447 
     442        popFieldContext();
     443
     444        return this;
     445    }
     446
     447    private void popFieldContext() {
     448        if (currentContext.scope == Scope.IN_FIELD) {
     449            currentContext = stack.pop();
     450        }
     451    }
     452
     453    @Override
    448454    public JsonGenerator write(boolean value) {
    449         if (currentContext.scope != Scope.IN_ARRAY) {
    450             throw new JsonGenerationException(
    451                     JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope));
    452         }
     455        checkContextForValue();
    453456        writeComma();
    454457        writeString(value ? "true" : "false");
    455         return this;
    456     }
    457 
     458        popFieldContext();
     459        return this;
     460    }
     461
     462    @Override
    458463    public JsonGenerator writeNull() {
    459         if (currentContext.scope != Scope.IN_ARRAY) {
    460             throw new JsonGenerationException(
    461                     JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope));
    462         }
     464        checkContextForValue();
    463465        writeComma();
    464466        writeString("null");
     467        popFieldContext();
    465468        return this;
    466469    }
     
    474477        writeComma();
    475478        writeEscapedString(name);
    476         writeChar(':');
     479        writeColon();
    477480        writeString(value);
     481    }
     482
     483    @Override
     484    public JsonGenerator writeKey(String name) {
     485        if (currentContext.scope != Scope.IN_OBJECT) {
     486            throw new JsonGenerationException(
     487                    JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope));
     488        }
     489        writeName(name);
     490        stack.push(currentContext);
     491        currentContext = new Context(Scope.IN_FIELD);
     492        currentContext.first = false;
     493        return this;
    478494    }
    479495
     
    485501        writeChar(currentContext.scope == Scope.IN_ARRAY ? ']' : '}');
    486502        currentContext = stack.pop();
     503        popFieldContext();
    487504        return this;
    488505    }
    489506
    490507    protected void writeComma() {
    491         if (!currentContext.first) {
     508        if (!currentContext.first && currentContext.scope != Scope.IN_FIELD) {
    492509            writeChar(',');
    493510        }
    494511        currentContext.first = false;
     512    }
     513
     514    protected void writeColon() {
     515        writeChar(':');
    495516    }
    496517
     
    505526    }
    506527
     528    @Override
    507529    public void close() {
    508530        if (currentContext.scope != Scope.IN_NONE || currentContext.first) {
  • trunk/src/org/glassfish/json/JsonLocationImpl.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    7474    }
    7575
     76    @Override
    7677    public String toString() {
    7778        return "(line no="+lineNo+", column no="+columnNo+", offset="+ offset +")";
  • trunk/src/org/glassfish/json/JsonMessages.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    4646import java.text.MessageFormat;
    4747import java.util.ResourceBundle;
     48import javax.json.JsonObject;
     49import javax.json.JsonValue;
    4850
    4951/**
     
    5658            ResourceBundle.getBundle("org.glassfish.json.messages");
    5759
     60    // global/shared messages
     61    static String INTERNAL_ERROR() {
     62        return localize("internal.error");
     63    }
     64
    5865    // tokenizer messages
    5966    static String TOKENIZER_UNEXPECTED_CHAR(int unexpected, JsonLocation location) {
     
    9198    }
    9299
     100    static String PARSER_GETARRAY_ERR(JsonParser.Event event) {
     101        return localize("parser.getArray.err", event);
     102    }
     103
     104    static String PARSER_GETOBJECT_ERR(JsonParser.Event event) {
     105        return localize("parser.getObject.err", event);
     106    }
     107
     108    static String PARSER_GETVALUE_ERR(JsonParser.Event event) {
     109        return localize("parser.getValue.err", event);
     110    }
     111
     112    static String PARSER_GETVALUESTREAM_ERR() {
     113        return localize("parser.getValueStream.err");
     114    }
     115
    93116    static String PARSER_EXPECTED_EOF(JsonTokenizer.JsonToken token) {
    94117        return localize("parser.expected.eof", token);
     
    103126    }
    104127
     128    static String PARSER_STATE_ERR(JsonValue.ValueType type) {
     129        return localize("parser.state.err", type);
     130    }
     131
     132    static String PARSER_SCOPE_ERR(JsonValue value) {
     133        return localize("parser.scope.err", value);
     134    }
     135
     136    static String PARSER_INPUT_ENC_DETECT_FAILED() {
     137        return localize("parser.input.enc.detect.failed");
     138    }
     139
     140    static String PARSER_INPUT_ENC_DETECT_IOERR() {
     141        return localize("parser.input.enc.detect.ioerr");
     142    }
    105143
    106144    // generator messages
     
    140178    }
    141179
    142 
    143180    // reader messages
    144181    static String READER_READ_ALREADY_CALLED() {
     
    146183    }
    147184
    148     static String READER_EXPECTED_ARRAY_GOT_OBJECT() {
    149         return localize("reader.expected.array.got.object");
    150     }
    151 
    152     static String READER_EXPECTED_OBJECT_GOT_ARRAY() {
    153         return localize("reader.expected.object.got.array");
    154     }
    155 
    156185
    157186    // obj builder messages
     
    184213    static String ARRBUILDER_ARRAY_BUILDER_NULL() {
    185214        return localize("arrbuilder.array.builder.null");
     215    }
     216
     217    static String ARRBUILDER_VALUELIST_NULL(int index, int size) {
     218        return localize("arrbuilder.valuelist.null", index, size);
     219    }
     220
     221    // json pointer messages
     222    static String POINTER_FORMAT_INVALID() {
     223        return localize("pointer.format.invalid");
     224    }
     225
     226    static String POINTER_MAPPING_MISSING(JsonObject object, String key) {
     227        return localize("pointer.mapping.missing", object, key);
     228    }
     229
     230    static String POINTER_REFERENCE_INVALID(JsonValue.ValueType type) {
     231        return localize("pointer.reference.invalid", type.name());
     232    }
     233
     234    static String POINTER_ARRAY_INDEX_ERR(String token) {
     235        return localize("pointer.array.index.err", token);
     236    }
     237
     238    static String POINTER_ARRAY_INDEX_ILLEGAL(String token) {
     239        return localize("pointer.array.index.illegal", token);
     240    }
     241
     242    // nodereference messages
     243    static String NODEREF_VALUE_ADD_ERR() {
     244        return localize("noderef.value.add.err");
     245    }
     246
     247    static String NODEREF_VALUE_CANNOT_REMOVE() {
     248        return localize("noderef.value.cannot.remove");
     249    }
     250
     251    static String NODEREF_OBJECT_MISSING(String key) {
     252        return localize("noderef.object.missing", key);
     253    }
     254
     255    static String NODEREF_ARRAY_INDEX_ERR(int index, int size) {
     256        return localize("noderef.array.index.err", index, size);
     257    }
     258
     259    // json patch messages
     260    static String PATCH_MUST_BE_ARRAY() {
     261        return localize("patch.must.be.array");
     262    }
     263
     264    static String PATCH_MOVE_PROPER_PREFIX(String from, String path) {
     265        return localize("patch.move.proper.prefix", from, path);
     266    }
     267
     268    static String PATCH_MOVE_TARGET_NULL(String from) {
     269        return localize("patch.move.target.null", from);
     270    }
     271
     272    static String PATCH_TEST_FAILED(String path, String value) {
     273        return localize("patch.test.failed", path, value);
     274    }
     275
     276    static String PATCH_ILLEGAL_OPERATION(String operation) {
     277        return localize("patch.illegal.operation", operation);
     278    }
     279
     280    static String PATCH_MEMBER_MISSING(String operation, String member) {
     281        return localize("patch.member.missing", operation, member);
    186282    }
    187283
  • trunk/src/org/glassfish/json/JsonNumberImpl.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    126126
    127127        @Override
     128        public Number numberValue() {
     129            return num;
     130        }
     131
     132        @Override
    128133        public String toString() {
    129134            return Integer.toString(num);
     
    143148        public boolean isIntegral() {
    144149            return true;
     150        }
     151
     152        @Override
     153        public int intValue() {
     154            return (int) num;
     155        }
     156
     157        @Override
     158        public int intValueExact() {
     159            return Math.toIntExact(num);
    145160        }
    146161
     
    172187
    173188        @Override
     189        public Number numberValue() {
     190            return num;
     191        }
     192
     193        @Override
    174194        public String toString() {
    175195            return Long.toString(num);
     
    191211        }
    192212
     213        @Override
     214        public Number numberValue() {
     215            return bigDecimalValue();
     216        }
     217
    193218    }
    194219
     
    245270    @Override
    246271    public boolean equals(Object obj) {
     272        if (this == obj){
     273            return true;
     274        }
    247275        if (!(obj instanceof JsonNumber)) {
    248276            return false;
  • trunk/src/org/glassfish/json/JsonObjectBuilderImpl.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    5151
    5252/**
    53  * JsonObjectBuilder impl
     53 * JsonObjectBuilder implementation
    5454 *
    5555 * @author Jitendra Kotamraju
     56 * @author Kin-man Chung
    5657 */
    5758class JsonObjectBuilderImpl implements JsonObjectBuilder {
     59
    5860    private Map<String, JsonValue> valueMap;
    5961    private final BufferPool bufferPool;
     
    6365    }
    6466
     67    JsonObjectBuilderImpl(JsonObject object, BufferPool bufferPool) {
     68        this.bufferPool = bufferPool;
     69        valueMap = new LinkedHashMap<>();
     70        valueMap.putAll(object);
     71    }
     72
     73    JsonObjectBuilderImpl(Map<String, Object> map, BufferPool bufferPool) {
     74        this.bufferPool = bufferPool;
     75        valueMap = new LinkedHashMap<>();
     76        populate(map);
     77    }
     78
     79    @Override
    6580    public JsonObjectBuilder add(String name, JsonValue value) {
    6681        validateName(name);
     
    7085    }
    7186
     87    @Override
    7288    public JsonObjectBuilder add(String name, String value) {
    7389        validateName(name);
     
    7793    }
    7894
     95    @Override
    7996    public JsonObjectBuilder add(String name, BigInteger value) {
    8097        validateName(name);
     
    84101    }
    85102
     103    @Override
    86104    public JsonObjectBuilder add(String name, BigDecimal value) {
    87105        validateName(name);
     
    91109    }
    92110
     111    @Override
    93112    public JsonObjectBuilder add(String name, int value) {
    94113        validateName(name);
     
    97116    }
    98117
     118    @Override
    99119    public JsonObjectBuilder add(String name, long value) {
    100120        validateName(name);
     
    103123    }
    104124
     125    @Override
    105126    public JsonObjectBuilder add(String name, double value) {
    106127        validateName(name);
     
    109130    }
    110131
     132    @Override
    111133    public JsonObjectBuilder add(String name, boolean value) {
    112134        validateName(name);
     
    115137    }
    116138
     139    @Override
    117140    public JsonObjectBuilder addNull(String name) {
    118141        validateName(name);
     
    121144    }
    122145
     146    @Override
    123147    public JsonObjectBuilder add(String name, JsonObjectBuilder builder) {
    124148        validateName(name);
     
    130154    }
    131155
     156    @Override
    132157    public JsonObjectBuilder add(String name, JsonArrayBuilder builder) {
    133158        validateName(name);
     
    139164    }
    140165
     166    @Override
     167    public JsonObjectBuilder addAll(JsonObjectBuilder builder) {
     168        if (builder == null) {
     169            throw new NullPointerException(JsonMessages.OBJBUILDER_OBJECT_BUILDER_NULL());
     170        }
     171        if (valueMap == null) {
     172            this.valueMap = new LinkedHashMap<>();
     173        }
     174        this.valueMap.putAll(builder.build());
     175        return this;
     176    }
     177
     178    @Override
     179    public JsonObjectBuilder remove(String name) {
     180        validateName(name);
     181        this.valueMap.remove(name);
     182        return this;
     183    }
     184
     185    @Override
    141186    public JsonObject build() {
    142187        Map<String, JsonValue> snapshot = (valueMap == null)
     
    147192    }
    148193
     194    private void populate(Map<String, Object> map) {
     195        final Set<String> fields = map.keySet();
     196        for (String field : fields) {
     197            Object value = map.get(field);
     198            if (value != null && value instanceof Optional) {
     199                ((Optional<?>) value).ifPresent(v ->
     200                        this.valueMap.put(field, MapUtil.handle(v, bufferPool)));
     201            } else {
     202                this.valueMap.put(field, MapUtil.handle(value, bufferPool));
     203            }
     204        }
     205    }
     206
    149207    private void putValueMap(String name, JsonValue value) {
    150208        if (valueMap == null) {
    151             this.valueMap = new LinkedHashMap<String, JsonValue>();
     209            this.valueMap = new LinkedHashMap<>();
    152210        }
    153211        valueMap.put(name, value);
     
    264322        public String toString() {
    265323            StringWriter sw = new StringWriter();
    266             JsonWriter jw = new JsonWriterImpl(sw, bufferPool);
    267             jw.write(this);
    268             jw.close();
     324            try (JsonWriter jw = new JsonWriterImpl(sw, bufferPool)) {
     325                jw.write(this);
     326            }
    269327            return sw.toString();
    270328        }
     329
     330        @Override
     331        public JsonObject asJsonObject() {
     332            return this;
     333        }
     334
     335        @Override
     336        public int size() {
     337            return valueMap.size();
     338        }
     339
     340        @Override
     341        public JsonValue get(Object key) {
     342            return valueMap.get(key);
     343        }
     344
     345        @Override
     346        public boolean containsKey(Object key) {
     347            return valueMap.containsKey(key);
     348        }
    271349    }
    272350
  • trunk/src/org/glassfish/json/JsonParserFactoryImpl.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
  • trunk/src/org/glassfish/json/JsonParserImpl.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    4141package org.glassfish.json;
    4242
    43 import javax.json.*;
     43import java.io.IOException;
     44import java.io.InputStream;
     45import java.io.InputStreamReader;
     46import java.io.Reader;
     47import java.math.BigDecimal;
     48import java.nio.charset.Charset;
     49import java.util.AbstractMap;
     50import java.util.Map;
     51import java.util.NoSuchElementException;
     52import java.util.Spliterator;
     53import java.util.Spliterators;
     54import java.util.function.Consumer;
     55import java.util.stream.Stream;
     56import java.util.stream.StreamSupport;
     57
     58import javax.json.JsonArray;
     59import javax.json.JsonArrayBuilder;
     60import javax.json.JsonException;
     61import javax.json.JsonObject;
     62import javax.json.JsonObjectBuilder;
     63import javax.json.JsonValue;
    4464import javax.json.stream.JsonLocation;
    4565import javax.json.stream.JsonParser;
     66import javax.json.stream.JsonParser.Event;
    4667import javax.json.stream.JsonParsingException;
    47 import java.io.*;
    48 import java.math.BigDecimal;
    49 import java.nio.charset.Charset;
    50 import java.util.*;
    5168
    5269import org.glassfish.json.JsonTokenizer.JsonToken;
     
    5875 *
    5976 * @author Jitendra Kotamraju
     77 * @author Kin-man Chung
    6078 */
    6179public class JsonParserImpl implements JsonParser {
    6280
     81    private final BufferPool bufferPool;
    6382    private Context currentContext = new NoneContext();
    6483    private Event currentEvent;
    6584
    6685    private final Stack stack = new Stack();
    67     private final StateIterator stateIterator;
    6886    private final JsonTokenizer tokenizer;
    6987
    7088    public JsonParserImpl(Reader reader, BufferPool bufferPool) {
     89        this.bufferPool = bufferPool;
    7190        tokenizer = new JsonTokenizer(reader, bufferPool);
    72         stateIterator = new StateIterator();
    7391    }
    7492
    7593    public JsonParserImpl(InputStream in, BufferPool bufferPool) {
     94        this.bufferPool = bufferPool;
    7695        UnicodeDetectingInputStream uin = new UnicodeDetectingInputStream(in);
    7796        tokenizer = new JsonTokenizer(new InputStreamReader(uin, uin.getCharset()), bufferPool);
    78         stateIterator = new StateIterator();
    7997    }
    8098
    8199    public JsonParserImpl(InputStream in, Charset encoding, BufferPool bufferPool) {
     100        this.bufferPool = bufferPool;
    82101        tokenizer = new JsonTokenizer(new InputStreamReader(in, encoding), bufferPool);
    83         stateIterator = new StateIterator();
    84     }
    85 
     102    }
     103
     104    @Override
    86105    public String getString() {
    87106        if (currentEvent == Event.KEY_NAME || currentEvent == Event.VALUE_STRING
     
    115134    }
    116135
     136    boolean isDefinitelyLong() {
     137        return tokenizer.isDefinitelyLong();
     138    }
     139
    117140    @Override
    118141    public long getLong() {
     
    121144                    JsonMessages.PARSER_GETLONG_ERR(currentEvent));
    122145        }
    123         return tokenizer.getBigDecimal().longValue();
     146        return tokenizer.getLong();
    124147    }
    125148
     
    134157
    135158    @Override
     159    public JsonArray getArray() {
     160        if (currentEvent != Event.START_ARRAY) {
     161            throw new IllegalStateException(
     162                JsonMessages.PARSER_GETARRAY_ERR(currentEvent));
     163        }
     164        return getArray(new JsonArrayBuilderImpl(bufferPool));
     165    }
     166
     167    @Override
     168    public JsonObject getObject() {
     169        if (currentEvent != Event.START_OBJECT) {
     170            throw new IllegalStateException(
     171                JsonMessages.PARSER_GETOBJECT_ERR(currentEvent));
     172        }
     173        return getObject(new JsonObjectBuilderImpl(bufferPool));
     174    }
     175
     176    @Override
     177    public JsonValue getValue() {
     178        switch (currentEvent) {
     179            case START_ARRAY:
     180                return getArray(new JsonArrayBuilderImpl(bufferPool));
     181            case START_OBJECT:
     182                return getObject(new JsonObjectBuilderImpl(bufferPool));
     183            case KEY_NAME:
     184            case VALUE_STRING:
     185                return new JsonStringImpl(getString());
     186            case VALUE_NUMBER:
     187                if (isDefinitelyInt()) {
     188                    return JsonNumberImpl.getJsonNumber(getInt());
     189                } else if (isDefinitelyLong()) {
     190                    return JsonNumberImpl.getJsonNumber(getLong());
     191                }
     192                return JsonNumberImpl.getJsonNumber(getBigDecimal());
     193            case VALUE_TRUE:
     194                return JsonValue.TRUE;
     195            case VALUE_FALSE:
     196                return JsonValue.FALSE;
     197            case VALUE_NULL:
     198                return JsonValue.NULL;
     199            case END_ARRAY:
     200            case END_OBJECT:
     201            default:
     202                throw new IllegalStateException(JsonMessages.PARSER_GETVALUE_ERR(currentEvent));
     203        }
     204    }
     205
     206    @Override
     207    public Stream<JsonValue> getArrayStream() {
     208        if (currentEvent != Event.START_ARRAY) {
     209            throw new IllegalStateException(
     210                JsonMessages.PARSER_GETARRAY_ERR(currentEvent));
     211        }
     212        Spliterator<JsonValue> spliterator =
     213                new Spliterators.AbstractSpliterator<JsonValue>(Long.MAX_VALUE, Spliterator.ORDERED) {
     214            @Override
     215            public Spliterator<JsonValue> trySplit() {
     216                return null;
     217            }
     218            @Override
     219            public boolean tryAdvance(Consumer<? super JsonValue> action) {
     220                if (action == null) {
     221                    throw new NullPointerException();
     222                }
     223                if (! hasNext()) {
     224                    return false;
     225                }
     226                if (next() == JsonParser.Event.END_ARRAY) {
     227                    return false;
     228                }
     229                action.accept(getValue());
     230                return true;
     231            }
     232        };
     233        return StreamSupport.stream(spliterator, false);
     234    }
     235
     236    @Override
     237    public Stream<Map.Entry<String, JsonValue>> getObjectStream() {
     238        if (currentEvent != Event.START_OBJECT) {
     239            throw new IllegalStateException(
     240                JsonMessages.PARSER_GETOBJECT_ERR(currentEvent));
     241        }
     242        Spliterator<Map.Entry<String, JsonValue>> spliterator =
     243                new Spliterators.AbstractSpliterator<Map.Entry<String, JsonValue>>(Long.MAX_VALUE, Spliterator.ORDERED) {
     244            @Override
     245            public Spliterator<Map.Entry<String,JsonValue>> trySplit() {
     246                return null;
     247            }
     248            @Override
     249            public boolean tryAdvance(Consumer<? super Map.Entry<String, JsonValue>> action) {
     250                if (action == null) {
     251                    throw new NullPointerException();
     252                }
     253                if (! hasNext()) {
     254                    return false;
     255                }
     256                JsonParser.Event e = next();
     257                if (e == JsonParser.Event.END_OBJECT) {
     258                    return false;
     259                }
     260                if (e != JsonParser.Event.KEY_NAME) {
     261                    throw new JsonException(JsonMessages.INTERNAL_ERROR());
     262                }
     263                String key = getString();
     264                if (! hasNext()) {
     265                    throw new JsonException(JsonMessages.INTERNAL_ERROR());
     266                }
     267                next();
     268                JsonValue value = getValue();
     269                action.accept(new AbstractMap.SimpleImmutableEntry<>(key, value));
     270                return true;
     271            }
     272        };
     273        return StreamSupport.stream(spliterator, false);
     274    }
     275
     276    @Override
     277    public Stream<JsonValue> getValueStream() {
     278        if (! (currentContext instanceof NoneContext)) {
     279            throw new IllegalStateException(
     280                JsonMessages.PARSER_GETVALUESTREAM_ERR());
     281        }
     282        Spliterator<JsonValue> spliterator =
     283                new Spliterators.AbstractSpliterator<JsonValue>(Long.MAX_VALUE, Spliterator.ORDERED) {
     284            @Override
     285            public Spliterator<JsonValue> trySplit() {
     286                return null;
     287            }
     288            @Override
     289            public boolean tryAdvance(Consumer<? super JsonValue> action) {
     290                if (action == null) {
     291                    throw new NullPointerException();
     292                }
     293                if (! hasNext()) {
     294                    return false;
     295                }
     296                next();
     297                action.accept(getValue());
     298                return true;
     299            }
     300        };
     301        return StreamSupport.stream(spliterator, false);
     302    }
     303
     304    @Override
     305    public void skipArray() {
     306        if (currentEvent == Event.START_ARRAY) {
     307            currentContext.skip();
     308            currentContext = stack.pop();
     309        }
     310    }
     311
     312    @Override
     313    public void skipObject() {
     314        if (currentEvent == Event.START_OBJECT) {
     315            currentContext.skip();
     316            currentContext = stack.pop();
     317        }
     318    }
     319
     320    private JsonArray getArray(JsonArrayBuilder builder) {
     321        while(hasNext()) {
     322            JsonParser.Event e = next();
     323            if (e == JsonParser.Event.END_ARRAY) {
     324                return builder.build();
     325            }
     326            builder.add(getValue());
     327        }
     328        throw parsingException(JsonToken.EOF, "[CURLYOPEN, SQUAREOPEN, STRING, NUMBER, TRUE, FALSE, NULL, SQUARECLOSE]");
     329    }
     330
     331    private JsonObject getObject(JsonObjectBuilder builder) {
     332        while(hasNext()) {
     333            JsonParser.Event e = next();
     334            if (e == JsonParser.Event.END_OBJECT) {
     335                return builder.build();
     336            }
     337            String key = getString();
     338            next();
     339            builder.add(key, getValue());
     340        }
     341        throw parsingException(JsonToken.EOF, "[STRING, CURLYCLOSE]");
     342    }
     343
     344    @Override
    136345    public JsonLocation getLocation() {
    137346        return tokenizer.getLocation();
     
    142351    }
    143352
     353    @Override
    144354    public boolean hasNext() {
    145         return stateIterator.hasNext();
    146     }
    147 
     355        return tokenizer.hasNextToken();
     356    }
     357
     358    @Override
    148359    public Event next() {
    149         return stateIterator.next();
    150     }
    151 
    152     private class StateIterator implements  Iterator<JsonParser.Event> {
    153 
    154         @Override
    155         public boolean hasNext() {
    156             if (stack.isEmpty() && (currentEvent == Event.END_ARRAY || currentEvent == Event.END_OBJECT)) {
    157                 JsonToken token = tokenizer.nextToken();
    158                 if (token != JsonToken.EOF) {
    159                     throw new JsonParsingException(JsonMessages.PARSER_EXPECTED_EOF(token),
    160                             getLastCharLocation());
    161                 }
    162                 return false;
    163             }
    164             return true;
    165         }
    166 
    167         @Override
    168         public JsonParser.Event next() {
    169             if (!hasNext()) {
    170                 throw new NoSuchElementException();
    171             }
    172             return currentEvent = currentContext.getNextEvent();
    173         }
    174 
    175         @Override
    176         public void remove() {
    177             throw new UnsupportedOperationException();
    178         }
    179     }
    180 
     360        if (!hasNext()) {
     361            throw new NoSuchElementException();
     362        }
     363        return currentEvent = currentContext.getNextEvent();
     364    }
     365
     366    @Override
    181367    public void close() {
    182368        try {
     
    206392        }
    207393
     394        private Context peek() {
     395            return head;
     396        }
     397
    208398        private boolean isEmpty() {
    209399            return head == null;
     
    214404        Context next;
    215405        abstract Event getNextEvent();
     406        abstract void skip();
    216407    }
    217408
     
    219410        @Override
    220411        public Event getNextEvent() {
    221             // Handle 1. {     2. [
     412            // Handle 1. {   2. [   3. value
    222413            JsonToken token = tokenizer.nextToken();
    223414            if (token == JsonToken.CURLYOPEN) {
     
    229420                currentContext = new ArrayContext();
    230421                return Event.START_ARRAY;
    231             }
    232             throw parsingException(token, "[CURLYOPEN, SQUAREOPEN]");
     422            } else if (token.isValue()) {
     423                return token.getEvent();
     424            }
     425            throw parsingException(token, "[CURLYOPEN, SQUAREOPEN, STRING, NUMBER, TRUE, FALSE, NULL]");
     426        }
     427
     428        @Override
     429        void skip() {
     430            // no-op
    233431        }
    234432    }
     
    293491        }
    294492
     493        @Override
     494        void skip() {
     495            JsonToken token;
     496            int depth = 1;
     497            do {
     498                token = tokenizer.nextToken();
     499                switch (token) {
     500                    case CURLYCLOSE:
     501                        depth--;
     502                        break;
     503                    case CURLYOPEN:
     504                        depth++;
     505                        break;
     506                }
     507            } while (!(token == JsonToken.CURLYCLOSE && depth == 0));
     508        }
     509
    295510    }
    296511
     
    328543        }
    329544
     545        @Override
     546        void skip() {
     547            JsonToken token;
     548            int depth = 1;
     549            do {
     550                token = tokenizer.nextToken();
     551                switch (token) {
     552                    case SQUARECLOSE:
     553                        depth--;
     554                        break;
     555                    case SQUAREOPEN:
     556                        depth++;
     557                        break;
     558                }
     559            } while (!(token == JsonToken.SQUARECLOSE && depth == 0));
     560        }
    330561    }
    331562
  • trunk/src/org/glassfish/json/JsonPrettyGeneratorImpl.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    117117    }
    118118
     119    @Override
     120    protected void writeColon() {
     121        super.writeColon();
     122        writeChar(' ');
     123    }
     124
    119125    private void writeNewLine() {
    120126        writeChar('\n');
  • trunk/src/org/glassfish/json/JsonProviderImpl.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    5353import java.io.Reader;
    5454import java.io.Writer;
     55import java.util.Collection;
    5556import java.util.Collections;
    5657import java.util.HashMap;
    5758import java.util.Map;
     59import java.math.BigDecimal;
     60import java.math.BigInteger;
    5861
    5962/**
    6063 * @author Jitendra Kotamraju
     64 * @author Kin-man Chung
     65 * @author Alex Soto
    6166 */
    6267public class JsonProviderImpl extends JsonProvider {
     
    106111            pool = bufferPool;
    107112        } else {
    108             providerConfig = new HashMap<String, Object>();
     113            providerConfig = new HashMap<>();
    109114            if (prettyPrinting=JsonProviderImpl.isPrettyPrintingEnabled(config)) {
    110115                providerConfig.put(JsonGenerator.PRETTY_PRINTING, true);
     
    152157            pool = bufferPool;
    153158        } else {
    154             providerConfig = new HashMap<String, Object>();
     159            providerConfig = new HashMap<>();
    155160            if (prettyPrinting=JsonProviderImpl.isPrettyPrintingEnabled(config)) {
    156161                providerConfig.put(JsonGenerator.PRETTY_PRINTING, true);
     
    185190
    186191    @Override
     192    public JsonObjectBuilder createObjectBuilder(JsonObject object) {
     193        return new JsonObjectBuilderImpl(object, bufferPool);
     194    }
     195
     196    @Override
     197    public JsonObjectBuilder createObjectBuilder(Map<String, Object> map) {
     198        return new JsonObjectBuilderImpl(map, bufferPool);
     199    }
     200
     201    @Override
    187202    public JsonArrayBuilder createArrayBuilder() {
    188203        return new JsonArrayBuilderImpl(bufferPool);
     204    }
     205
     206    @Override
     207    public JsonArrayBuilder createArrayBuilder(JsonArray array) {
     208        return new JsonArrayBuilderImpl(array, bufferPool);
     209    }
     210
     211    @Override
     212    public JsonArrayBuilder createArrayBuilder(Collection<?> collection) {
     213        return new JsonArrayBuilderImpl(collection, bufferPool);
     214    }
     215
     216    @Override
     217    public JsonPointer createPointer(String jsonPointer) {
     218        return new JsonPointerImpl(jsonPointer);
     219    }
     220
     221    @Override
     222    public JsonPatchBuilder createPatchBuilder() {
     223        return new JsonPatchBuilderImpl();
     224    }
     225
     226    @Override
     227    public JsonPatchBuilder createPatchBuilder(JsonArray array) {
     228        return new JsonPatchBuilderImpl(array);
     229    }
     230
     231    @Override
     232    public JsonPatch createPatch(JsonArray array) {
     233        return new JsonPatchImpl(array);
     234    }
     235
     236    @Override
     237    public JsonPatch createDiff(JsonStructure source, JsonStructure target) {
     238        return new JsonPatchImpl(JsonPatchImpl.diff(source, target));
     239    }
     240
     241    @Override
     242    public JsonMergePatch createMergePatch(JsonValue patch) {
     243        return new JsonMergePatchImpl(patch);
     244    }
     245
     246    @Override
     247    public JsonMergePatch createMergeDiff(JsonValue source, JsonValue target) {
     248        return new JsonMergePatchImpl(JsonMergePatchImpl.diff(source, target));
     249    }
     250
     251    @Override
     252    public JsonString createValue(String value) {
     253        return new JsonStringImpl(value);
     254    }
     255
     256    @Override
     257    public JsonNumber createValue(int value) {
     258        return JsonNumberImpl.getJsonNumber(value);
     259    }
     260
     261    @Override
     262    public JsonNumber createValue(long value) {
     263        return JsonNumberImpl.getJsonNumber(value);
     264    }
     265
     266    @Override
     267    public JsonNumber createValue(double value) {
     268        return JsonNumberImpl.getJsonNumber(value);
     269    }
     270
     271    @Override
     272    public JsonNumber createValue(BigInteger value) {
     273        return JsonNumberImpl.getJsonNumber(value);
     274    }
     275
     276    @Override
     277    public JsonNumber createValue(BigDecimal value) {
     278        return JsonNumberImpl.getJsonNumber(value);
    189279    }
    190280
  • trunk/src/org/glassfish/json/JsonReaderFactoryImpl.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
  • trunk/src/org/glassfish/json/JsonReaderImpl.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    4343import org.glassfish.json.api.BufferPool;
    4444
    45 import javax.json.*;
    46 import javax.json.stream.JsonParser;
    4745import java.io.InputStream;
    4846import java.io.Reader;
    49 import java.math.BigDecimal;
    5047import java.nio.charset.Charset;
     48import javax.json.JsonArray;
     49import javax.json.JsonException;
     50import javax.json.JsonObject;
     51import javax.json.JsonReader;
     52import javax.json.JsonStructure;
     53import javax.json.JsonValue;
     54import javax.json.stream.JsonParser;
     55import javax.json.stream.JsonParsingException;
    5156
    5257/**
     
    8287        readDone = true;
    8388        if (parser.hasNext()) {
    84             JsonParser.Event e = parser.next();
    85             if (e == JsonParser.Event.START_ARRAY) {
    86                 return readArray(new JsonArrayBuilderImpl(bufferPool));
    87             } else if (e == JsonParser.Event.START_OBJECT) {
    88                 return readObject(new JsonObjectBuilderImpl(bufferPool));
     89            try {
     90                JsonParser.Event e = parser.next();
     91                if (e == JsonParser.Event.START_ARRAY) {
     92                    return parser.getArray();
     93                } else if (e == JsonParser.Event.START_OBJECT) {
     94                    return parser.getObject();
     95                }
     96            } catch (IllegalStateException ise) {
     97                throw new JsonParsingException(ise.getMessage(), ise, parser.getLastCharLocation());
    8998            }
    9099        }
    91         throw new JsonException("Internal Error");
     100        throw new JsonException(JsonMessages.INTERNAL_ERROR());
    92101    }
    93102
     
    99108        readDone = true;
    100109        if (parser.hasNext()) {
    101             JsonParser.Event e = parser.next();
    102             if (e == JsonParser.Event.START_OBJECT) {
    103                 return readObject(new JsonObjectBuilderImpl(bufferPool));
    104             } else if (e == JsonParser.Event.START_ARRAY) {
    105                 throw new JsonException(JsonMessages.READER_EXPECTED_OBJECT_GOT_ARRAY());
     110            try {
     111                parser.next();
     112                return parser.getObject();
     113            } catch (IllegalStateException ise) {
     114                throw new JsonParsingException(ise.getMessage(), ise, parser.getLastCharLocation());
    106115            }
    107116        }
    108         throw new JsonException("Internal Error");
     117        throw new JsonException(JsonMessages.INTERNAL_ERROR());
    109118    }
    110119
     
    116125        readDone = true;
    117126        if (parser.hasNext()) {
    118             JsonParser.Event e = parser.next();
    119             if (e == JsonParser.Event.START_ARRAY) {
    120                 return readArray(new JsonArrayBuilderImpl(bufferPool));
    121             } else if (e == JsonParser.Event.START_OBJECT) {
    122                 throw new JsonException(JsonMessages.READER_EXPECTED_ARRAY_GOT_OBJECT());
     127            try {
     128                parser.next();
     129                return parser.getArray();
     130            } catch (IllegalStateException ise) {
     131                throw new JsonParsingException(ise.getMessage(), ise, parser.getLastCharLocation());
    123132            }
    124133        }
    125         throw new JsonException("Internal Error");
     134        throw new JsonException(JsonMessages.INTERNAL_ERROR());
     135    }
     136
     137    @Override
     138    public JsonValue readValue() {
     139        if (readDone) {
     140            throw new IllegalStateException(JsonMessages.READER_READ_ALREADY_CALLED());
     141        }
     142        readDone = true;
     143        if (parser.hasNext()) {
     144            try {
     145                parser.next();
     146                return parser.getValue();
     147            } catch (IllegalStateException ise) {
     148                throw new JsonParsingException(ise.getMessage(), ise, parser.getLastCharLocation());
     149            }
     150        }
     151        throw new JsonException(JsonMessages.INTERNAL_ERROR());
    126152    }
    127153
     
    131157        parser.close();
    132158    }
    133 
    134     private JsonArray readArray(JsonArrayBuilder builder) {
    135         while(parser.hasNext()) {
    136             JsonParser.Event e = parser.next();
    137             switch (e) {
    138                 case START_ARRAY:
    139                     JsonArray array = readArray(new JsonArrayBuilderImpl(bufferPool));
    140                     builder.add(array);
    141                     break;
    142                 case START_OBJECT:
    143                     JsonObject object = readObject(new JsonObjectBuilderImpl(bufferPool));
    144                     builder.add(object);
    145                     break;
    146                 case VALUE_STRING:
    147                     builder.add(parser.getString());
    148                     break;
    149                 case VALUE_NUMBER:
    150                     if (parser.isDefinitelyInt()) {
    151                         builder.add(parser.getInt());
    152                     } else {
    153                         builder.add(parser.getBigDecimal());
    154                     }
    155                     break;
    156                 case VALUE_TRUE:
    157                     builder.add(JsonValue.TRUE);
    158                     break;
    159                 case VALUE_FALSE:
    160                     builder.add(JsonValue.FALSE);
    161                     break;
    162                 case VALUE_NULL:
    163                     builder.addNull();
    164                     break;
    165                 case END_ARRAY:
    166                     return builder.build();
    167                 default:
    168                     throw new JsonException("Internal Error");
    169             }
    170         }
    171         throw new JsonException("Internal Error");
    172     }
    173 
    174     private JsonObject readObject(JsonObjectBuilder builder) {
    175         String key = null;
    176         while(parser.hasNext()) {
    177             JsonParser.Event e = parser .next();
    178             switch (e) {
    179                 case START_ARRAY:
    180                     JsonArray array = readArray(new JsonArrayBuilderImpl(bufferPool));
    181                     builder.add(key, array);
    182                     break;
    183                 case START_OBJECT:
    184                     JsonObject object = readObject(new JsonObjectBuilderImpl(bufferPool));
    185                     builder.add(key, object);
    186                     break;
    187                 case KEY_NAME:
    188                     key = parser.getString();
    189                     break;
    190                 case VALUE_STRING:
    191                     builder.add(key, parser.getString());
    192                     break;
    193                 case VALUE_NUMBER:
    194                     if (parser.isDefinitelyInt()) {
    195                         builder.add(key, parser.getInt());
    196                     } else {
    197                         builder.add(key, parser.getBigDecimal());
    198                     }
    199                     break;
    200                 case VALUE_TRUE:
    201                     builder.add(key, JsonValue.TRUE);
    202                     break;
    203                 case VALUE_FALSE:
    204                     builder.add(key, JsonValue.FALSE);
    205                     break;
    206                 case VALUE_NULL:
    207                     builder.addNull(key);
    208                     break;
    209                 case END_OBJECT:
    210                     return builder.build();
    211                 default:
    212                     throw new JsonException("Internal Error");
    213             }
    214         }
    215         throw new JsonException("Internal Error");
    216     }
    217 
    218159}
  • trunk/src/org/glassfish/json/JsonStringImpl.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    7878    @Override
    7979    public boolean equals(Object obj) {
     80        if (this == obj){
     81            return true;
     82        }
    8083        if (!(obj instanceof JsonString)) {
    8184            return false;
  • trunk/src/org/glassfish/json/JsonStructureParser.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    4545import javax.json.stream.JsonParser;
    4646import java.math.BigDecimal;
    47 import java.util.*;
     47import java.util.ArrayDeque;
     48import java.util.Deque;
     49import java.util.Iterator;
     50import java.util.Map;
     51import java.util.NoSuchElementException;
    4852
    4953/**
     
    5660    private Scope current;
    5761    private Event state;
    58     private final Deque<Scope> scopeStack = new ArrayDeque<Scope>();
     62    private final Deque<Scope> scopeStack = new ArrayDeque<>();
    5963
    6064    JsonStructureParser(JsonArray array) {
     
    6872    @Override
    6973    public String getString() {
    70         if (state == Event.KEY_NAME) {
    71             return ((ObjectScope)current).key;
    72         } else if (state == Event.VALUE_STRING) {
    73             return ((JsonString)current.getJsonValue()).getString();
    74         }
    75         throw new IllegalStateException(JsonMessages.PARSER_GETSTRING_ERR(state));
     74        switch (state) {
     75            case KEY_NAME:
     76                return ((ObjectScope)current).key;
     77            case VALUE_STRING:
     78                return ((JsonString)current.getJsonValue()).getString();
     79            case VALUE_NUMBER:
     80                return ((JsonNumber)current.getJsonValue()).toString();
     81            default:
     82                throw new IllegalStateException(JsonMessages.PARSER_GETSTRING_ERR(state));
     83        }
    7684    }
    7785
     
    168176    public void close() {
    169177        // no-op
     178    }
     179
     180    @Override
     181    public void skipObject() {
     182        if (current instanceof ObjectScope) {
     183            int depth = 1;
     184            do {
     185                if (state == Event.KEY_NAME) {
     186                    state = getState(current.getJsonValue());
     187                    switch (state) {
     188                        case START_OBJECT:
     189                            depth++;
     190                            break;
     191                        case END_OBJECT:
     192                            depth--;
     193                            break;
     194                        default:
     195                            //no-op
     196                    }
     197                } else {
     198                    if (current.hasNext()) {
     199                        current.next();
     200                        state = Event.KEY_NAME;
     201                    } else {
     202                        state = Event.END_OBJECT;
     203                        depth--;
     204                    }
     205                }
     206            } while (state != Event.END_OBJECT && depth > 0);
     207        }
     208    }
     209
     210    @Override
     211    public void skipArray() {
     212        if (current instanceof ArrayScope) {
     213            int depth = 1;
     214            do {
     215                if (current.hasNext()) {
     216                    current.next();
     217                    state = getState(current.getJsonValue());
     218                    switch (state) {
     219                        case START_ARRAY:
     220                            depth++;
     221                            break;
     222                        case END_ARRAY:
     223                            depth--;
     224                            break;
     225                        default:
     226                            //no-op
     227                    }
     228                } else {
     229                    state = Event.END_ARRAY;
     230                    depth--;
     231                }
     232            } while (!(state == Event.END_ARRAY && depth == 0));
     233        }
    170234    }
    171235
     
    187251                return Event.VALUE_NULL;
    188252            default:
    189                 throw new JsonException("Unknown value type="+value.getValueType());
     253                throw new JsonException(JsonMessages.PARSER_STATE_ERR(value.getValueType()));
    190254        }
    191255    }
     
    200264                return new ObjectScope((JsonObject)value);
    201265            }
    202             throw new JsonException("Cannot be called for value="+value);
     266            throw new JsonException(JsonMessages.PARSER_SCOPE_ERR(value));
    203267        }
    204268    }
  • trunk/src/org/glassfish/json/JsonTokenizer.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    293293            }
    294294        }
    295         readBegin--;
    296         storeEnd = readBegin;
     295        if (ch != -1) {
     296            // Only reset readBegin if eof has not been reached
     297            readBegin--;
     298            storeEnd = readBegin;
     299        }
    297300    }
    298301
     
    417420    }
    418421
     422    boolean hasNextToken() {
     423        reset();
     424        int ch = peek();
     425
     426        // whitespace
     427        while (ch == 0x20 || ch == 0x09 || ch == 0x0a || ch == 0x0d) {
     428            if (ch == '\r') {
     429                ++lineNo;
     430                ++readBegin;
     431                ch = peek();
     432                if (ch == '\n') {
     433                    lastLineOffset = bufferOffset+readBegin+1;
     434                } else {
     435                    lastLineOffset = bufferOffset+readBegin;
     436                    continue;
     437                }
     438            } else if (ch == '\n') {
     439                ++lineNo;
     440                lastLineOffset = bufferOffset+readBegin+1;
     441            }
     442            ++readBegin;
     443            ch = peek();
     444        }
     445        return ch != -1;
     446    }
     447
     448    private int peek() {
     449        try {
     450            if (readBegin == readEnd) {     // need to fill the buffer
     451                int len = fillBuf();
     452                if (len == -1) {
     453                    return -1;
     454                }
     455                assert len != 0;
     456                readBegin = storeEnd;
     457                readEnd = readBegin+len;
     458            }
     459            return buf[readBegin];
     460        } catch (IOException ioe) {
     461            throw new JsonException(JsonMessages.TOKENIZER_IO_ERR(), ioe);
     462        }
     463    }
     464
    419465    // Gives the location of the last char. Used for
    420466    // JsonParsingException.getLocation
     
    499545        // no need to create BigDecimal for common integer values (1-9 digits)
    500546        int storeLen = storeEnd-storeBegin;
    501         if (!fracOrExp && (storeLen <= 9 || (minus && storeLen == 10))) {
     547        if (!fracOrExp && (storeLen <= 9 || (minus && storeLen <= 10))) {
    502548            int num = 0;
    503549            int i = minus ? 1 : 0;
     
    510556        }
    511557    }
     558   
     559    long getLong() {
     560        // no need to create BigDecimal for common integer values (1-18 digits)
     561        int storeLen = storeEnd-storeBegin;
     562        if (!fracOrExp && (storeLen <= 18 || (minus && storeLen <= 19))) {
     563            long num = 0;
     564            int i = minus ? 1 : 0;
     565            for(; i < storeLen; i++) {
     566                num = num * 10 + (buf[storeBegin+i] - '0');
     567            }
     568            return minus ? -num : num;
     569        } else {
     570            return getBigDecimal().longValue();
     571        }
     572    }
    512573
    513574    // returns true for common integer values (1-9 digits).
     
    515576    boolean isDefinitelyInt() {
    516577        int storeLen = storeEnd-storeBegin;
    517         return !fracOrExp && (storeLen <= 9 || (minus && storeLen == 10));
     578        return !fracOrExp && (storeLen <= 9 || (minus && storeLen <= 10));
     579    }
     580   
     581    // returns true for common long values (1-18 digits).
     582    // So there are cases it will return false even though the number is long
     583    boolean isDefinitelyLong() {
     584        int storeLen = storeEnd-storeBegin;
     585        return !fracOrExp && (storeLen <= 18 || (minus && storeLen <= 19));
    518586    }
    519587
  • trunk/src/org/glassfish/json/JsonWriterFactoryImpl.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
  • trunk/src/org/glassfish/json/JsonWriterImpl.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    4949import java.io.Writer;
    5050import java.nio.charset.Charset;
     51import java.nio.charset.StandardCharsets;
    5152import java.util.Map;
    5253
     
    5758 */
    5859class JsonWriterImpl implements JsonWriter {
    59     private static final Charset UTF_8 = Charset.forName("UTF-8");
    6060
    6161    private final JsonGeneratorImpl generator;
     
    7575
    7676    JsonWriterImpl(OutputStream out, BufferPool bufferPool) {
    77         this(out, UTF_8, false, bufferPool);
     77        this(out, StandardCharsets.UTF_8, false, bufferPool);
    7878    }
    7979
    8080    JsonWriterImpl(OutputStream out, boolean prettyPrinting, BufferPool bufferPool) {
    81         this(out, UTF_8, prettyPrinting, bufferPool);
     81        this(out, StandardCharsets.UTF_8, prettyPrinting, bufferPool);
    8282    }
    8383
     
    146146
    147147    @Override
     148    public void write(JsonValue value) {
     149        switch (value.getValueType()) {
     150            case OBJECT:
     151                writeObject((JsonObject) value);
     152                return;
     153            case ARRAY:
     154                writeArray((JsonArray) value);
     155                return;
     156            default:
     157                if (writeDone) {
     158                    throw new IllegalStateException(JsonMessages.WRITER_WRITE_ALREADY_CALLED());
     159                }
     160                writeDone = true;
     161                generator.write(value);
     162                generator.flushBuffer();
     163                if (os != null) {
     164                    generator.flush();
     165                }
     166        }
     167    }
     168
     169    @Override
    148170    public void close() {
    149171        writeDone = true;
  • trunk/src/org/glassfish/json/UnicodeDetectingInputStream.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    4646import java.io.InputStream;
    4747import java.nio.charset.Charset;
     48import java.nio.charset.StandardCharsets;
    4849
    4950/**
     
    5455 */
    5556class UnicodeDetectingInputStream extends FilterInputStream {
    56     private static final Charset UTF_8 = Charset.forName("UTF-8");
    57     private static final Charset UTF_16BE = Charset.forName("UTF-16BE");
    58     private static final Charset UTF_16LE = Charset.forName("UTF-16LE");
     57
    5958    private static final Charset UTF_32LE = Charset.forName("UTF-32LE");
    6059    private static final Charset UTF_32BE = Charset.forName("UTF-32BE");
     
    122121            buf[3] = (byte)b4;
    123122        } catch (IOException ioe) {
    124             throw new JsonException("I/O error while auto-detecting the encoding of stream", ioe);
     123            throw new JsonException(JsonMessages.PARSER_INPUT_ENC_DETECT_IOERR(), ioe);
    125124        }
    126125    }
     
    129128        fillBuf();
    130129        if (bufLen < 2) {
    131             throw new JsonException("Cannot auto-detect encoding, not enough chars");
     130            throw new JsonException(JsonMessages.PARSER_INPUT_ENC_DETECT_FAILED());
    132131        } else if (bufLen == 4) {
    133132            // Use BOM to detect encoding
     
    140139            } else if (buf[0] == FE && buf[1] == FF) {
    141140                curIndex = 2;
    142                 return UTF_16BE;
     141                return StandardCharsets.UTF_16BE;
    143142            } else if (buf[0] == FF && buf[1] == FE) {
    144143                curIndex = 2;
    145                 return UTF_16LE;
     144                return StandardCharsets.UTF_16LE;
    146145            } else if (buf[0] == EF && buf[1] == BB && buf[2] == BF) {
    147146                curIndex = 3;
    148                 return UTF_8;
     147                return StandardCharsets.UTF_8;
    149148            }
    150149            // No BOM, just use JSON RFC's encoding algo to auto-detect
     
    152151                return UTF_32BE;
    153152            } else if (buf[0] == NUL && buf[2] == NUL) {
    154                 return UTF_16BE;
     153                return StandardCharsets.UTF_16BE;
    155154            } else if (buf[1] == NUL && buf[2] == NUL && buf[3] == NUL) {
    156155                return UTF_32LE;
    157156            } else if (buf[1] == NUL && buf[3] == NUL) {
    158                 return UTF_16LE;
     157                return StandardCharsets.UTF_16LE;
    159158            }
    160159        }
    161         return UTF_8;
     160        return StandardCharsets.UTF_8;
    162161    }
    163162
  • trunk/src/org/glassfish/json/api/BufferPool.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    6161    /**
    6262     * Returns an object back to the pool.
     63     *
     64     * @param buf object to return back to the pool
    6365     */
    6466    void recycle(char[] buf);
Note: See TracChangeset for help on using the changeset viewer.