Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 237   Methods: 10
NCLOC: 78   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
BaseFilterReader.java 66.7% 81.8% 90% 78.7%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 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   
 package org.apache.tools.ant.filters;
 55   
 
 56   
 import java.io.FilterReader;
 57   
 import java.io.IOException;
 58   
 import java.io.Reader;
 59   
 import java.io.StringReader;
 60   
 import org.apache.tools.ant.Project;
 61   
 import org.apache.tools.ant.util.FileUtils;
 62   
 
 63   
 /**
 64   
  * Base class for core filter readers.
 65   
  *
 66   
  * @author Magesh Umasankar
 67   
  */
 68   
 public abstract class BaseFilterReader
 69   
     extends FilterReader {
 70   
     /** Have the parameters passed been interpreted? */
 71   
     private boolean initialized = false;
 72   
 
 73   
     /** The Ant project this filter is part of. */
 74   
     private Project project = null;
 75   
 
 76   
     /**
 77   
      * Constructor used by Ant's introspection mechanism.
 78   
      * The original filter reader is only used for chaining
 79   
      * purposes, never for filtering purposes (and indeed
 80   
      * it would be useless for filtering purposes, as it has
 81   
      * no real data to filter). ChainedReaderHelper uses
 82   
      * this placeholder instance to create a chain of real filters.
 83   
      */
 84  17
     public BaseFilterReader() {
 85  17
         super(new StringReader(new String()));
 86  17
         try {
 87  17
             close();
 88   
         } catch (IOException  ioe) {
 89   
             // Ignore
 90   
         }
 91   
     }
 92   
 
 93   
     /**
 94   
      * Creates a new filtered reader.
 95   
      *
 96   
      * @param in A Reader object providing the underlying stream.
 97   
      *           Must not be <code>null</code>.
 98   
      *           
 99   
      */
 100  21
     public BaseFilterReader(final Reader in) {
 101  21
         super(in);
 102   
     }
 103   
 
 104   
     /**
 105   
      * Reads characters into a portion of an array.  This method will block
 106   
      * until some input is available, an I/O error occurs, or the end of the
 107   
      * stream is reached.
 108   
      *
 109   
      * @param      cbuf  Destination buffer to write characters to. 
 110   
      *                   Must not be <code>null</code>.
 111   
      * @param      off   Offset at which to start storing characters.
 112   
      * @param      len   Maximum number of characters to read.
 113   
      *
 114   
      * @return     the number of characters read, or -1 if the end of the
 115   
      *             stream has been reached
 116   
      *
 117   
      * @exception  IOException  If an I/O error occurs
 118   
      */
 119  39
     public final int read(final char cbuf[], final int off,
 120   
                           final int len) throws IOException {
 121  39
         for (int i = 0; i < len; i++) {
 122  1436
             final int ch = read();
 123  1436
             if (ch == -1) {
 124  37
                 if (i == 0) {
 125  22
                     return -1;
 126   
                 } else {
 127  15
                     return i;
 128   
                 }
 129   
             }
 130  1399
             cbuf[off + i] = (char) ch;
 131   
         }
 132  2
         return len;
 133   
     }
 134   
 
 135   
     /**
 136   
      * Skips characters.  This method will block until some characters are
 137   
      * available, an I/O error occurs, or the end of the stream is reached.
 138   
      *
 139   
      * @param  n  The number of characters to skip
 140   
      *
 141   
      * @return    the number of characters actually skipped
 142   
      *
 143   
      * @exception  IllegalArgumentException  If <code>n</code> is negative.
 144   
      * @exception  IOException  If an I/O error occurs
 145   
      */
 146  0
     public final long skip(final long n) throws IOException {
 147  0
         if (n < 0L) {
 148  0
             throw new IllegalArgumentException("skip value is negative");
 149   
         }
 150   
 
 151  0
         for (long i = 0; i < n; i++) {
 152  0
             if (read() == -1) {
 153  0
                 return i;
 154   
             }
 155   
         }
 156  0
         return n;
 157   
     }
 158   
 
 159   
     /**
 160   
      * Sets the initialized status.
 161   
      * 
 162   
      * @param initialized Whether or not the filter is initialized.
 163   
      */
 164  19
     protected final void setInitialized(final boolean initialized) {
 165  19
         this.initialized = initialized;
 166   
     }
 167   
 
 168   
     /**
 169   
      * Returns the initialized status.
 170   
      * 
 171   
      * @return whether or not the filter is initialized
 172   
      */
 173  1056
     protected final boolean getInitialized() {
 174  1056
         return initialized;
 175   
     }
 176   
 
 177   
     /**
 178   
      * Sets the project to work with.
 179   
      * 
 180   
      * @param project The project this filter is part of. 
 181   
      *                Should not be <code>null</code>.
 182   
      */
 183  23
     public final void setProject(final Project project) {
 184  23
         this.project = project;
 185   
     }
 186   
 
 187   
     /**
 188   
      * Returns the project this filter is part of.
 189   
      * 
 190   
      * @return the project this filter is part of
 191   
      */
 192  4
     protected final Project getProject() {
 193  4
         return project;
 194   
     }
 195   
 
 196   
     /**
 197   
      * Reads a line of text ending with '\n' (or until the end of the stream).
 198   
      * The returned String retains the '\n'.
 199   
      * 
 200   
      * @return the line read, or <code>null</code> if the end of the stream
 201   
      * has already been reached
 202   
      * 
 203   
      * @exception IOException if the underlying reader throws one during 
 204   
      *                        reading
 205   
      */
 206  36
     protected final String readLine() throws IOException {
 207  36
         int ch = in.read();
 208   
         
 209  36
         if (ch == -1) {
 210  14
             return null;
 211   
         }
 212   
             
 213  22
         StringBuffer line = new StringBuffer();
 214   
                 
 215  22
         while (ch != -1) {
 216  358
             line.append ((char) ch);
 217  358
             if (ch == '\n') {
 218  18
                 break;
 219   
             }
 220  340
             ch = in.read();
 221   
         }
 222  22
         return line.toString();
 223   
     }
 224   
 
 225   
     /**
 226   
      * Reads to the end of the stream, returning the contents as a String.
 227   
      * 
 228   
      * @return the remaining contents of the reader, as a String
 229   
      * 
 230   
      * @exception IOException if the underlying reader throws one during 
 231   
      *            reading
 232   
      */
 233  5
     protected final String readFully() throws IOException {
 234  5
         return FileUtils.readFully(in, 8192);
 235   
     }
 236   
 }
 237