Coverage Report - org.apache.johnzon.core.JsonReaderFactoryImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
JsonReaderFactoryImpl
88%
15/17
83%
5/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.InputStream;
 22  
 import java.io.Reader;
 23  
 import java.io.Serializable;
 24  
 import java.nio.charset.Charset;
 25  
 import java.util.Collection;
 26  
 import java.util.Collections;
 27  
 import java.util.HashMap;
 28  
 import java.util.Map;
 29  
 import java.util.logging.Logger;
 30  
 
 31  
 import javax.json.JsonReader;
 32  
 import javax.json.JsonReaderFactory;
 33  
 
 34  
 import static java.util.Arrays.asList;
 35  
 
 36  
 class JsonReaderFactoryImpl implements JsonReaderFactory, Serializable {
 37  1
     private static final Logger LOGGER = Logger.getLogger(JsonReaderFactoryImpl.class.getName());
 38  
 
 39  46
     private final Map<String, Object> internalConfig = new HashMap<String, Object>();
 40  1
     private static final Collection<String> SUPPORTED_CONFIG_KEYS = asList(
 41  
         JsonParserFactoryImpl.BUFFER_STRATEGY, JsonParserFactoryImpl.MAX_STRING_LENGTH,
 42  
         JsonParserFactoryImpl.BUFFER_LENGTH, JsonParserFactoryImpl.SUPPORTS_COMMENTS
 43  
     );
 44  
     private final JsonParserFactoryImpl parserFactory;
 45  
 
 46  46
     JsonReaderFactoryImpl(final Map<String, ?> config) {
 47  
 
 48  46
         if(config != null) {
 49  
             
 50  45
             for (String configKey : config.keySet()) {
 51  45
                 if(SUPPORTED_CONFIG_KEYS.contains(configKey)) {
 52  45
                     internalConfig.put(configKey, config.get(configKey));
 53  
                 } else {
 54  0
                     LOGGER.warning(configKey + " not supported by " + getClass().getName());
 55  
                 }
 56  45
             }
 57  
             
 58  45
             this.parserFactory = new JsonParserFactoryImpl(internalConfig);
 59  
             
 60  
         } else {
 61  1
             this.parserFactory = new JsonParserFactoryImpl(null);
 62  
         }
 63  
         
 64  45
     }
 65  
 
 66  
     @Override
 67  
     public JsonReader createReader(final Reader reader) {
 68  7
         return new JsonReaderImpl(parserFactory.createInternalParser(reader));
 69  
     }
 70  
 
 71  
     @Override
 72  
     public JsonReader createReader(final InputStream in) {
 73  85
         return new JsonReaderImpl(parserFactory.createInternalParser(in));
 74  
     }
 75  
 
 76  
     @Override
 77  
     public JsonReader createReader(final InputStream in, final Charset charset) {
 78  54
         return new JsonReaderImpl(parserFactory.createInternalParser(in, charset));
 79  
     }
 80  
 
 81  
     @Override
 82  
     public Map<String, ?> getConfigInUse() {
 83  0
         return Collections.unmodifiableMap(internalConfig);
 84  
     }
 85  
 }