Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 154   Methods: 7
NCLOC: 46   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
LogOutputStream.java 83.3% 93.8% 85.7% 89.7%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
 5   
  * reserved.
 6   
  *
 7   
  * Redistribution and use in source and binary forms, with or without
 8   
  * modification, are permitted provided that the following conditions
 9   
  * are met:
 10   
  *
 11   
  * 1. Redistributions of source code must retain the above copyright
 12   
  *    notice, this list of conditions and the following disclaimer.
 13   
  *
 14   
  * 2. Redistributions in binary form must reproduce the above copyright
 15   
  *    notice, this list of conditions and the following disclaimer in
 16   
  *    the documentation and/or other materials provided with the
 17   
  *    distribution.
 18   
  *
 19   
  * 3. The end-user documentation included with the redistribution, if
 20   
  *    any, must include the following acknowlegement:
 21   
  *       "This product includes software developed by the
 22   
  *        Apache Software Foundation (http://www.apache.org/)."
 23   
  *    Alternately, this acknowlegement may appear in the software itself,
 24   
  *    if and wherever such third-party acknowlegements normally appear.
 25   
  *
 26   
  * 4. The names "Ant" and "Apache Software
 27   
  *    Foundation" must not be used to endorse or promote products derived
 28   
  *    from this software without prior written permission. For written
 29   
  *    permission, please contact apache@apache.org.
 30   
  *
 31   
  * 5. Products derived from this software may not be called "Apache"
 32   
  *    nor may "Apache" appear in their names without prior written
 33   
  *    permission of the Apache Group.
 34   
  *
 35   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 36   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 37   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 38   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 39   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 40   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 41   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 42   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 43   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 44   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 45   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46   
  * SUCH DAMAGE.
 47   
  * ====================================================================
 48   
  *
 49   
  * This software consists of voluntary contributions made by many
 50   
  * individuals on behalf of the Apache Software Foundation.  For more
 51   
  * information on the Apache Software Foundation, please see
 52   
  * <http://www.apache.org/>.
 53   
  */
 54   
 
 55   
 package org.apache.tools.ant.taskdefs;
 56   
 
 57   
 import java.io.ByteArrayOutputStream;
 58   
 import java.io.IOException;
 59   
 import java.io.OutputStream;
 60   
 import org.apache.tools.ant.Project;
 61   
 import org.apache.tools.ant.Task;
 62   
 
 63   
 
 64   
 /**
 65   
  * Logs each line written to this stream to the log system of ant.
 66   
  *
 67   
  * Tries to be smart about line separators.<br>
 68   
  * TODO: This class can be split to implement other line based processing
 69   
  * of data written to the stream.
 70   
  *
 71   
  * @author thomas.haas@softwired-inc.com
 72   
  * @since Ant 1.2
 73   
  */
 74   
 public class LogOutputStream extends OutputStream {
 75   
 
 76   
     private ByteArrayOutputStream buffer = new ByteArrayOutputStream();
 77   
     private boolean skip = false;
 78   
 
 79   
     private Task task;
 80   
     private int level = Project.MSG_INFO;
 81   
 
 82   
     /**
 83   
      * Creates a new instance of this class.
 84   
      *
 85   
      * @param task the task for whom to log
 86   
      * @param level loglevel used to log data written to this stream.
 87   
      */
 88  210
     public LogOutputStream(Task task, int level) {
 89  210
         this.task = task;
 90  210
         this.level = level;
 91   
     }
 92   
 
 93   
 
 94   
     /**
 95   
      * Write the data to the buffer and flush the buffer, if a line
 96   
      * separator is detected.
 97   
      *
 98   
      * @param cc data to log (byte).
 99   
      */
 100  62041
     public void write(int cc) throws IOException {
 101  62041
         final byte c = (byte) cc;
 102  62041
         if ((c == '\n') || (c == '\r')) {
 103  1179
             if (!skip) {
 104  1179
               processBuffer();
 105   
             }
 106   
         } else {
 107  60862
           buffer.write(cc);
 108   
         }
 109  62041
         skip = (c == '\r');
 110   
     }
 111   
 
 112   
 
 113   
     /**
 114   
      * Converts the buffer to a string and sends it to <code>processLine</code>
 115   
      */
 116  1187
     protected void processBuffer() {
 117  1187
         processLine(buffer.toString());
 118  1187
         buffer.reset();
 119   
     }
 120   
 
 121   
     /**
 122   
      * Logs a line to the log system of ant.
 123   
      *
 124   
      * @param line the line to log.
 125   
      */
 126  1187
     protected void processLine(String line) {
 127  1187
         processLine(line, level);
 128   
     }
 129   
 
 130   
     /**
 131   
      * Logs a line to the log system of ant.
 132   
      *
 133   
      * @param line the line to log.
 134   
      */
 135  1187
     protected void processLine(String line, int level) {
 136  1187
         task.log(line, level);
 137   
     }
 138   
 
 139   
 
 140   
     /**
 141   
      * Writes all remaining
 142   
      */
 143  206
     public void close() throws IOException {
 144  206
         if (buffer.size() > 0) {
 145  8
           processBuffer();
 146   
         }
 147  206
         super.close();
 148   
     }
 149   
 
 150  0
     public int getMessageLevel() {
 151  0
         return level;
 152   
     }
 153   
 }
 154