Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 191   Methods: 7
NCLOC: 59   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
StripLineBreaks.java 35.7% 57.7% 85.7% 55.3%
 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.IOException;
 57   
 import java.io.Reader;
 58   
 import org.apache.tools.ant.types.Parameter;
 59   
 
 60   
 /**
 61   
  * Filter to flatten the stream to a single line.
 62   
  * 
 63   
  * Example:
 64   
  *
 65   
  * <pre>&lt;striplinebreaks/&gt;</pre>
 66   
  *
 67   
  * Or:
 68   
  *
 69   
  * <pre>&lt;filterreader classname=&quot;org.apache.tools.ant.filters.StripLineBreaks&quot;/&gt;</pre>
 70   
  *
 71   
  * @author Steve Loughran
 72   
  * @author Magesh Umasankar
 73   
  */
 74   
 public final class StripLineBreaks
 75   
     extends BaseParamFilterReader
 76   
     implements ChainableReader {
 77   
     /**
 78   
      * Line-breaking characters.
 79   
      * What should we do on funny IBM mainframes with odd line endings?
 80   
      */
 81   
     private static final String DEFAULT_LINE_BREAKS = "\r\n";
 82   
 
 83   
     /** Parameter name for the line-breaking characters parameter. */
 84   
     private static final String LINE_BREAKS_KEY = "linebreaks";
 85   
 
 86   
     /** The characters that are recognized as line breaks. */
 87   
     private String lineBreaks = DEFAULT_LINE_BREAKS;
 88   
 
 89   
     /**
 90   
      * Constructor for "dummy" instances.
 91   
      * 
 92   
      * @see BaseFilterReader#BaseFilterReader()
 93   
      */
 94  1
     public StripLineBreaks() {
 95  1
         super();
 96   
     }
 97   
 
 98   
     /**
 99   
      * Creates a new filtered reader.
 100   
      *
 101   
      * @param in A Reader object providing the underlying stream.
 102   
      *           Must not be <code>null</code>.
 103   
      */
 104  1
     public StripLineBreaks(final Reader in) {
 105  1
         super(in);
 106   
     }
 107   
 
 108   
     /**
 109   
      * Returns the next character in the filtered stream, only including
 110   
      * characters not in the set of line-breaking characters.
 111   
      * 
 112   
      * @return the next character in the resulting stream, or -1
 113   
      * if the end of the resulting stream has been reached
 114   
      * 
 115   
      * @exception IOException if the underlying stream throws an IOException
 116   
      * during reading     
 117   
      */
 118  9
     public final int read() throws IOException {
 119  9
         if (!getInitialized()) {
 120  0
             initialize();
 121  0
             setInitialized(true);
 122   
         }
 123   
 
 124  9
         int ch = in.read();
 125  9
         while (ch != -1) {
 126  11
             if (lineBreaks.indexOf(ch) == -1) {
 127  7
                 break;
 128   
             } else {
 129  4
                 ch = in.read();
 130   
             }
 131   
         }
 132  9
         return ch;
 133   
     }
 134   
 
 135   
     /**
 136   
      * Sets the line-breaking characters.
 137   
      * 
 138   
      * @param lineBreaks A String containing all the characters to be
 139   
      *                   considered as line-breaking.
 140   
      */
 141  1
     public final void setLineBreaks(final String lineBreaks) {
 142  1
         this.lineBreaks = lineBreaks;
 143   
     }
 144   
 
 145   
     /**
 146   
      * Returns the line-breaking characters as a String.
 147   
      * 
 148   
      * @return a String containing all the characters considered as 
 149   
      *         line-breaking
 150   
      */
 151  1
     private final String getLineBreaks() {
 152  1
         return lineBreaks;
 153   
     }
 154   
 
 155   
     /**
 156   
      * Creates a new StripLineBreaks using the passed in
 157   
      * Reader for instantiation.
 158   
      * 
 159   
      * @param rdr A Reader object providing the underlying stream.
 160   
      *            Must not be <code>null</code>.
 161   
      * 
 162   
      * @return a new filter based on this configuration, but filtering
 163   
      *         the specified reader
 164   
      */
 165  1
     public final Reader chain(final Reader rdr) {
 166  1
         StripLineBreaks newFilter = new StripLineBreaks(rdr);
 167  1
         newFilter.setLineBreaks(getLineBreaks());
 168  1
         newFilter.setInitialized(true);
 169  1
         return newFilter;
 170   
     }
 171   
 
 172   
     /**
 173   
      * Parses the parameters to set the line-breaking characters.
 174   
      */
 175  0
     private final void initialize() {
 176  0
         String userDefinedLineBreaks = null;
 177  0
         Parameter[] params = getParameters();
 178  0
         if (params != null) {
 179  0
             for (int i = 0; i < params.length; i++) {
 180  0
                 if (LINE_BREAKS_KEY.equals(params[i].getName())) {
 181  0
                     userDefinedLineBreaks = params[i].getValue();
 182  0
                     break;
 183   
                 }
 184   
             }
 185   
         }
 186  0
         if (userDefinedLineBreaks != null) {
 187  0
             lineBreaks = userDefinedLineBreaks;
 188   
         }
 189   
     }
 190   
 }
 191