Coverage Report - org.apache.maven.shared.invoker.PrintStreamHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
PrintStreamHandler
78%
11/14
83%
5/6
2,333
 
 1  
 package org.apache.maven.shared.invoker;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.io.PrintStream;
 23  
 
 24  
 /**
 25  
  * Offers an output handler that writes to a print stream like {@link System#out}.
 26  
  * 
 27  
  * @version $Id: PrintStreamHandler.java 681956 2008-08-02 11:43:44Z dennisl $
 28  
  * @since 2.0.9
 29  
  */
 30  
 public class PrintStreamHandler
 31  
     implements InvocationOutputHandler
 32  
 {
 33  
 
 34  
     /**
 35  
      * The print stream to write to, never <code>null</code>.
 36  
      */
 37  
     private PrintStream out;
 38  
 
 39  
     /**
 40  
      * A flag whether the print stream should be flushed after each line.
 41  
      */
 42  
     private boolean alwaysFlush;
 43  
 
 44  
     /**
 45  
      * Creates a new output handler that writes to {@link System#out}.
 46  
      */
 47  
     public PrintStreamHandler()
 48  
     {
 49  0
         this( System.out, false );
 50  0
     }
 51  
 
 52  
     /**
 53  
      * Creates a new output handler that writes to the specified print stream.
 54  
      * 
 55  
      * @param out The print stream to write to, must not be <code>null</code>.
 56  
      * @param alwaysFlush A flag whether the print stream should be flushed after each line.
 57  
      */
 58  
     public PrintStreamHandler( PrintStream out, boolean alwaysFlush )
 59  4
     {
 60  4
         if ( out == null )
 61  
         {
 62  0
             throw new NullPointerException( "missing output stream" );
 63  
         }
 64  4
         this.out = out;
 65  4
         this.alwaysFlush = alwaysFlush;
 66  4
     }
 67  
 
 68  
     public void consumeLine( String line )
 69  
     {
 70  1831
         if ( line == null )
 71  
         {
 72  1
             out.println();
 73  
         }
 74  
         else
 75  
         {
 76  1830
             out.println( line );
 77  
         }
 78  
 
 79  1831
         if ( alwaysFlush )
 80  
         {
 81  1
             out.flush();
 82  
         }
 83  1831
     }
 84  
 
 85  
 }