From 5fe7f691e923b524fb38e96c12a4e0eab1971989 Mon Sep 17 00:00:00 2001 From: Brian Remedios Date: Sun, 25 Sep 2011 03:59:28 +0000 Subject: [PATCH] StringBuffer -> StringBuilder switchovers, refactoring git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@7345 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/src/net/sourceforge/pmd/cpd/FileReporter.java | 14 ++++++++++---- pmd/src/net/sourceforge/pmd/cpd/GUI.java | 7 +++---- .../sourceforge/pmd/lang/ast/TokenMgrError.java | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/pmd/src/net/sourceforge/pmd/cpd/FileReporter.java b/pmd/src/net/sourceforge/pmd/cpd/FileReporter.java index de3c3f28ed..1938f796bb 100644 --- a/pmd/src/net/sourceforge/pmd/cpd/FileReporter.java +++ b/pmd/src/net/sourceforge/pmd/cpd/FileReporter.java @@ -3,7 +3,15 @@ */ package net.sourceforge.pmd.cpd; -import java.io.*; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; + +import net.sourceforge.pmd.util.IOUtil; /** * @author Philippe T'Seyen @@ -38,9 +46,7 @@ public class FileReporter { writer = new BufferedWriter(new OutputStreamWriter(outputStream, encoding)); writer.write(content); } finally { - if (writer != null) { - writer.close(); - } + IOUtil.closeQuietly(writer); } } catch (IOException ioe) { throw new ReportException(ioe); diff --git a/pmd/src/net/sourceforge/pmd/cpd/GUI.java b/pmd/src/net/sourceforge/pmd/cpd/GUI.java index 3c75b25d9b..2bc327ed30 100644 --- a/pmd/src/net/sourceforge/pmd/cpd/GUI.java +++ b/pmd/src/net/sourceforge/pmd/cpd/GUI.java @@ -64,6 +64,7 @@ import javax.swing.table.TableColumnModel; import javax.swing.table.TableModel; import net.sourceforge.pmd.PMD; +import net.sourceforge.pmd.util.IOUtil; public class GUI implements CPDListener { @@ -205,9 +206,7 @@ public class GUI implements CPDListener { } catch (IOException e) { error("Couldn't save file" + f.getAbsolutePath(), e); } finally { - if (pw != null) { - pw.close(); - } + IOUtil.closeQuietly(pw); } } else { error("Could not write to file " + f.getAbsolutePath(), null); @@ -441,7 +440,7 @@ public class GUI implements CPDListener { int[] selectionIndices = resultsTable.getSelectedRows(); int colCount = resultsTable.getColumnCount(); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (int r=0; r 0) { diff --git a/pmd/src/net/sourceforge/pmd/lang/ast/TokenMgrError.java b/pmd/src/net/sourceforge/pmd/lang/ast/TokenMgrError.java index 59ef734ce5..84fd533777 100644 --- a/pmd/src/net/sourceforge/pmd/lang/ast/TokenMgrError.java +++ b/pmd/src/net/sourceforge/pmd/lang/ast/TokenMgrError.java @@ -41,7 +41,7 @@ public class TokenMgrError extends RuntimeException * equivalents in the given string */ protected static final String addEscapes(String str) { - StringBuffer retval = new StringBuffer(); + StringBuilder retval = new StringBuilder(); char ch; for (int i = 0; i < str.length(); i++) { switch (str.charAt(i))