Coverage Report - org.apache.commons.flatfile.util.BasicFilterFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
BasicFilterFactory
0%
0/13
N/A
3.5
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.commons.flatfile.util;
 18  
 
 19  
 import java.io.InputStream;
 20  
 import java.lang.reflect.Constructor;
 21  
 
 22  
 import org.apache.commons.lang3.Validate;
 23  
 import org.apache.commons.lang3.reflect.ConstructorUtils;
 24  
 
 25  
 /**
 26  
  * Basic FilterFactory that creates an instance of a given InputStream subclass with a (InputStream) constructor.
 27  
  * @version $Revision: 1301244 $ $Date: 2012-03-15 17:16:23 -0500 (Thu, 15 Mar 2012) $
 28  
  */
 29  
 public class BasicFilterFactory extends FilterFactory {
 30  
     private static final long serialVersionUID = 9080292216759574895L;
 31  
 
 32  
     private final Constructor<? extends InputStream> constructor;
 33  
 
 34  
     /**
 35  
      * Create a new BasicFilterFactory instance.
 36  
      * @param type (Filter)InputStream type to instantiate.
 37  
      */
 38  0
     public BasicFilterFactory(Class<? extends InputStream> type) {
 39  0
         Validate.isAssignableFrom(InputStream.class, type);
 40  0
         this.constructor =
 41  0
             Validate.notNull(ConstructorUtils.getAccessibleConstructor(type,
 42  0
                 InputStream.class), String.format(
 43  0
                 "Constructor %s(%s) not found", type.getName(),
 44  0
                 InputStream.class.getName()));
 45  0
     }
 46  
 
 47  
     /**
 48  
      * {@inheritDoc}
 49  
      */
 50  
     protected InputStream iGetFilter(InputStream markIsSupported) {
 51  
         try {
 52  0
             return constructor.newInstance(markIsSupported);
 53  0
         } catch (RuntimeException e) {
 54  0
             throw e;
 55  0
         } catch (Exception e) {
 56  0
             throw new RuntimeException(e);
 57  
         }
 58  
     }
 59  
 }