From ab08e2cd2569fe20d71c5b268b5f0994161b8187 Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Fri, 4 Mar 2005 22:29:32 +0000 Subject: [PATCH] 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 --- .../tools/ant/filters/FixCrLfFilter.java | 64 ++++++++----------- 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/src/main/org/apache/tools/ant/filters/FixCrLfFilter.java b/src/main/org/apache/tools/ant/filters/FixCrLfFilter.java index 52766db09..95da2a13e 100755 --- a/src/main/org/apache/tools/ant/filters/FixCrLfFilter.java +++ b/src/main/org/apache/tools/ant/filters/FixCrLfFilter.java @@ -79,6 +79,7 @@ public final class FixCrLfFilter private AddAsisRemove tabs; private boolean javafiles = false; private boolean fixlast = true; + private boolean initialized = false; /** * Constructor for "dummy" instances. @@ -263,6 +264,7 @@ public final class FixCrLfFilter } // Add missing EOF character 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 * during reading. */ - public final int read() throws IOException { + public synchronized final int read() throws IOException { + if (!initialized) { + initInternalFilters(); + } return in.read(); } @@ -552,16 +557,24 @@ public final class FixCrLfFilter if (normalizedEOL == 0) { int numEOL = 0; - + boolean atEnd = false; switch (thisChar) { case CTRLZ: + int c = super.read(); + if (c == -1) { + atEnd = true; + if (fixLast && !previousWasEOL) { + numEOL = 1; + push(thisChar); + } + } else { + push(c); + } + break; case -1: + atEnd = true; if (fixLast && !previousWasEOL) { numEOL = 1; - - if (thisChar == CTRLZ) { - push(thisChar); - } } break; case '\n': @@ -595,7 +608,7 @@ public final class FixCrLfFilter } previousWasEOL = true; thisChar = read(); - } else if (thisChar != -1) { + } else if (!atEnd) { previousWasEOL = false; } } 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 { int lastChar = -1; @@ -643,10 +629,14 @@ public final class FixCrLfFilter int thisChar = super.read(); // 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; } }