Browse Source

Replace algorithm with a less recursive one - avoid StackOverflow on

large files.

PR: 15528


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274120 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
c5e6e4bd95
3 changed files with 34 additions and 17 deletions
  1. +3
    -3
      src/main/org/apache/tools/ant/filters/LineContains.java
  2. +17
    -9
      src/main/org/apache/tools/ant/filters/LineContainsRegExp.java
  3. +14
    -5
      src/main/org/apache/tools/ant/filters/StripLineComments.java

+ 3
- 3
src/main/org/apache/tools/ant/filters/LineContains.java View File

@@ -71,9 +71,9 @@ import org.apache.tools.ant.types.Parameter;
* *
* Or: * Or:
* *
* <pre>&lt;filterreader classname="org.apache.tools.ant.filters.LineContains"&gt; * <pre>&lt;filterreader classname=&quot;org.apache.tools.ant.filters.LineContains&quot;&gt;
* &lt;param type="contains" value="foo"/&gt; * &lt;param type=&quot;contains&quot; value=&quot;foo&quot;/&gt;
* &lt;param type="contains" value="bar"/&gt; * &lt;param type=&quot;contains&quot; value=&quot;bar&quot;/&gt;
* &lt;/filterreader&gt;</pre> * &lt;/filterreader&gt;</pre>
* *
* This will include only those lines that contain <code>foo</code> and * This will include only those lines that contain <code>foo</code> and


+ 17
- 9
src/main/org/apache/tools/ant/filters/LineContainsRegExp.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2002 The Apache Software Foundation. All rights * Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -88,7 +88,7 @@ public final class LineContainsRegExp
/** Vector that holds the expressions that input lines must contain. */ /** Vector that holds the expressions that input lines must contain. */
private Vector regexps = new Vector(); private Vector regexps = new Vector();


/** /**
* Remaining line to be read from this filter, or <code>null</code> if * Remaining line to be read from this filter, or <code>null</code> if
* the next call to <code>read()</code> should read the original stream * the next call to <code>read()</code> should read the original stream
* to find the next matching line. * to find the next matching line.
@@ -97,7 +97,7 @@ public final class LineContainsRegExp


/** /**
* Constructor for "dummy" instances. * Constructor for "dummy" instances.
* *
* @see BaseFilterReader#BaseFilterReader() * @see BaseFilterReader#BaseFilterReader()
*/ */
public LineContainsRegExp() { public LineContainsRegExp() {
@@ -121,9 +121,9 @@ public final class LineContainsRegExp
* *
* @return the next character in the resulting stream, or -1 * @return the next character in the resulting stream, or -1
* if the end of the resulting stream has been reached * if the end of the resulting stream has been reached
* *
* @exception IOException if the underlying stream throws an IOException * @exception IOException if the underlying stream throws an IOException
* during reading * during reading
*/ */
public final int read() throws IOException { public final int read() throws IOException {
if (!getInitialized()) { if (!getInitialized()) {
@@ -142,10 +142,9 @@ public final class LineContainsRegExp
} }
} else { } else {
line = readLine(); line = readLine();
if (line == null) { final int regexpsSize = regexps.size();
ch = -1; while (line != null) {
} else {
final int regexpsSize = regexps.size();
for (int i = 0; i < regexpsSize; i++) { for (int i = 0; i < regexpsSize; i++) {
RegularExpression regexp = (RegularExpression) RegularExpression regexp = (RegularExpression)
regexps.elementAt(i); regexps.elementAt(i);
@@ -157,6 +156,15 @@ public final class LineContainsRegExp
} }
} }


if (line == null) {
// line didn't match
line = readLine();
} else {
break;
}
}

if (line != null) {
return read(); return read();
} }
} }


+ 14
- 5
src/main/org/apache/tools/ant/filters/StripLineComments.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2002 The Apache Software Foundation. All rights * Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -142,10 +142,9 @@ public final class StripLineComments
} }
} else { } else {
line = readLine(); line = readLine();
if (line == null) { final int commentsSize = comments.size();
ch = -1; while (line != null) {
} else {
int commentsSize = comments.size();
for (int i = 0; i < commentsSize; i++) { for (int i = 0; i < commentsSize; i++) {
String comment = (String) comments.elementAt(i); String comment = (String) comments.elementAt(i);
if (line.startsWith(comment)) { if (line.startsWith(comment)) {
@@ -153,6 +152,16 @@ public final class StripLineComments
break; break;
} }
} }

if (line == null) {
// line started with comment
line = readLine();
} else {
break;
}
}

if (line != null) {
return read(); return read();
} }
} }


||||||
x
 
000:0
Loading…
Cancel
Save