Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 171   Methods: 5
NCLOC: 56   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
EscapeUnicode.java 64.3% 81.5% 80% 76.1%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2003 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   
  * Converts non latin characters to unicode escapes
 62   
  * Useful to load properties containing non latin
 63   
  * Example:
 64   
  *
 65   
  * <pre>&lt;escapeunicode&gt;</pre>
 66   
  *
 67   
  * Or:
 68   
  *
 69   
  * <pre>&lt;filterreader classname=&quot;org.apache.tools.ant.filters.EscapeUnicode&quot;/&gt;
 70   
 *  </pre>
 71   
  *
 72   
  * @author <a href="mailto:levylambert@tiscali-dsl.de">Antoine Levy-Lambert</a>
 73   
  * @since Ant 1.6
 74   
  */
 75   
 public class EscapeUnicode
 76   
     extends BaseParamFilterReader
 77   
     implements ChainableReader {
 78   
     //this field will hold unnnn right after reading a non latin character
 79   
     //afterwards it will be truncated of one char every call to read
 80   
     private StringBuffer unicodeBuf;
 81   
 
 82   
     /**
 83   
      * Constructor for "dummy" instances.
 84   
      *
 85   
      * @see BaseFilterReader#BaseFilterReader()
 86   
      */
 87  1
     public EscapeUnicode() {
 88  1
         super();
 89  1
         unicodeBuf = new StringBuffer();
 90   
     }
 91   
 
 92   
     /**
 93   
      * Creates a new filtered reader.
 94   
      *
 95   
      * @param in A Reader object providing the underlying stream.
 96   
      *           Must not be <code>null</code>.
 97   
      */
 98  1
     public EscapeUnicode(final Reader in) {
 99  1
         super(in);
 100  1
         unicodeBuf = new StringBuffer();
 101   
     }
 102   
 
 103   
     /**
 104   
      * Returns the next character in the filtered stream, converting non latin
 105   
      * characters to unicode escapes.
 106   
      *
 107   
      * @return the next character in the resulting stream, or -1
 108   
      * if the end of the resulting stream has been reached
 109   
      *
 110   
      * @exception java.io.IOException if the underlying stream throws
 111   
      * an IOException during reading
 112   
      */
 113  377
     public final int read() throws IOException {
 114  377
         if (!getInitialized()) {
 115  0
             initialize();
 116  0
             setInitialized(true);
 117   
         }
 118   
 
 119  377
         int ch= - 1;
 120  377
         if (unicodeBuf.length() == 0) {
 121  317
             ch = in.read();
 122  317
             if (ch != -1) {
 123  315
                 char achar = (char) ch;
 124  315
                 if (achar >= '\u0080') {
 125  12
                     unicodeBuf = new StringBuffer("u0000");
 126  12
                     String s = Integer.toHexString(ch);
 127   
                     //replace the last 0s by the chars contained in s
 128  12
                     for (int i = 0; i < s.length(); i++) {
 129  32
                         unicodeBuf.setCharAt(unicodeBuf.length()
 130   
                                              - s.length() + i,
 131   
                                              s.charAt(i));
 132   
                     }
 133  12
                     ch='\\';
 134   
                 }
 135   
             }
 136   
         } else {
 137  60
             ch = (int) unicodeBuf.charAt(0);
 138  60
             unicodeBuf.deleteCharAt(0);
 139   
         }
 140  377
         return ch;
 141   
     }
 142   
 
 143   
     /**
 144   
      * Creates a new EscapeUnicode using the passed in
 145   
      * Reader for instantiation.
 146   
      *
 147   
      * @param rdr A Reader object providing the underlying stream.
 148   
      *            Must not be <code>null</code>.
 149   
      *
 150   
      * @return a new filter based on this configuration, but filtering
 151   
      *         the specified reader
 152   
      */
 153  1
     public final Reader chain(final Reader rdr) {
 154  1
         EscapeUnicode newFilter = new EscapeUnicode(rdr);
 155  1
         newFilter.setInitialized(true);
 156  1
         return newFilter;
 157   
     }
 158   
 
 159   
     /**
 160   
      * Parses the parameters (currently unused)
 161   
      */
 162  0
     private final void initialize() {
 163  0
         Parameter[] params = getParameters();
 164  0
         if (params != null) {
 165  0
             for (int i = 0; i < params.length; i++) {
 166   
             }
 167   
         }
 168   
     }
 169   
 }
 170   
 
 171