Vastly reduce memory requirements of DOMElementWriter on JDK 1.4.1 by using the workaround for JDK 1.4.1's StringBuffer#toString memory leak (JDC BugParade Bug 4724129). PR: 18504 Submitted by: Andrus Adamchik <mensk at users dot sourceforge dot net> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274393 13f79535-47bb-0310-9956-ffa450edef68master
@@ -54,6 +54,7 @@ | |||||
package org.apache.tools.ant.taskdefs.optional.junit; | package org.apache.tools.ant.taskdefs.optional.junit; | ||||
import java.io.BufferedWriter; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.OutputStream; | import java.io.OutputStream; | ||||
import java.io.OutputStreamWriter; | import java.io.OutputStreamWriter; | ||||
@@ -165,7 +166,7 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||||
if (out != null) { | if (out != null) { | ||||
Writer wri = null; | Writer wri = null; | ||||
try { | try { | ||||
wri = new OutputStreamWriter(out, "UTF8"); | |||||
wri = new BufferedWriter(new OutputStreamWriter(out, "UTF8")); | |||||
wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); | wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); | ||||
(new DOMElementWriter()).write(rootElement, wri, 0, " "); | (new DOMElementWriter()).write(rootElement, wri, 0, " "); | ||||
wri.flush(); | wri.flush(); | ||||
@@ -1,7 +1,7 @@ | |||||
/* | /* | ||||
* The Apache Software License, Version 1.1 | * The Apache Software License, Version 1.1 | ||||
* | * | ||||
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights | |||||
* Copyright (c) 2001-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 | ||||
@@ -53,6 +53,7 @@ | |||||
*/ | */ | ||||
package org.apache.tools.ant.taskdefs.optional.junit; | package org.apache.tools.ant.taskdefs.optional.junit; | ||||
import java.io.BufferedOutputStream; | |||||
import java.io.File; | import java.io.File; | ||||
import java.io.FileOutputStream; | import java.io.FileOutputStream; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
@@ -228,7 +229,7 @@ public class XMLResultAggregator extends Task implements XMLConstants { | |||||
OutputStream out = null; | OutputStream out = null; | ||||
PrintWriter wri = null; | PrintWriter wri = null; | ||||
try { | try { | ||||
out = new FileOutputStream(file); | |||||
out = new BufferedOutputStream(new FileOutputStream(file)); | |||||
wri = new PrintWriter(new OutputStreamWriter(out, "UTF8")); | wri = new PrintWriter(new OutputStreamWriter(out, "UTF8")); | ||||
wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); | wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); | ||||
(new DOMElementWriter()).write(doc.getDocumentElement(), wri, 0, " "); | (new DOMElementWriter()).write(doc.getDocumentElement(), wri, 0, " "); | ||||
@@ -53,6 +53,7 @@ | |||||
*/ | */ | ||||
package org.apache.tools.ant.taskdefs.optional.junit; | package org.apache.tools.ant.taskdefs.optional.junit; | ||||
import java.io.BufferedOutputStream; | |||||
import java.io.ByteArrayOutputStream; | import java.io.ByteArrayOutputStream; | ||||
import java.io.File; | import java.io.File; | ||||
import java.io.FileOutputStream; | import java.io.FileOutputStream; | ||||
@@ -81,12 +82,12 @@ abstract class XalanExecutor { | |||||
/** get the appropriate stream based on the format (frames/noframes) */ | /** get the appropriate stream based on the format (frames/noframes) */ | ||||
protected OutputStream getOutputStream() throws IOException { | protected OutputStream getOutputStream() throws IOException { | ||||
if (caller.FRAMES.equals(caller.format)){ | |||||
if (AggregateTransformer.FRAMES.equals(caller.format)){ | |||||
// dummy output for the framed report | // dummy output for the framed report | ||||
// it's all done by extension... | // it's all done by extension... | ||||
return new ByteArrayOutputStream(); | return new ByteArrayOutputStream(); | ||||
} else { | } else { | ||||
return new FileOutputStream(new File(caller.toDir, "junit-noframes.html")); | |||||
return new BufferedOutputStream(new FileOutputStream(new File(caller.toDir, "junit-noframes.html"))); | |||||
} | } | ||||
} | } | ||||
@@ -205,7 +205,8 @@ public class DOMElementWriter { | |||||
*/ | */ | ||||
public String encode(String value) { | public String encode(String value) { | ||||
sb.setLength(0); | sb.setLength(0); | ||||
for (int i = 0; i < value.length(); i++) { | |||||
int len = value.length(); | |||||
for (int i = 0; i < len; i++) { | |||||
char c = value.charAt(i); | char c = value.charAt(i); | ||||
switch (c) { | switch (c) { | ||||
case '<': | case '<': | ||||
@@ -236,7 +237,7 @@ public class DOMElementWriter { | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
return sb.toString(); | |||||
return sb.substring(0); | |||||
} | } | ||||
/** | /** | ||||
@@ -261,13 +262,13 @@ public class DOMElementWriter { | |||||
} | } | ||||
} | } | ||||
String result = sb.toString(); | |||||
String result = sb.substring(0); | |||||
int cdEnd = result.indexOf("]]>"); | int cdEnd = result.indexOf("]]>"); | ||||
while (cdEnd != -1) { | while (cdEnd != -1) { | ||||
sb.setLength(cdEnd); | sb.setLength(cdEnd); | ||||
sb.append("]]>") | sb.append("]]>") | ||||
.append(result.substring(cdEnd+3)); | .append(result.substring(cdEnd+3)); | ||||
result = sb.toString(); | |||||
result = sb.substring(0); | |||||
cdEnd = result.indexOf("]]>"); | cdEnd = result.indexOf("]]>"); | ||||
} | } | ||||