Coverage Report - org.apache.johnzon.core.JsonWriterImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
JsonWriterImpl
60%
14/23
75%
3/4
1,5
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements. See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership. The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License. You may obtain a copy of the License at
 9  
  *
 10  
  * http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied. See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.apache.johnzon.core;
 20  
 
 21  
 import java.io.Serializable;
 22  
 
 23  
 import javax.json.JsonArray;
 24  
 import javax.json.JsonObject;
 25  
 import javax.json.JsonStructure;
 26  
 import javax.json.JsonWriter;
 27  
 import javax.json.stream.JsonGenerator;
 28  
 
 29  
 class JsonWriterImpl implements JsonWriter, Serializable{
 30  
     private final JsonGenerator generator;
 31  1
     private boolean closed = false;
 32  
 
 33  1
     JsonWriterImpl(final JsonGenerator generator) {
 34  1
         this.generator = generator;
 35  1
     }
 36  
 
 37  
     @Override
 38  
     public void writeArray(final JsonArray array) {
 39  0
         checkClosed();
 40  0
         generator.write(array);
 41  0
         close();
 42  0
     }
 43  
 
 44  
     @Override
 45  
     public void writeObject(final JsonObject object) {
 46  0
         checkClosed();
 47  0
         generator.write(object);
 48  0
         close();
 49  0
     }
 50  
 
 51  
     @Override
 52  
     public void write(final JsonStructure value) {
 53  1
         checkClosed();
 54  1
         generator.write(value);
 55  1
         close();
 56  1
     }
 57  
 
 58  
     @Override
 59  
     public void close() {
 60  
         
 61  2
         if(!closed) {
 62  1
             closed = true;
 63  1
             generator.close();
 64  
         }
 65  2
     }
 66  
     
 67  
     private void checkClosed() {
 68  1
         if(closed) {
 69  0
             throw new IllegalStateException("writeArray(), writeObject(), write() or close() method was already called");
 70  
         }
 71  
            
 72  1
     }
 73  
 }