diff --git a/pmd/src/net/sourceforge/pmd/lang/dfa/report/ReportHTMLPrintVisitor.java b/pmd/src/net/sourceforge/pmd/lang/dfa/report/ReportHTMLPrintVisitor.java index ffa62cb107..23aacce4dc 100644 --- a/pmd/src/net/sourceforge/pmd/lang/dfa/report/ReportHTMLPrintVisitor.java +++ b/pmd/src/net/sourceforge/pmd/lang/dfa/report/ReportHTMLPrintVisitor.java @@ -2,6 +2,7 @@ package net.sourceforge.pmd.lang.dfa.report; import net.sourceforge.pmd.RuleViolation; import net.sourceforge.pmd.PMD; +import net.sourceforge.pmd.util.IOUtil; import net.sourceforge.pmd.util.StringUtil; import java.io.BufferedWriter; @@ -21,9 +22,9 @@ import java.io.IOException; public class ReportHTMLPrintVisitor extends ReportVisitor { @SuppressWarnings("PMD.AvoidStringBufferField") - private StringBuffer packageBuf = new StringBuffer(); + private StringBuilder packageBuf = new StringBuilder(); @SuppressWarnings("PMD.AvoidStringBufferField") - private StringBuffer classBuf = new StringBuffer(); + private StringBuilder classBuf = new StringBuilder(); private int length; private String baseDir; @@ -36,10 +37,10 @@ public class ReportHTMLPrintVisitor extends ReportVisitor { /** * Writes the buffer to file. */ - private void write(String filename, StringBuffer buf) throws IOException { + private void write(String filename, StringBuilder buf) throws IOException { BufferedWriter bw = new BufferedWriter(new FileWriter(new File(baseDir + FILE_SEPARATOR + filename))); bw.write(buf.toString(), 0, buf.length()); - bw.close(); + IOUtil.closeQuietly(bw); } /** @@ -47,7 +48,7 @@ public class ReportHTMLPrintVisitor extends ReportVisitor { */ private String displayRuleViolation(RuleViolation vio) { - StringBuffer sb = new StringBuffer(200); + StringBuilder sb = new StringBuilder(200); sb.append("
").append(fieldName).append(" | ").append(fieldData).append(" | # | " + " " + PMD.EOL); - this.length = this.packageBuf.length(); + length = packageBuf.length(); } @@ -133,14 +134,14 @@ public class ReportHTMLPrintVisitor extends ReportVisitor { try { - this.write(str + ".html", classBuf); + write(str + ".html", classBuf); } catch (Exception e) { throw new RuntimeException("Error while writing HTML report: " + e.getMessage()); } - classBuf = new StringBuffer(); + classBuf = new StringBuilder(); - this.packageBuf.insert(this.length, + packageBuf.insert(this.length, "
---|---|---|
- | " + "" + str + " | " + @@ -160,7 +161,7 @@ public class ReportHTMLPrintVisitor extends ReportVisitor { node.getParent().addNumberOfViolation(node.getNumberOfViolations()); } - this.packageBuf.insert(this.length, + packageBuf.insert(length, "|
" + str + " | " + "- | " + "" + node.getNumberOfViolations() + " | " + @@ -168,9 +169,9 @@ public class ReportHTMLPrintVisitor extends ReportVisitor { } // The first node of result tree. if (node.getParent() == null) { - this.packageBuf.append("