You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Eric Fesler <er...@hubmethods.com> on 2002/11/28 14:47:37 UTC

extra CRLF when copying file with filtering

Hi,

Using ant 1.5, I just discover that ant is systematically adding an
extra CRLF at the end of the file when I used that copy task with
filtering set to true.

I've looked in the source and indeed, when the filters are applied, ant
is adding a new line at the end of each line.

In my case, this is an issue because the copied file is used as a
template for an email subject. The extra CRLF makes that the email
message header has an extra blank line and therefore is nomore compliant
with the email RFC.

Does anybody have an idea how to bypass this extra CRLF?

BTW, here is the code as I would correct it.

FileUtils.copyFile
...
if (filterChainsAvailable) {
	ChainReaderHelper crh = new ChainReaderHelper();
	crh.setBufferSize(8192);
	crh.setPrimaryReader(in);
	crh.setFilterChains(filterChains);
	crh.setProject(project);
	Reader rdr = crh.getAssembledReader();
	in = new BufferedReader(rdr);
}
int length;
String newline = null;
String line = in.readLine();
while (line != null) {
	if (line.length() == 0) {
		out.newLine();
	} else {
		if (filterSetsAvailable) {
			newline = filters.replaceTokens(line);
		} else {
			newline = line;
		}
		out.write(newline);
		// out.newLine();           // do not add it
systematically
	}
	line = in.readLine();
	if (line != null) out.newLine();  // Add the new line only id
really needed
}


--Eric



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: extra CRLF when copying file with filtering

Posted by Eric Fesler <er...@hubmethods.com>.
"It adds a newline if there hasn't been one.  If the original file ends
in a newline, everything is fine.  Correct?"

Yes that's true.

"This would strip a newline character from the last line if there is
one."

Oops! You're right. So there is no trivial solution except rewrting a
new readline method that will allow an exact copy.

--Eric

-----Original Message-----
From: Stefan Bodewig [mailto:bodewig@apache.org] 
Sent: jeudi 28 novembre 2002 17:02
To: ant-user@jakarta.apache.org
Subject: Re: extra CRLF when copying file with filtering


On Thu, 28 Nov 2002, Eric Fesler <er...@hubmethods.com> wrote:

> Using ant 1.5, I just discover that ant is systematically adding an 
> extra CRLF at the end of the file when I used that copy task with 
> filtering set to true.

Quite possible, we have similar bugs in <concat> in CVS and in
<replaceregexp> for Ant 1.5.1.

It adds a newline if there hasn't been one.  If the original file ends
in a newline, everything is fine.  Correct?

> BTW, here is the code as I would correct it.

This would strip a newline character from the last line if there is one.

Stefan

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: extra CRLF when copying file with filtering

Posted by Stefan Bodewig <bo...@apache.org>.
On Thu, 28 Nov 2002, Eric Fesler <er...@hubmethods.com> wrote:

> Using ant 1.5, I just discover that ant is systematically adding an
> extra CRLF at the end of the file when I used that copy task with
> filtering set to true.

Quite possible, we have similar bugs in <concat> in CVS and in
<replaceregexp> for Ant 1.5.1.

It adds a newline if there hasn't been one.  If the original file ends
in a newline, everything is fine.  Correct?

> BTW, here is the code as I would correct it.

This would strip a newline character from the last line if there is
one.

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>