Coverage Report - org.apache.commons.flatfile.InputFilteringDynamicField
 
Classes in this File Line Coverage Branch Coverage Complexity
InputFilteringDynamicField
0%
0/20
0%
0/4
1.571
 
 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;
 18  
 
 19  
 import java.io.IOException;
 20  
 import java.io.InputStream;
 21  
 
 22  
 import org.apache.commons.flatfile.util.FilterFactory;
 23  
 
 24  
 /**
 25  
  * Dynamic field with filtered input. This allows a user to set up a means by which an Entity containing a nested
 26  
  * DynamicField can have a input read in without the DynamicField consuming everything. Instead its filterFactory helps
 27  
  * to filter the incoming data for release at the proper point in the stream.
 28  
  * TODO test
 29  
  * @version $Revision: 758023 $ $Date: 2009-03-24 16:09:19 -0500 (Tue, 24 Mar 2009) $
 30  
  */
 31  
 public class InputFilteringDynamicField extends DynamicField {
 32  
     private static final long serialVersionUID = 5179298156801023038L;
 33  
 
 34  
     private FilterFactory filterFactory;
 35  
 
 36  
     /**
 37  
      * Create a new InputFilteringDynamicField.
 38  
      */
 39  
     public InputFilteringDynamicField() {
 40  0
         super();
 41  0
     }
 42  
 
 43  
     /**
 44  
      * Create a new InputFilteringDynamicField.
 45  
      * @param filterFactory to filter input
 46  
      */
 47  
     public InputFilteringDynamicField(FilterFactory filterFactory) {
 48  0
         this();
 49  0
         setFilterFactory(filterFactory);
 50  0
     }
 51  
 
 52  
     /**
 53  
      * Create a new InputFilteringDynamicField.
 54  
      * @param bounds field bounds
 55  
      */
 56  
     public InputFilteringDynamicField(Bounds bounds) {
 57  0
         super(bounds);
 58  0
     }
 59  
 
 60  
     /**
 61  
      * Create a new InputFilteringDynamicField.
 62  
      * @param bounds field bounds
 63  
      * @param filterFactory to filter input
 64  
      */
 65  
     public InputFilteringDynamicField(Bounds bounds, FilterFactory filterFactory) {
 66  0
         this(bounds);
 67  0
         setFilterFactory(filterFactory);
 68  0
     }
 69  
 
 70  
     /**
 71  
      * {@inheritDoc}
 72  
      */
 73  
     public synchronized void readFrom(InputStream is) throws IOException {
 74  0
         if (filterFactory == null) {
 75  0
             throw new IllegalStateException("filterFactory has not been set");
 76  
         }
 77  0
         InputStream filter = filterFactory.getFilter(is);
 78  0
         if (filter == null) {
 79  0
             throw new IllegalArgumentException("Filter factory "
 80  
                     + filterFactory + " cannot filter " + is);
 81  
         }
 82  0
         super.readFrom(filter);
 83  0
     }
 84  
 
 85  
     /**
 86  
      * Get the filterFactory.
 87  
      * @return FilterFactory
 88  
      */
 89  
     public FilterFactory getFilterFactory() {
 90  0
         return filterFactory;
 91  
     }
 92  
 
 93  
     /**
 94  
      * Set the filterFactory.
 95  
      * @param filterFactory the FilterFactory filterFactory to set
 96  
      */
 97  
     public void setFilterFactory(FilterFactory filterFactory) {
 98  0
         this.filterFactory = filterFactory;
 99  0
     }
 100  
 }