Browse Source

1. Remove unused private inner class.

2. Fix loop introduced by a seemingly innocent logic change :(
3. Fix bug that caused extra EOFs when input already contained EOF.
4. Make instances constructed with a Reader usable.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277792 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 20 years ago
parent
commit
ab08e2cd25
1 changed files with 27 additions and 37 deletions
  1. +27
    -37
      src/main/org/apache/tools/ant/filters/FixCrLfFilter.java

+ 27
- 37
src/main/org/apache/tools/ant/filters/FixCrLfFilter.java View File

@@ -79,6 +79,7 @@ public final class FixCrLfFilter
private AddAsisRemove tabs; private AddAsisRemove tabs;
private boolean javafiles = false; private boolean javafiles = false;
private boolean fixlast = true; private boolean fixlast = true;
private boolean initialized = false;


/** /**
* Constructor for "dummy" instances. * Constructor for "dummy" instances.
@@ -263,6 +264,7 @@ public final class FixCrLfFilter
} }
// Add missing EOF character // Add missing EOF character
in = (ctrlz == AddAsisRemove.ADD) ? new AddEofFilter(in) : in; in = (ctrlz == AddAsisRemove.ADD) ? new AddEofFilter(in) : in;
initialized = true;
} }


/** /**
@@ -274,7 +276,10 @@ public final class FixCrLfFilter
* @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 synchronized final int read() throws IOException {
if (!initialized) {
initInternalFilters();
}
return in.read(); return in.read();
} }


@@ -552,16 +557,24 @@ public final class FixCrLfFilter


if (normalizedEOL == 0) { if (normalizedEOL == 0) {
int numEOL = 0; int numEOL = 0;
boolean atEnd = false;
switch (thisChar) { switch (thisChar) {
case CTRLZ: case CTRLZ:
int c = super.read();
if (c == -1) {
atEnd = true;
if (fixLast && !previousWasEOL) {
numEOL = 1;
push(thisChar);
}
} else {
push(c);
}
break;
case -1: case -1:
atEnd = true;
if (fixLast && !previousWasEOL) { if (fixLast && !previousWasEOL) {
numEOL = 1; numEOL = 1;

if (thisChar == CTRLZ) {
push(thisChar);
}
} }
break; break;
case '\n': case '\n':
@@ -595,7 +608,7 @@ public final class FixCrLfFilter
} }
previousWasEOL = true; previousWasEOL = true;
thisChar = read(); thisChar = read();
} else if (thisChar != -1) {
} else if (!atEnd) {
previousWasEOL = false; previousWasEOL = false;
} }
} else { } else {
@@ -605,33 +618,6 @@ public final class FixCrLfFilter
} }
} }


private static class FixLastFilter extends SimpleFilterReader {
int lastChar = -1;
char[] eol = null;

public FixLastFilter(Reader in, String eolString) {
super(in);
eol = eolString.toCharArray();
}

public int read() throws IOException {
int thisChar = super.read();
// if source is EOF but last character was NOT eol, return eol
if (thisChar == -1) {
switch (lastChar) {
case '\r':
case '\n':
// Return first character of EOL
thisChar = eol[0];
// Push remaining characters onto input stream
push(eol, 1, eol.length - 1);
}
}
lastChar = thisChar;
return thisChar;
}
}

private static class AddEofFilter extends SimpleFilterReader { private static class AddEofFilter extends SimpleFilterReader {
int lastChar = -1; int lastChar = -1;


@@ -643,10 +629,14 @@ public final class FixCrLfFilter
int thisChar = super.read(); int thisChar = super.read();


// if source is EOF but last character was NOT ctrl-z, return ctrl-z // if source is EOF but last character was NOT ctrl-z, return ctrl-z
if (thisChar == -1 && lastChar != CTRLZ) {
thisChar = CTRLZ;
if (thisChar == -1) {
if (lastChar != CTRLZ) {
lastChar = CTRLZ;
return lastChar;
}
} else {
lastChar = thisChar;
} }
lastChar = thisChar;
return thisChar; return thisChar;
} }
} }


Loading…
Cancel
Save