Coverage Report - org.apache.commons.pipeline.stage.InputStreamLineBreakStage
 
Classes in this File Line Coverage Branch Coverage Complexity
InputStreamLineBreakStage
62%
13/21
50%
3/6
1.8
 
 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  
 
 18  
 package org.apache.commons.pipeline.stage;
 19  
 
 20  
 import java.io.BufferedReader;
 21  
 import java.io.IOException;
 22  
 import java.io.InputStream;
 23  
 import java.io.InputStreamReader;
 24  
 import org.apache.commons.pipeline.stage.BaseStage;
 25  
 import org.apache.commons.pipeline.StageException;
 26  
 
 27  
 /**
 28  
  * Breaks up an InputStream by line and exqueues each resulting line.
 29  
  */
 30  
 public class InputStreamLineBreakStage extends BaseStage {
 31  
     /**
 32  
      * Holds value of property ignoringBlankLines.
 33  
      */
 34  1
     private boolean ignoringBlankLines = false;
 35  
     
 36  
     /** Creates a new instance of InputStreamLineBreakStage */
 37  
     public InputStreamLineBreakStage() {
 38  1
         super();
 39  1
     }
 40  
 
 41  
     /** Creates a new instance of InputStreamLineBreakStage */
 42  0
     public InputStreamLineBreakStage(boolean ignoringBlankLines) {
 43  0
         this.ignoringBlankLines = ignoringBlankLines;
 44  0
     }
 45  
 
 46  
     public void process(Object obj) throws org.apache.commons.pipeline.StageException {
 47  1
         InputStream is = (InputStream) obj;
 48  
         try {
 49  1
             InputStreamReader reader = new InputStreamReader(is);
 50  1
             BufferedReader buffered = new BufferedReader(reader);
 51  1
             String line = buffered.readLine();
 52  4
             while (line != null){
 53  3
                 if (!(ignoringBlankLines && line.trim().equals(""))) {
 54  3
                     this.emit(line);
 55  
                 }
 56  3
                 line = buffered.readLine();
 57  
             }
 58  0
         } catch (IOException e){
 59  0
             throw new StageException(this, e);
 60  1
         }
 61  1
     }
 62  
 
 63  
     /**
 64  
      * Getter for property ignoreBlankLines.
 65  
      * @return Value of property ignoreBlankLines.
 66  
      */
 67  
     public boolean isIgnoringBlankLines()  {
 68  0
         return this.ignoringBlankLines;
 69  
     }
 70  
 
 71  
     /**
 72  
      * Specifies that this stage will not exqueue blank lines.
 73  
      * @param ignoreBlankLines New value of property ignoreBlankLines.
 74  
      */
 75  
     public void setIgnoringBlankLines(boolean ignoringBlankLines)  {
 76  0
         this.ignoringBlankLines = ignoringBlankLines;
 77  0
     }
 78  
 }