ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From umag...@apache.org
Subject cvs commit: jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters BaseFilterReader.java HeadFilter.java LineContains.java PrefixLines.java ReplaceTokens.java StripJavaComments.java StripLineBreaks.java StripLineComments.java TabsToSpaces.java TailFilter.java
Date Thu, 28 Feb 2002 01:48:49 GMT
umagesh     02/02/27 17:48:49

  Modified:    proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters
                        HeadFilter.java LineContains.java PrefixLines.java
                        ReplaceTokens.java StripJavaComments.java
                        StripLineBreaks.java StripLineComments.java
                        TabsToSpaces.java TailFilter.java
  Added:       proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters
                        BaseFilterReader.java
  Log:
  1. Move a couple of common methods to an abstract base class.
  2. Javadoc
  
  Revision  Changes    Path
  1.7       +30 -35    jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/HeadFilter.java
  
  Index: HeadFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/HeadFilter.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- HeadFilter.java	27 Feb 2002 20:48:44 -0000	1.6
  +++ HeadFilter.java	28 Feb 2002 01:48:49 -0000	1.7
  @@ -53,10 +53,8 @@
    */
   package org.apache.tools.ant.filters;
   
  -import java.io.FilterReader;
   import java.io.IOException;
   import java.io.Reader;
  -import java.io.StringReader;
   
   import org.apache.tools.ant.types.Parameter;
   import org.apache.tools.ant.types.Parameterizable;
  @@ -78,19 +76,25 @@
    * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
    */
   public final class HeadFilter
  -    extends FilterReader
  +    extends BaseFilterReader
       implements Parameterizable, ChainableReader
   {
  +    /** Lines key to represent the number of lines to be returned. */
       private static final String LINES_KEY = "lines";
   
  +    /** The passed in parameter array. */
       private Parameter[] parameters;
   
  +    /** Have the parameters passed been interpreted? */
       private boolean initialized = false;
   
  +    /** Number of lines currently read in. */
       private long linesRead = 0;
   
  +    /** Default number of lines returned. */
       private long lines = 10;
   
  +    /** If the next character being read is a linefeed, must it be ignored? */
       private boolean ignoreLineFeed = false;
   
       /**
  @@ -100,13 +104,7 @@
        * that is created making it useless for further operations.
        */
       public HeadFilter() {
  -        // Dummy constructor to be invoked by Ant's Introspector
  -        super(new StringReader(new String()));
  -        try {
  -            close();
  -        } catch (IOException  ioe) {
  -            // Ignore
  -        }
  +        super();
       }
   
       /**
  @@ -118,6 +116,9 @@
           super(in);
       }
   
  +    /**
  +     * Read the first n lines.
  +     */
       public final int read() throws IOException {
           if (!getInitialized()) {
               initialize();
  @@ -151,47 +152,38 @@
           return ch;
       }
   
  -    public final int read(final char cbuf[], final int off,
  -                          final int len) throws IOException {
  -        for (int i = 0; i < len; i++) {
  -            final int ch = read();
  -            if (ch == -1) {
  -                if (i == 0) {
  -                    return -1;
  -                } else {
  -                    return i;
  -                }
  -            }
  -            cbuf[off + i] = (char) ch;
  -        }
  -        return len;
  -    }
  -
  -    public final long skip(long n) throws IOException {
  -        for (long i = 0; i < n; i++) {
  -            if (in.read() == -1) {
  -                return i;
  -            }
  -        }
  -        return n;
  -    }
  -
  +    /**
  +     * Set number of lines to be returned.
  +     */
       public final void setLines(final long lines) {
           this.lines = lines;
       }
   
  +    /**
  +     * Get number of lines to be returned.
  +     */
       private final long getLines() {
           return lines;
       }
   
  +    /**
  +     * Set the initialized status.
  +     */
       private final void setInitialized(final boolean initialized) {
           this.initialized = initialized;
       }
   
  +    /**
  +     * Get the initialized status.
  +     */
       private final boolean getInitialized() {
           return initialized;
       }
   
  +    /**
  +     * Create a new HeadFilter using the passed in
  +     * Reader for instantiation.
  +     */
       public final Reader chain(final Reader rdr) {
           HeadFilter newFilter = new HeadFilter(rdr);
           newFilter.setLines(getLines());
  @@ -207,6 +199,9 @@
           setInitialized(false);
       }
   
  +    /**
  +     * Scan for the lines parameter.
  +     */
       private final void initialize() {
           if (parameters != null) {
               for (int i = 0; i < parameters.length; i++) {
  
  
  
  1.6       +44 -33    jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/LineContains.java
  
  Index: LineContains.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/LineContains.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- LineContains.java	28 Feb 2002 00:44:00 -0000	1.5
  +++ LineContains.java	28 Feb 2002 01:48:49 -0000	1.6
  @@ -53,10 +53,8 @@
    */
   package org.apache.tools.ant.filters;
   
  -import java.io.FilterReader;
   import java.io.IOException;
   import java.io.Reader;
  -import java.io.StringReader;
   import java.util.Vector;
   
   import org.apache.tools.ant.types.Parameter;
  @@ -86,17 +84,22 @@
    * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
    */
   public final class LineContains
  -    extends FilterReader
  +    extends BaseFilterReader
       implements Parameterizable, ChainableReader
   {
  +    /** contains key */
       private static final String CONTAINS_KEY = "contains";
   
  +    /** The passed in parameter array. */
       private Parameter[] parameters;
   
  +    /** Have the parameters passed been interpreted? */
       private boolean initialized = false;
   
  +    /** Vector that holds the strings that input lines must contain. */
       private Vector contains = new Vector();
   
  +    /** Currently read in line. */
       private String line = null;
   
       /**
  @@ -106,13 +109,7 @@
        * that is created making it useless for further operations.
        */
       public LineContains() {
  -        // Dummy constructor to be invoked by Ant's Introspector
  -        super(new StringReader(new String()));
  -        try {
  -            close();
  -        } catch (IOException  ioe) {
  -            // Ignore
  -        }
  +        super();
       }
   
       /**
  @@ -124,6 +121,10 @@
           super(in);
       }
   
  +    /**
  +     * Choose only those lines that contains
  +     * user defined values.
  +     */
       public final int read() throws IOException {
           if (!initialized) {
               initialize();
  @@ -169,49 +170,45 @@
           return ch;
       }
   
  -    public final int read(final char cbuf[], final int off,
  -                          final int len) throws IOException {
  -        for (int i = 0; i < len; i++) {
  -            final int ch = read();
  -            if (ch == -1) {
  -                if (i == 0) {
  -                    return -1;
  -                } else {
  -                    return i;
  -                }
  -            }
  -            cbuf[off + i] = (char) ch;
  -        }
  -        return len;
  -    }
  -
  -    public final long skip(final long n) throws IOException {
  -        for (long i = 0; i < n; i++) {
  -            if (in.read() == -1) return i;
  -        }
  -        return n;
  -    }
  -
  +    /**
  +     * Add a contains element.
  +     */
       public final void addConfiguredContains(final Contains contains) {
           this.contains.addElement(contains.getValue());
       }
   
  +    /**
  +     * Set contains vector.
  +     */
       private void setContains(final Vector contains) {
           this.contains = contains;
       }
   
  +    /**
  +     * Get contains vector.
  +     */
       private final Vector getContains() {
           return contains;
       }
   
  +    /**
  +     * Set the initialized status.
  +     */
       private final void setInitialized(final boolean initialized) {
           this.initialized = initialized;
       }
   
  +    /**
  +     * Get the initialized status.
  +     */
       private final boolean getInitialized() {
           return initialized;
       }
   
  +    /**
  +     * Create a new LineContains using the passed in
  +     * Reader for instantiation.
  +     */
       public final Reader chain(final Reader rdr) {
           LineContains newFilter = new LineContains(rdr);
           newFilter.setContains(getContains());
  @@ -227,6 +224,9 @@
           initialized = false;
       }
   
  +    /**
  +     * Parse params to add user defined contains strings.
  +     */
       private final void initialize() {
           if (parameters != null) {
               for (int i = 0; i < parameters.length; i++) {
  @@ -237,13 +237,24 @@
           }
       }
   
  +    /**
  +     * Holds a contains element
  +     */
       public static class Contains {
  +
  +        /** User defined contains string */
           private String value;
   
  +        /**
  +         * Set the contains string
  +         */
           public final void setValue(String contains) {
               value = contains;
           }
   
  +        /**
  +         * Get the contains string
  +         */
           public final String getValue() {
               return value;
           }
  
  
  
  1.6       +29 -38    jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/PrefixLines.java
  
  Index: PrefixLines.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/PrefixLines.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PrefixLines.java	28 Feb 2002 00:44:00 -0000	1.5
  +++ PrefixLines.java	28 Feb 2002 01:48:49 -0000	1.6
  @@ -53,10 +53,8 @@
    */
   package org.apache.tools.ant.filters;
   
  -import java.io.FilterReader;
   import java.io.IOException;
   import java.io.Reader;
  -import java.io.StringReader;
   
   import org.apache.tools.ant.types.Parameter;
   import org.apache.tools.ant.types.Parameterizable;
  @@ -78,20 +76,22 @@
    * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
    */
   public final class PrefixLines
  -    extends FilterReader
  +    extends BaseFilterReader
       implements Parameterizable, ChainableReader
   {
  -    /**
  -     * prefix key
  -     */
  +    /** prefix key */
       private static final String PREFIX_KEY = "prefix";
   
  +    /** The passed in parameter array. */
       private Parameter[] parameters;
   
  +    /** Have the parameters passed been interpreted? */
       private boolean initialized = false;
   
  +    /** The prefix to be used. */
       private String prefix = null;
   
  +    /** Data that must be read from, if not null. */
       private String queuedData = null;
   
       /**
  @@ -101,13 +101,7 @@
        * that is created making it useless for further operations.
        */
       public PrefixLines() {
  -        // Dummy constructor to be invoked by Ant's Introspector
  -        super(new StringReader(new String()));
  -        try {
  -            close();
  -        } catch (IOException  ioe) {
  -            // Ignore
  -        }
  +        super();
       }
   
       /**
  @@ -119,6 +113,9 @@
           super(in);
       }
   
  +    /**
  +     * Prefix lines with user defined prefix.
  +     */
       public final int read() throws IOException {
           if (!getInitialized()) {
               initialize();
  @@ -160,47 +157,38 @@
           return ch;
       }
   
  -    public final int read(final char cbuf[], final int off,
  -                          final int len) throws IOException {
  -        for (int i = 0; i < len; i++) {
  -            final int ch = read();
  -            if (ch == -1) {
  -                if (i == 0) {
  -                    return -1;
  -                } else {
  -                    return i;
  -                }
  -            }
  -            cbuf[off + i] = (char) ch;
  -        }
  -        return len;
  -    }
  -
  -    public final long skip(long n) throws IOException {
  -        for (long i = 0; i < n; i++) {
  -            if (in.read() == -1) {
  -                return i;
  -            }
  -        }
  -        return n;
  -    }
  -
  +    /**
  +     * Set the prefix
  +     */
       public final void setPrefix(final String prefix) {
           this.prefix = prefix;
       }
   
  +    /**
  +     * Get the prefix
  +     */
       private final String getPrefix() {
           return prefix;
       }
   
  +    /**
  +     * Set the initialized status.
  +     */
       private final void setInitialized(final boolean initialized) {
           this.initialized = initialized;
       }
   
  +    /**
  +     * Get the initialized status.
  +     */
       private final boolean getInitialized() {
           return initialized;
       }
   
  +    /**
  +     * Create a new PrefixLines using the passed in
  +     * Reader for instantiation.
  +     */
       public final Reader chain(final Reader rdr) {
           PrefixLines newFilter = new PrefixLines(rdr);
           newFilter.setPrefix(getPrefix());
  @@ -216,6 +204,9 @@
           setInitialized(false);
       }
   
  +    /**
  +     * Initialize prefix if available from the param element.
  +     */
       private final void initialize() {
           if (parameters != null) {
               for (int i = 0; i < parameters.length; i++) {
  
  
  
  1.7       +59 -35    jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/ReplaceTokens.java
  
  Index: ReplaceTokens.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/ReplaceTokens.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ReplaceTokens.java	27 Feb 2002 20:48:44 -0000	1.6
  +++ ReplaceTokens.java	28 Feb 2002 01:48:49 -0000	1.7
  @@ -53,10 +53,8 @@
    */
   package org.apache.tools.ant.filters;
   
  -import java.io.FilterReader;
   import java.io.IOException;
   import java.io.Reader;
  -import java.io.StringReader;
   import java.util.Hashtable;
   
   import org.apache.tools.ant.types.Parameter;
  @@ -83,23 +81,31 @@
    * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
    */
   public final class ReplaceTokens
  -    extends FilterReader
  +    extends BaseFilterReader
       implements Parameterizable, ChainableReader
   {
  +    /** Default begin token character. */
       private static final char DEFAULT_BEGIN_TOKEN = '@';
   
  +    /** Default end token character. */
       private static final char DEFAULT_END_TOKEN = '@';
   
  +    /** Data that must be read from, if not null. */
       private String queuedData = null;
   
  +    /** The passed in parameter array. */
       private Parameter[] parameters;
   
  +    /** Hashtable to hold the replacee-replacer pairs. */
       private Hashtable hash = new Hashtable();
   
  +    /** Have the parameters passed been interpreted? */
       private boolean initialized;
   
  +    /** Begin token. */
       private char beginToken = DEFAULT_BEGIN_TOKEN;
   
  +    /** End token. */
       private char endToken = DEFAULT_END_TOKEN;
   
       /**
  @@ -109,13 +115,7 @@
        * that is created making it useless for further operations.
        */
       public ReplaceTokens() {
  -        // Dummy constructor to be invoked by Ant's Introspector
  -        super(new StringReader(new String()));
  -        try {
  -            close();
  -        } catch (IOException  ioe) {
  -            // Ignore
  -        }
  +        super();
       }
   
       /**
  @@ -176,67 +176,73 @@
           return ch;
       }
   
  -    public final int read(final char cbuf[], final int off,
  -                          final int len) throws IOException {
  -        for (int i = 0; i < len; i++) {
  -            final int ch = read();
  -            if (ch == -1) {
  -                if (i == 0) {
  -                    return -1;
  -                } else {
  -                    return i;
  -                }
  -            }
  -            cbuf[off + i] = (char) ch;
  -        }
  -        return len;
  -    }
  -
  -    public final long skip(long n) throws IOException {
  -        for (long i = 0; i < n; i++) {
  -            if (in.read() == -1) {
  -                return i;
  -            }
  -        }
  -        return n;
  -    }
  -
  +    /**
  +     * Set begin token.
  +     */
       public final void setBeginToken(final char beginToken) {
           this.beginToken = beginToken;
       }
   
  +    /**
  +     * Get begin token.
  +     */
       private final char getBeginToken() {
           return beginToken;
       }
   
  +    /**
  +     * Set end token.
  +     */
       public final void setEndToken(final char endToken) {
           this.endToken = endToken;
       }
   
  +    /**
  +     * Get begin token.
  +     */
       private final char getEndToken() {
           return endToken;
       }
   
  +    /**
  +     * Add a token element.
  +     */
       public final void addConfiguredToken(final Token token) {
           hash.put(token.getKey(), token.getValue());
       }
   
  +    /**
  +     * Set the tokens.
  +     */
       private void setTokens(final Hashtable hash) {
           this.hash = hash;
       }
   
  +    /**
  +     * Get the tokens.
  +     */
       private final Hashtable getTokens() {
           return hash;
       }
   
  +    /**
  +     * Set the initialized status.
  +     */
       private final void setInitialized(final boolean initialized) {
           this.initialized = initialized;
       }
   
  +    /**
  +     * Get the initialized status.
  +     */
       private final boolean getInitialized() {
           return initialized;
       }
   
  +    /**
  +     * Create a new ReplaceTokens using the passed in
  +     * Reader for instantiation.
  +     */
       public final Reader chain(final Reader rdr) {
           ReplaceTokens newFilter = new ReplaceTokens(rdr);
           newFilter.setBeginToken(getBeginToken());
  @@ -279,23 +285,41 @@
           }
       }
   
  +    /**
  +     * Holds a token
  +     */
       public static class Token {
  +
  +        /** token key */
           private String key;
   
  +        /** token value */
           private String value;
   
  +        /**
  +         * Set the token key
  +         */
           public final void setKey(String key) {
               this.key = key;
           }
   
  +        /**
  +         * Set the token value
  +         */
           public final void setValue(String value) {
               this.value = value;
           }
   
  +        /**
  +         * Get the token key
  +         */
           public final String getKey() {
               return key;
           }
   
  +        /**
  +         * Get the token value
  +         */
           public final String getValue() {
               return value;
           }
  
  
  
  1.5       +9 -33     jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/StripJavaComments.java
  
  Index: StripJavaComments.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/StripJavaComments.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- StripJavaComments.java	27 Feb 2002 20:48:44 -0000	1.4
  +++ StripJavaComments.java	28 Feb 2002 01:48:49 -0000	1.5
  @@ -53,10 +53,8 @@
    */
   package org.apache.tools.ant.filters;
   
  -import java.io.FilterReader;
   import java.io.IOException;
   import java.io.Reader;
  -import java.io.StringReader;
   
   /**
    * This is a java comment and string stripper reader that filters
  @@ -66,7 +64,7 @@
    * you are reccomended to make it work on top of a buffered reader.
    */
   public final class StripJavaComments
  -    extends FilterReader
  +    extends BaseFilterReader
       implements ChainableReader
   {
       /**
  @@ -76,13 +74,7 @@
        * that is created making it useless for further operations.
        */
       public StripJavaComments() {
  -        // Dummy constructor to be invoked by Ant's Introspector
  -        super(new StringReader(new String()));
  -        try {
  -            close();
  -        } catch (IOException  ioe) {
  -            // Ignore
  -        }
  +        super();
       }
   
       /**
  @@ -94,6 +86,9 @@
           super(in);
       }
   
  +    /**
  +     * Filter out Java Style comments
  +     */
       public final int read() throws IOException {
           int ch = in.read();
           if (ch == '/') {
  @@ -144,29 +139,10 @@
           return ch;
       }
   
  -    public final int read(final char cbuf[], final int off,
  -                          final int len) throws IOException {
  -        for (int i = 0; i < len; i++) {
  -            final int ch = read();
  -            if (ch == -1) {
  -                if (i == 0) {
  -                    return -1;
  -                } else {
  -                    return i;
  -                }
  -            }
  -            cbuf[off + i] = (char) ch;
  -        }
  -        return len;
  -    }
  -
  -    public final long skip(final long n) throws IOException {
  -        for (long i = 0; i < n; i++) {
  -            if (in.read() == -1) return i;
  -        }
  -        return n;
  -    }
  -
  +    /**
  +     * Create a new StripJavaComments object using the passed in
  +     * Reader for instantiation.
  +     */
       public final Reader chain(final Reader rdr) {
           StripJavaComments newFilter = new StripJavaComments(rdr);
           return newFilter;
  
  
  
  1.8       +29 -35    jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/StripLineBreaks.java
  
  Index: StripLineBreaks.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/StripLineBreaks.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- StripLineBreaks.java	27 Feb 2002 20:48:44 -0000	1.7
  +++ StripLineBreaks.java	28 Feb 2002 01:48:49 -0000	1.8
  @@ -53,10 +53,8 @@
    */
   package org.apache.tools.ant.filters;
   
  -import java.io.FilterReader;
   import java.io.IOException;
   import java.io.Reader;
  -import java.io.StringReader;
   
   import org.apache.tools.ant.types.Parameter;
   import org.apache.tools.ant.types.Parameterizable;
  @@ -74,7 +72,7 @@
    * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
    */
   public final class StripLineBreaks
  -    extends FilterReader
  +    extends BaseFilterReader
       implements Parameterizable, ChainableReader
   {
       /**
  @@ -88,10 +86,13 @@
        */
       private static final String LINE_BREAKS_KEY = "linebreaks";
   
  +    /** The passed in parameter array. */
       private Parameter[] parameters;
   
  +    /** Holds the characters that are recognized as line breaks. */
       private String lineBreaks = DEFAULT_LINE_BREAKS;
   
  +    /** Have the parameters passed been interpreted? */
       private boolean initialized = false;
   
       /**
  @@ -101,13 +102,7 @@
        * that is created making it useless for further operations.
        */
       public StripLineBreaks() {
  -        // Dummy constructor to be invoked by Ant's Introspector
  -        super(new StringReader(new String()));
  -        try {
  -            close();
  -        } catch (IOException  ioe) {
  -            // Ignore
  -        }
  +        super();
       }
   
       /**
  @@ -119,6 +114,11 @@
           super(in);
       }
   
  +    /**
  +     * If the character that is being read in is a
  +     * line break character, ignore it and move on to the
  +     * next one.
  +     */
       public final int read() throws IOException {
           if (!initialized) {
               initialize();
  @@ -136,47 +136,38 @@
           return ch;
       }
   
  -    public final int read(final char cbuf[], final int off,
  -                          final int len) throws IOException {
  -        for (int i = 0; i < len; i++) {
  -            final int ch = read();
  -            if (ch == -1) {
  -                if (i == 0) {
  -                    return -1;
  -                } else {
  -                    return i;
  -                }
  -            }
  -            cbuf[off + i] = (char) ch;
  -        }
  -        return len;
  -    }
  -
  -    public final long skip(long n) throws IOException {
  -        for (long i = 0; i < n; i++) {
  -            if (in.read() == -1) {
  -                return i;
  -            }
  -        }
  -        return n;
  -    }
  -
  +    /**
  +     * Set the line break characters.
  +     */
       public final void setLineBreaks(final String lineBreaks) {
           this.lineBreaks = lineBreaks;
       }
   
  +    /**
  +     * Get the line breaks characters
  +     */
       private final String getLineBreaks() {
           return lineBreaks;
       }
   
  +    /**
  +     * Set the initialized status.
  +     */
       private final void setInitialized(final boolean initialized) {
           this.initialized = initialized;
       }
   
  +    /**
  +     * Get the initialized status.
  +     */
       private final boolean getInitialized() {
           return initialized;
       }
   
  +    /**
  +     * Create a new StripLineBreaks object using the passed in
  +     * Reader for instantiation.
  +     */
       public final Reader chain(final Reader rdr) {
           StripLineBreaks newFilter = new StripLineBreaks(rdr);
           newFilter.setLineBreaks(getLineBreaks());
  @@ -192,6 +183,9 @@
           setInitialized(false);
       }
   
  +    /**
  +     * Line break characters set using the param element.
  +     */
       private final void initialize() {
           String userDefinedLineBreaks = null;
           if (parameters != null) {
  
  
  
  1.7       +44 -33    jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/StripLineComments.java
  
  Index: StripLineComments.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/StripLineComments.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- StripLineComments.java	27 Feb 2002 20:59:46 -0000	1.6
  +++ StripLineComments.java	28 Feb 2002 01:48:49 -0000	1.7
  @@ -53,10 +53,8 @@
    */
   package org.apache.tools.ant.filters;
   
  -import java.io.FilterReader;
   import java.io.IOException;
   import java.io.Reader;
  -import java.io.StringReader;
   import java.util.Vector;
   
   import org.apache.tools.ant.types.Parameter;
  @@ -89,17 +87,22 @@
    * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
    */
   public final class StripLineComments
  -    extends FilterReader
  +    extends BaseFilterReader
       implements Parameterizable, ChainableReader
   {
  +    /** The type that param recognizes to set the comments. */
       private static final String COMMENTS_KEY = "comment";
   
  +    /** The passed in parameter array. */
       private Parameter[] parameters;
   
  +    /** Have the parameters passed been interpreted? */
       private boolean initialized = false;
   
  +    /** Vector that holds comments. */
       private Vector comments = new Vector();
   
  +    /** The line that has been read ahead. */
       private String line = null;
   
       /**
  @@ -109,13 +112,7 @@
        * that is created making it useless for further operations.
        */
       public StripLineComments() {
  -        // Dummy constructor to be invoked by Ant's Introspector
  -        super(new StringReader(new String()));
  -        try {
  -            close();
  -        } catch (IOException  ioe) {
  -            // Ignore
  -        }
  +        super();
       }
   
       /**
  @@ -127,6 +124,10 @@
           super(in);
       }
   
  +    /**
  +     * Read in line by line; Ignore line if it
  +     * begins with a comment string.
  +     */
       public final int read() throws IOException {
           if (!getInitialized()) {
               initialize();
  @@ -171,49 +172,45 @@
           return ch;
       }
   
  -    public final int read(final char cbuf[], final int off,
  -                          final int len) throws IOException {
  -        for (int i = 0; i < len; i++) {
  -            final int ch = read();
  -            if (ch == -1) {
  -                if (i == 0) {
  -                    return -1;
  -                } else {
  -                    return i;
  -                }
  -            }
  -            cbuf[off + i] = (char) ch;
  -        }
  -        return len;
  -    }
  -
  -    public final long skip(final long n) throws IOException {
  -        for (long i = 0; i < n; i++) {
  -            if (in.read() == -1) return i;
  -        }
  -        return n;
  -    }
  -
  +    /**
  +     * Add the Comment element.
  +     */
       public final void addConfiguredComment(final Comment comment) {
           comments.addElement(comment.getValue());
       }
   
  +    /**
  +     * Set the comments vector.
  +     */
       private void setComments(final Vector comments) {
           this.comments = comments;
       }
   
  +    /**
  +     * Get the comments vector.
  +     */
       private final Vector getComments() {
           return comments;
       }
   
  +    /**
  +     * Set the initialized status.
  +     */
       private final void setInitialized(final boolean initialized) {
           this.initialized = initialized;
       }
   
  +    /**
  +     * Get the initialized status.
  +     */
       private final boolean getInitialized() {
           return initialized;
       }
   
  +    /**
  +     * Create a new StripLineComments object using the passed in
  +     * Reader for instantiation.
  +     */
       public final Reader chain(final Reader rdr) {
           StripLineComments newFilter = new StripLineComments(rdr);
           newFilter.setComments(getComments());
  @@ -229,6 +226,9 @@
           setInitialized(false);
       }
   
  +    /**
  +     * Comments set using the param element.
  +     */
       private final void initialize() {
           if (parameters != null) {
               for (int i = 0; i < parameters.length; i++) {
  @@ -239,13 +239,24 @@
           }
       }
   
  +    /**
  +     * The class that holds a comment.
  +     */
       public static class Comment {
  +
  +        /** The comment*/
           private String value;
   
  +        /**
  +         * Set the comment.
  +         */
           public final void setValue(String comment) {
               value = comment;
           }
   
  +        /**
  +         * Get the comment.
  +         */
           public final String getValue() {
               return value;
           }
  
  
  
  1.5       +24 -35    jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/TabsToSpaces.java
  
  Index: TabsToSpaces.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/TabsToSpaces.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TabsToSpaces.java	27 Feb 2002 20:48:44 -0000	1.4
  +++ TabsToSpaces.java	28 Feb 2002 01:48:49 -0000	1.5
  @@ -53,10 +53,8 @@
    */
   package org.apache.tools.ant.filters;
   
  -import java.io.FilterReader;
   import java.io.IOException;
   import java.io.Reader;
  -import java.io.StringReader;
   
   import org.apache.tools.ant.types.Parameter;
   import org.apache.tools.ant.types.Parameterizable;
  @@ -78,19 +76,25 @@
    * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
    */
   public final class TabsToSpaces
  -    extends FilterReader
  +    extends BaseFilterReader
       implements Parameterizable, ChainableReader
   {
  +    /** The default tab length is 8 */
       private static final int DEFAULT_TAB_LENGTH = 8;
   
  +    /** The name that param recognizes to set the tablength. */
       private static final String TAB_LENGTH_KEY = "tablength";
   
  +    /** The passed in parameter array. */
       private Parameter[] parameters;
   
  +    /** Have the parameters passed been interpreted? */
       private boolean initialized;
   
  +    /** Default tab length. */
       private int tabLength = DEFAULT_TAB_LENGTH;
   
  +    /** How many more spaces must be returned to replace a tab? */
       private int spacesRemaining = 0;
   
       /**
  @@ -100,13 +104,7 @@
        * that is created making it useless for further operations.
        */
       public TabsToSpaces() {
  -        // Dummy constructor to be invoked by Ant's Introspector
  -        super(new StringReader(new String()));
  -        try {
  -            close();
  -        } catch (IOException  ioe) {
  -            // Ignore
  -        }
  +        super();
       }
   
       /**
  @@ -142,47 +140,38 @@
           return ch;
       }
   
  -    public final int read(final char cbuf[], final int off,
  -                          final int len) throws IOException {
  -        for (int i = 0; i < len; i++) {
  -            final int ch = read();
  -            if (ch == -1) {
  -                if (i == 0) {
  -                    return -1;
  -                } else {
  -                    return i;
  -                }
  -            }
  -            cbuf[off + i] = (char) ch;
  -        }
  -        return len;
  -    }
  -
  -    public final long skip(long n) throws IOException {
  -        for (long i = 0; i < n; i++) {
  -            if (in.read() == -1) {
  -                return i;
  -            }
  -        }
  -        return n;
  -    }
  -
  +    /**
  +     * Set the tab length.
  +     */
       public final void setTablength(final int tabLength) {
           this.tabLength = tabLength;
       }
   
  +    /**
  +     * Get the tab length
  +     */
       private final int getTablength() {
           return tabLength;
       }
   
  +    /**
  +     * Set the initialized status.
  +     */
       private final void setInitialized(final boolean initialized) {
           this.initialized = initialized;
       }
   
  +    /**
  +     * Get the initialized status.
  +     */
       private final boolean getInitialized() {
           return initialized;
       }
   
  +    /**
  +     * Create a new TabsToSpaces object using the passed in
  +     * Reader for instantiation.
  +     */
       public final Reader chain(final Reader rdr) {
           TabsToSpaces newFilter = new TabsToSpaces(rdr);
           newFilter.setTablength(getTablength());
  
  
  
  1.6       +31 -35    jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/TailFilter.java
  
  Index: TailFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/TailFilter.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TailFilter.java	27 Feb 2002 20:48:44 -0000	1.5
  +++ TailFilter.java	28 Feb 2002 01:48:49 -0000	1.6
  @@ -53,10 +53,8 @@
    */
   package org.apache.tools.ant.filters;
   
  -import java.io.FilterReader;
   import java.io.IOException;
   import java.io.Reader;
  -import java.io.StringReader;
   
   import org.apache.tools.ant.types.Parameter;
   import org.apache.tools.ant.types.Parameterizable;
  @@ -78,27 +76,37 @@
    * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
    */
   public final class TailFilter
  -    extends FilterReader
  +    extends BaseFilterReader
       implements Parameterizable, ChainableReader
   {
  +    /** The name that param recognizes to set the number of lines. */
       private static final String LINES_KEY = "lines";
   
  +    /** The passed in parameter array. */
       private Parameter[] parameters;
   
  +    /** Have the parameters passed been interpreted? */
       private boolean initialized = false;
   
  +    /** Number of lines currently read in. */
       private long linesRead = 0;
   
  +    /** Default number of lines returned. */
       private long lines = 10;
   
  +    /** If the next character being read is a linefeed, must it be ignored? */
       private boolean ignoreLineFeed = false;
   
  +    /** Buffer to hold in characters read ahead. */
       private char[] buffer = new char[4096];
   
  +    /** The character position that has been returned from the buffer. */
       private int returnedCharPos = -1;
   
  +    /** Has read ahead been completed? */
       private boolean completedReadAhead = false;
   
  +    /** Current index position on the buffer. */
       private int bufferPos = 0;
   
       /**
  @@ -108,13 +116,7 @@
        * that is created making it useless for further operations.
        */
       public TailFilter() {
  -        // Dummy constructor to be invoked by Ant's Introspector
  -        super(new StringReader(new String()));
  -        try {
  -            close();
  -        } catch (IOException  ioe) {
  -            // Ignore
  -        }
  +        super();
       }
   
       /**
  @@ -196,47 +198,38 @@
           }
       }
   
  -    public final int read(final char cbuf[], final int off,
  -                          final int len) throws IOException {
  -        for (int i = 0; i < len; i++) {
  -            final int ch = read();
  -            if (ch == -1) {
  -                if (i == 0) {
  -                    return -1;
  -                } else {
  -                    return i;
  -                }
  -            }
  -            cbuf[off + i] = (char) ch;
  -        }
  -        return len;
  -    }
  -
  -    public final long skip(long n) throws IOException {
  -        for (long i = 0; i < n; i++) {
  -            if (in.read() == -1) {
  -                return i;
  -            }
  -        }
  -        return n;
  -    }
  -
  +    /**
  +     * Set number of lines to be returned.
  +     */
       public final void setLines(final long lines) {
           this.lines = lines;
       }
   
  +    /**
  +     * Get number of lines to be returned.
  +     */
       private final long getLines() {
           return lines;
       }
   
  +    /**
  +     * Set the initialized status.
  +     */
       private final void setInitialized(final boolean initialized) {
           this.initialized = initialized;
       }
   
  +    /**
  +     * Get the initialized status.
  +     */
       private final boolean getInitialized() {
           return initialized;
       }
   
  +    /**
  +     * Create a new TailFilter using the passed in
  +     * Reader for instantiation.
  +     */
       public final Reader chain(final Reader rdr) {
           TailFilter newFilter = new TailFilter(rdr);
           newFilter.setLines(getLines());
  @@ -252,6 +245,9 @@
           setInitialized(false);
       }
   
  +    /**
  +     * Scan for the lines parameter.
  +     */
       private final void initialize() {
           if (parameters != null) {
               for (int i = 0; i < parameters.length; i++) {
  
  
  
  1.1                  jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/BaseFilterReader.java
  
  Index: BaseFilterReader.java
  ===================================================================
  /*
   *  The Apache Software License, Version 1.1
   *
   *  Copyright (c) 2002 The Apache Software Foundation.  All rights
   *  reserved.
   *
   *  Redistribution and use in source and binary forms, with or without
   *  modification, are permitted provided that the following conditions
   *  are met:
   *
   *  1. Redistributions of source code must retain the above copyright
   *  notice, this list of conditions and the following disclaimer.
   *
   *  2. Redistributions in binary form must reproduce the above copyright
   *  notice, this list of conditions and the following disclaimer in
   *  the documentation and/or other materials provided with the
   *  distribution.
   *
   *  3. The end-user documentation included with the redistribution, if
   *  any, must include the following acknowlegement:
   *  "This product includes software developed by the
   *  Apache Software Foundation (http://www.apache.org/)."
   *  Alternately, this acknowlegement may appear in the software itself,
   *  if and wherever such third-party acknowlegements normally appear.
   *
   *  4. The names "The Jakarta Project", "Ant", and "Apache Software
   *  Foundation" must not be used to endorse or promote products derived
   *  from this software without prior written permission. For written
   *  permission, please contact apache@apache.org.
   *
   *  5. Products derived from this software may not be called "Apache"
   *  nor may "Apache" appear in their names without prior written
   *  permission of the Apache Group.
   *
   *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   *  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   *  DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   *  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   *  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   *  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   *  SUCH DAMAGE.
   *  ====================================================================
   *
   *  This software consists of voluntary contributions made by many
   *  individuals on behalf of the Apache Software Foundation.  For more
   *  information on the Apache Software Foundation, please see
   *  <http://www.apache.org/>.
   */
  package org.apache.tools.ant.filters;
  
  import java.io.FilterReader;
  import java.io.IOException;
  import java.io.Reader;
  import java.io.StringReader;
  
  /**
   * Base class for core filter readers.
   *
   * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
   */
  public abstract class BaseFilterReader
      extends FilterReader
  {
      /**
       * This constructor is a dummy constructor and is
       * not meant to be used by any class other than Ant's
       * introspection mechanism. This will close the filter
       * that is created making it useless for further operations.
       */
      public BaseFilterReader() {
          // Dummy constructor to be invoked by Ant's Introspector
          super(new StringReader(new String()));
          try {
              close();
          } catch (IOException  ioe) {
              // Ignore
          }
      }
  
      /**
       * Create a new filtered reader.
       *
       * @param in  a Reader object providing the underlying stream.
       */
      public BaseFilterReader(final Reader in) {
          super(in);
      }
  
      /**
       * Read characters into a portion of an array.  This method will block
       * until some input is available, an I/O error occurs, or the end of the
       * stream is reached.
       *
       * @param      cbuf  Destination buffer
       * @param      off   Offset at which to start storing characters
       * @param      len   Maximum number of characters to read
       *
       * @return     The number of characters read, or -1 if the end of the
       *             stream has been reached
       *
       * @exception  IOException  If an I/O error occurs
       */
      public final int read(final char cbuf[], final int off,
                            final int len) throws IOException {
          for (int i = 0; i < len; i++) {
              final int ch = read();
              if (ch == -1) {
                  if (i == 0) {
                      return -1;
                  } else {
                      return i;
                  }
              }
              cbuf[off + i] = (char) ch;
          }
          return len;
      }
  
      /**
       * Skip characters.  This method will block until some characters are
       * available, an I/O error occurs, or the end of the stream is reached.
       *
       * @param  n  The number of characters to skip
       *
       * @return    The number of characters actually skipped
       *
       * @exception  IllegalArgumentException  If <code>n</code> is negative.
       * @exception  IOException  If an I/O error occurs
       */
      public final long skip(long n) throws IOException {
          if (n < 0L) {
              throw new IllegalArgumentException("skip value is negative");
          }
  
          for (long i = 0; i < n; i++) {
              if (in.read() == -1) {
                  return i;
              }
          }
          return n;
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message