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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.