Coverage Report - org.apache.johnzon.core.JsonWriterFactoryImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
JsonWriterFactoryImpl
60%
9/15
16%
1/6
1,6
 
 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.OutputStream;
 22  
 import java.io.OutputStreamWriter;
 23  
 import java.io.Serializable;
 24  
 import java.io.Writer;
 25  
 import java.nio.charset.Charset;
 26  
 import java.util.Collections;
 27  
 import java.util.HashMap;
 28  
 import java.util.Map;
 29  
 
 30  
 import javax.json.JsonWriter;
 31  
 import javax.json.JsonWriterFactory;
 32  
 import javax.json.stream.JsonGenerator;
 33  
 import javax.json.stream.JsonGeneratorFactory;
 34  
 
 35  
 class JsonWriterFactoryImpl implements JsonWriterFactory, Serializable {
 36  1
     private static final Charset UTF8_CHARSET = Charset.forName("UTF-8");
 37  1
     private final Map<String, Object> internalConfig = new HashMap<String, Object>();
 38  1
     private static final String[] SUPPORTED_CONFIG_KEYS = new String[] {
 39  
 
 40  
     JsonGenerator.PRETTY_PRINTING
 41  
 
 42  
     };
 43  
     private final JsonGeneratorFactory factory;
 44  
 
 45  1
     JsonWriterFactoryImpl(final Map<String, ?> config) {
 46  1
         if (config != null) {
 47  
 
 48  0
             for (final String configKey : SUPPORTED_CONFIG_KEYS) {
 49  0
                 if (config.containsKey(configKey)) {
 50  0
                     internalConfig.put(configKey, config.get(configKey));
 51  
                 }
 52  
             }
 53  
 
 54  0
             this.factory = new JsonGeneratorFactoryImpl(internalConfig);
 55  
         } else {
 56  1
             this.factory = new JsonGeneratorFactoryImpl(null);
 57  
         }
 58  
 
 59  1
     }
 60  
 
 61  
     @Override
 62  
     public JsonWriter createWriter(final Writer writer) {
 63  1
         return new JsonWriterImpl(factory.createGenerator(writer));
 64  
     }
 65  
 
 66  
     @Override
 67  
     public JsonWriter createWriter(final OutputStream out) {
 68  1
         return createWriter(new OutputStreamWriter(out, UTF8_CHARSET));
 69  
     }
 70  
 
 71  
     @Override
 72  
     public JsonWriter createWriter(final OutputStream out, final Charset charset) {
 73  0
         return createWriter(new OutputStreamWriter(out, charset));
 74  
     }
 75  
 
 76  
     @Override
 77  
     public Map<String, ?> getConfigInUse() {
 78  0
         return Collections.unmodifiableMap(internalConfig);
 79  
     }
 80  
 }