Coverage Report - org.apache.johnzon.core.JsonWriterFactoryImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
JsonWriterFactoryImpl
55%
10/18
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.Collection;
 27  
 import java.util.Collections;
 28  
 import java.util.HashMap;
 29  
 import java.util.Map;
 30  
 import java.util.logging.Logger;
 31  
 
 32  
 import javax.json.JsonWriter;
 33  
 import javax.json.JsonWriterFactory;
 34  
 import javax.json.stream.JsonGenerator;
 35  
 import javax.json.stream.JsonGeneratorFactory;
 36  
 
 37  
 import static java.util.Arrays.asList;
 38  
 
 39  
 class JsonWriterFactoryImpl implements JsonWriterFactory, Serializable {
 40  1
     private static final Logger LOGGER = Logger.getLogger(JsonWriterFactoryImpl.class.getName());
 41  
 
 42  1
     private static final Charset UTF8_CHARSET = Charset.forName("UTF-8");
 43  1
     private final Map<String, Object> internalConfig = new HashMap<String, Object>();
 44  1
     private static final Collection<String> SUPPORTED_CONFIG_KEYS = asList(
 45  
         JsonGenerator.PRETTY_PRINTING
 46  
     );
 47  
     private final JsonGeneratorFactory factory;
 48  
 
 49  1
     JsonWriterFactoryImpl(final Map<String, ?> config) {
 50  1
         if (config != null) {
 51  
 
 52  0
             for (final String configKey : config.keySet()) {
 53  0
                 if (SUPPORTED_CONFIG_KEYS.contains(configKey)) {
 54  0
                     internalConfig.put(configKey, config.get(configKey));
 55  
                 } else {
 56  0
                     LOGGER.warning(configKey + " not supported by " + getClass().getName());
 57  
                 }
 58  0
             }
 59  
 
 60  0
             this.factory = new JsonGeneratorFactoryImpl(internalConfig);
 61  
         } else {
 62  1
             this.factory = new JsonGeneratorFactoryImpl(null);
 63  
         }
 64  
 
 65  1
     }
 66  
 
 67  
     @Override
 68  
     public JsonWriter createWriter(final Writer writer) {
 69  1
         return new JsonWriterImpl(factory.createGenerator(writer));
 70  
     }
 71  
 
 72  
     @Override
 73  
     public JsonWriter createWriter(final OutputStream out) {
 74  1
         return createWriter(new OutputStreamWriter(out, UTF8_CHARSET));
 75  
     }
 76  
 
 77  
     @Override
 78  
     public JsonWriter createWriter(final OutputStream out, final Charset charset) {
 79  0
         return createWriter(new OutputStreamWriter(out, charset));
 80  
     }
 81  
 
 82  
     @Override
 83  
     public Map<String, ?> getConfigInUse() {
 84  0
         return Collections.unmodifiableMap(internalConfig);
 85  
     }
 86  
 }