rm unnecessary .this references
cleaned up poor stream/reader/writer resource closures git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@7140 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src
name/herlin/command
net/sourceforge/pmd/eclipse
core
ext
impl
rulesets
plugin
runtime
cmd
BaseVisitor.javaDetectCutAndPasteCmd.javaFakeRuleViolation.javaRenderReportCmd.javaReviewResourceForRuleCommand.java
preferences/impl
properties/impl
ui
util
@ -163,14 +163,14 @@ public abstract class AbstractProcessableCommand implements Command {
|
||||
* @return the command processor for that command
|
||||
*/
|
||||
protected CommandProcessor getCommandProcessor() throws CommandException {
|
||||
if (this.commandProcessor == null) {
|
||||
if (commandProcessor == null) {
|
||||
final CommandProcessorStrategy strategy = getCommandProcessorStrategy();
|
||||
this.commandProcessor = strategy.getCommandProcessor(this);
|
||||
if (this.commandProcessor == null) {
|
||||
commandProcessor = strategy.getCommandProcessor(this);
|
||||
if (commandProcessor == null) {
|
||||
throw new UnregisteredCommandException("Processor cannot be found for that command");
|
||||
}
|
||||
}
|
||||
|
||||
return this.commandProcessor;
|
||||
return commandProcessor;
|
||||
}
|
||||
}
|
||||
|
@ -96,12 +96,12 @@ public class DefaultCommandProcessorStrategy implements CommandProcessorStrategy
|
||||
*/
|
||||
private void loadBundle() {
|
||||
try {
|
||||
final ResourceBundle bundle = ResourceBundle.getBundle(COMMAND_PROCESSOR_STRATEGY_BUNDLE);
|
||||
final Enumeration<String> e = bundle.getKeys();
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(COMMAND_PROCESSOR_STRATEGY_BUNDLE);
|
||||
Enumeration<String> e = bundle.getKeys();
|
||||
while (e.hasMoreElements()) {
|
||||
final String key = e.nextElement();
|
||||
final String value = bundle.getString(key);
|
||||
this.registeredCommandProcessors.put(key, value);
|
||||
String key = e.nextElement();
|
||||
String value = bundle.getString(key);
|
||||
registeredCommandProcessors.put(key, value);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
// @PMD:REVIEWED:EmptyCatchBlock: by Herlin on 01/05/05 18:10
|
||||
|
@ -87,8 +87,8 @@ public class RuleSetsExtensionProcessor {
|
||||
if (object instanceof IRuleSetsExtension) {
|
||||
final IRuleSetsExtension extension = (IRuleSetsExtension) object;
|
||||
|
||||
extension.registerRuleSets(this.ruleSetManager.getRegisteredRuleSets());
|
||||
extension.registerDefaultRuleSets(this.ruleSetManager.getDefaultRuleSets());
|
||||
extension.registerRuleSets(ruleSetManager.getRegisteredRuleSets());
|
||||
extension.registerDefaultRuleSets(ruleSetManager.getDefaultRuleSets());
|
||||
|
||||
} else {
|
||||
PMDPlugin.getDefault().log(IStatus.ERROR, "Extension " + element.getName() + " is not an instance of IRuleSetsExtension", null);
|
||||
|
@ -62,44 +62,44 @@ public class RuleSetManagerImpl implements IRuleSetManager {
|
||||
/**
|
||||
* @see net.sourceforge.pmd.eclipse.core.IRuleSetManager#registerRuleSet(net.sourceforge.pmd.RuleSet)
|
||||
*/
|
||||
public void registerRuleSet(final RuleSet ruleSet) {
|
||||
public void registerRuleSet(RuleSet ruleSet) {
|
||||
checkForNull(ruleSet);
|
||||
|
||||
this.ruleSets.add(ruleSet);
|
||||
ruleSets.add(ruleSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.eclipse.core.IRuleSetManager#unregisterRuleSet(net.sourceforge.pmd.RuleSet)
|
||||
*/
|
||||
public void unregisterRuleSet(final RuleSet ruleSet) {
|
||||
public void unregisterRuleSet(RuleSet ruleSet) {
|
||||
checkForNull(ruleSet);
|
||||
|
||||
this.ruleSets.remove(ruleSet);
|
||||
ruleSets.remove(ruleSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.eclipse.core.IRuleSetManager#getDefaultRuleSets()
|
||||
*/
|
||||
public Set<RuleSet> getDefaultRuleSets() {
|
||||
return this.defaultRuleSets;
|
||||
return defaultRuleSets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.eclipse.core.IRuleSetManager#registerDefaultRuleSet(net.sourceforge.pmd.RuleSet)
|
||||
*/
|
||||
public void registerDefaultRuleSet(final RuleSet ruleSet) {
|
||||
public void registerDefaultRuleSet(RuleSet ruleSet) {
|
||||
checkForNull(ruleSet);
|
||||
|
||||
this.defaultRuleSets.add(ruleSet);
|
||||
defaultRuleSets.add(ruleSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.eclipse.core.IRuleSetManager#unregisterDefaultRuleSet(net.sourceforge.pmd.RuleSet)
|
||||
*/
|
||||
public void unregisterDefaultRuleSet(final RuleSet ruleSet) {
|
||||
public void unregisterDefaultRuleSet(RuleSet ruleSet) {
|
||||
checkForNull(ruleSet);
|
||||
|
||||
this.defaultRuleSets.remove(ruleSet);
|
||||
defaultRuleSets.remove(ruleSet);
|
||||
}
|
||||
|
||||
private void checkForNull(RuleSet ruleSet) {
|
||||
|
@ -50,6 +50,7 @@ import net.sourceforge.pmd.eclipse.core.rulesets.IRuleSetsManager;
|
||||
import net.sourceforge.pmd.eclipse.core.rulesets.vo.Rule;
|
||||
import net.sourceforge.pmd.eclipse.core.rulesets.vo.RuleSet;
|
||||
import net.sourceforge.pmd.eclipse.core.rulesets.vo.RuleSets;
|
||||
import net.sourceforge.pmd.eclipse.util.IOUtil;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@ -114,12 +115,13 @@ public class RuleSetsManagerImpl implements IRuleSetsManager {
|
||||
throw new PMDCoreException("A RuleSetsNotFound Exception was thrown.", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.eclipse.core.rulesets.IRuleSetsManager#writeToXml(net.sourceforge.pmd.eclipse.core.rulesets.vo.RuleSets, java.io.OutputStream)
|
||||
*/
|
||||
public void writeToXml(RuleSets ruleSets, OutputStream output) throws PMDCoreException {
|
||||
LOG.debug("Storing plug-in rulesets");
|
||||
StringWriter writer = null;
|
||||
try {
|
||||
LocalConfiguration.getInstance().getProperties().setProperty("org.exolab.castor.indent", "true");
|
||||
|
||||
@ -127,12 +129,11 @@ public class RuleSetsManagerImpl implements IRuleSetsManager {
|
||||
final URL mappingSpecUrl = this.getClass().getResource(RULESETS_MAPPING);
|
||||
mapping.loadMapping(mappingSpecUrl);
|
||||
|
||||
final StringWriter writer = new StringWriter();
|
||||
writer = new StringWriter();
|
||||
final Marshaller marshaller = new Marshaller(writer);
|
||||
marshaller.setMapping(mapping);
|
||||
marshaller.marshal(ruleSets);
|
||||
writer.flush();
|
||||
writer.close();
|
||||
|
||||
output.write(writer.getBuffer().toString().getBytes());
|
||||
output.flush();
|
||||
@ -149,6 +150,8 @@ public class RuleSetsManagerImpl implements IRuleSetsManager {
|
||||
} catch (IOException e) {
|
||||
LOG.error("A IO Exception was thrown.");
|
||||
throw new PMDCoreException("A IO Exception was thrown.", e);
|
||||
} finally {
|
||||
IOUtil.closeQuietly(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ public class Properties {
|
||||
|
||||
if (arg0 instanceof Properties) {
|
||||
final Properties p = (Properties) arg0;
|
||||
equal = this.propertiesSet.equals(p.propertiesSet);
|
||||
equal = propertiesSet.equals(p.propertiesSet);
|
||||
}
|
||||
|
||||
return equal;
|
||||
@ -92,7 +92,7 @@ public class Properties {
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.propertiesSet.hashCode();
|
||||
return propertiesSet.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,9 +100,9 @@ public class Properties {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder buffer = new StringBuilder("Properties");
|
||||
for (Property property : this.propertiesSet) {
|
||||
final Property p = property;
|
||||
StringBuilder buffer = new StringBuilder("Properties");
|
||||
for (Property property : propertiesSet) {
|
||||
Property p = property;
|
||||
buffer.append(' ').append(p);
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ public class Property {
|
||||
* @return Returns the name.
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,7 +76,7 @@ public class Property {
|
||||
* @return Returns the value.
|
||||
*/
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -99,8 +99,8 @@ public class Property {
|
||||
boolean equal = false;
|
||||
|
||||
if (arg0 instanceof Property) {
|
||||
final Property p = (Property) arg0;
|
||||
equal = this.name.equals(p.name) && this.value.equals(p.value);
|
||||
Property p = (Property) arg0;
|
||||
equal = name.equals(p.name) && value.equals(p.value);
|
||||
}
|
||||
|
||||
return equal;
|
||||
@ -110,14 +110,14 @@ public class Property {
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
public int hashCode() {
|
||||
return (this.name + this.value).hashCode();
|
||||
return (name + value).hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return "property name=" + this.name + " value=" + this.value;
|
||||
return "property name=" + name + " value=" + value;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ public class Rule {
|
||||
* @return Returns the ref.
|
||||
*/
|
||||
public String getRef() {
|
||||
return this.ref;
|
||||
return ref;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -145,9 +145,9 @@ public class Rule {
|
||||
|
||||
if (arg0 instanceof Rule) {
|
||||
final Rule r = (Rule) arg0;
|
||||
equal = this.ref.equals(r.ref);
|
||||
equal = equal && (((this.priority == null) && (r.priority == null)) || (this.priority.equals(r.priority)));
|
||||
equal = equal && (((this.properties == null) && (r.properties == null)) || (this.properties.equals(r.properties)));
|
||||
equal = ref.equals(r.ref);
|
||||
equal = equal && (((priority == null) && (r.priority == null)) || (this.priority.equals(r.priority)));
|
||||
equal = equal && (((properties == null) && (r.properties == null)) || (this.properties.equals(r.properties)));
|
||||
}
|
||||
|
||||
return equal;
|
||||
@ -157,12 +157,12 @@ public class Rule {
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
public int hashCode() {
|
||||
int hashCode = this.ref.hashCode();
|
||||
if (this.priority != null) {
|
||||
hashCode += this.priority.hashCode() * 13 * 13;
|
||||
int hashCode = ref.hashCode();
|
||||
if (priority != null) {
|
||||
hashCode += priority.hashCode() * 13 * 13;
|
||||
}
|
||||
if (this.properties != null) {
|
||||
hashCode += this.properties.hashCode() * 21 * 21;
|
||||
if (properties != null) {
|
||||
hashCode += properties.hashCode() * 21 * 21;
|
||||
}
|
||||
|
||||
return hashCode;
|
||||
@ -172,8 +172,8 @@ public class Rule {
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return "Rule ref=" + this.ref + " message=" + this.message + " priority=" + this.priority.toString() + " properties="
|
||||
+ this.properties.toString();
|
||||
return "Rule ref=" + ref + " message=" + message + " priority=" + priority.toString() + " properties="
|
||||
+ properties.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -183,7 +183,7 @@ public class Rule {
|
||||
* @return Returns the PMD Rule object.
|
||||
*/
|
||||
public net.sourceforge.pmd.Rule getPmdRule() {
|
||||
return this.pmdRule;
|
||||
return pmdRule;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,7 +62,7 @@ public class RuleSets {
|
||||
* @return Returns the defaultRuleSet.
|
||||
*/
|
||||
public RuleSet getDefaultRuleSet() {
|
||||
return this.defaultRuleSet;
|
||||
return defaultRuleSet;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -75,7 +75,7 @@ public class RuleSets {
|
||||
if (defaultRuleSet == null) {
|
||||
throw new IllegalArgumentException("default rule set cannot be null");
|
||||
}
|
||||
if (!this.ruleSetsList.contains(defaultRuleSet)) {
|
||||
if (!ruleSetsList.contains(defaultRuleSet)) {
|
||||
throw new IllegalArgumentException("The rule set " + defaultRuleSet.getName()
|
||||
+ " must belong to the rule set list to be set as default.");
|
||||
}
|
||||
@ -89,7 +89,7 @@ public class RuleSets {
|
||||
* @return Returns the ruleSet list.
|
||||
*/
|
||||
public List<RuleSet> getRuleSets() {
|
||||
return this.ruleSetsList;
|
||||
return ruleSetsList;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -110,7 +110,7 @@ public class RuleSets {
|
||||
* @return the name of the default ruleset
|
||||
*/
|
||||
public String getDefaultRuleSetName() {
|
||||
return this.defaultRuleSet.getName();
|
||||
return defaultRuleSet.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -123,8 +123,8 @@ public class RuleSets {
|
||||
throw new IllegalArgumentException("The default ruleset name must not be null or empty");
|
||||
}
|
||||
|
||||
for (RuleSet ruleSet2 : this.ruleSetsList) {
|
||||
final RuleSet ruleSet = ruleSet2;
|
||||
for (RuleSet ruleSet2 : ruleSetsList) {
|
||||
RuleSet ruleSet = ruleSet2;
|
||||
if (ruleSet.getName().equals(ruleSetName)) {
|
||||
setDefaultRuleSet(ruleSet);
|
||||
break;
|
||||
@ -137,11 +137,11 @@ public class RuleSets {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder buffer = new StringBuilder("RuleSets defaultRuleSet=");
|
||||
buffer.append(this.defaultRuleSet.getName());
|
||||
StringBuilder buffer = new StringBuilder("RuleSets defaultRuleSet=");
|
||||
buffer.append(defaultRuleSet.getName());
|
||||
buffer.append(" ruleSetsList=");
|
||||
|
||||
for (RuleSet ruleSet : this.ruleSetsList) {
|
||||
for (RuleSet ruleSet : ruleSetsList) {
|
||||
buffer.append(ruleSet);
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sourceforge.pmd.RuleSet;
|
||||
import net.sourceforge.pmd.RuleSetFactory;
|
||||
@ -65,7 +66,7 @@ public class PMDPlugin extends AbstractUIPlugin {
|
||||
|
||||
private static File pluginFolder;
|
||||
|
||||
private HashMap<RGB, Color> coloursByRGB = new HashMap<RGB, Color>();
|
||||
private Map<RGB, Color> coloursByRGB = new HashMap<RGB, Color>();
|
||||
|
||||
public static final String PLUGIN_ID = "net.sourceforge.pmd.eclipse.plugin";
|
||||
|
||||
|
@ -47,6 +47,7 @@ import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
|
||||
import net.sourceforge.pmd.eclipse.runtime.PMDRuntimeConstants;
|
||||
import net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties;
|
||||
import net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException;
|
||||
import net.sourceforge.pmd.eclipse.util.IOUtil;
|
||||
import net.sourceforge.pmd.util.NumericConstants;
|
||||
import net.sourceforge.pmd.util.StringUtil;
|
||||
|
||||
@ -255,12 +256,12 @@ public class BaseVisitor {
|
||||
input.close();
|
||||
|
||||
timer.stop();
|
||||
this.pmdDuration += timer.getDuration();
|
||||
pmdDuration += timer.getDuration();
|
||||
|
||||
updateMarkers(file, context, isUseTaskMarker(), getAccumulator());
|
||||
|
||||
worked(1);
|
||||
this.fileCount++;
|
||||
fileCount++;
|
||||
} else {
|
||||
log.debug("The file " + file.getName() + " is not in the working set");
|
||||
}
|
||||
@ -294,9 +295,9 @@ public class BaseVisitor {
|
||||
*/
|
||||
private boolean isFileInWorkingSet(final IFile file) throws PropertiesException {
|
||||
boolean fileInWorkingSet = true;
|
||||
final IWorkingSet workingSet = this.projectProperties.getProjectWorkingSet();
|
||||
IWorkingSet workingSet = projectProperties.getProjectWorkingSet();
|
||||
if (workingSet != null) {
|
||||
final ResourceWorkingSetFilter filter = new ResourceWorkingSetFilter();
|
||||
ResourceWorkingSetFilter filter = new ResourceWorkingSetFilter();
|
||||
filter.setWorkingSet(workingSet);
|
||||
fileInWorkingSet = filter.select(null, null, file);
|
||||
}
|
||||
@ -401,12 +402,13 @@ public class BaseVisitor {
|
||||
*/
|
||||
private List<Review> findReviewedViolations(final IFile file) {
|
||||
final List<Review> reviews = new ArrayList<Review>();
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
int lineNumber = 0;
|
||||
boolean findLine = false;
|
||||
boolean comment = false;
|
||||
final Stack<String> pendingReviews = new Stack<String>();
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContents()));
|
||||
reader = new BufferedReader(new InputStreamReader(file.getContents()));
|
||||
while (reader.ready()) {
|
||||
String line = reader.readLine();
|
||||
if (line != null) {
|
||||
@ -447,6 +449,8 @@ public class BaseVisitor {
|
||||
PMDPlugin.getDefault().logError("Core Exception when searching reviewed violations", e);
|
||||
} catch (IOException e) {
|
||||
PMDPlugin.getDefault().logError("IO Exception when searching reviewed violations", e);
|
||||
} finally {
|
||||
IOUtil.closeQuietly(reader);
|
||||
}
|
||||
|
||||
return reviews;
|
||||
|
@ -53,6 +53,7 @@ import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
|
||||
import net.sourceforge.pmd.eclipse.runtime.PMDRuntimeConstants;
|
||||
import net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties;
|
||||
import net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException;
|
||||
import net.sourceforge.pmd.eclipse.util.IOUtil;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
@ -100,7 +101,7 @@ public class DetectCutAndPasteCmd extends AbstractProjectCommand {
|
||||
public void execute() throws CommandException {
|
||||
try {
|
||||
// find the files
|
||||
final List<File> files = findFiles();
|
||||
List<File> files = findFiles();
|
||||
|
||||
if (files.size() == 0) {
|
||||
logInfo("No files found for specified language.");
|
||||
@ -116,7 +117,7 @@ public class DetectCutAndPasteCmd extends AbstractProjectCommand {
|
||||
|
||||
if (!isCanceled()) {
|
||||
// if the command was not canceled
|
||||
if (this.createReport) {
|
||||
if (createReport) {
|
||||
// create the report optionally
|
||||
this.renderReport(cpd.getMatches());
|
||||
}
|
||||
@ -138,7 +139,7 @@ public class DetectCutAndPasteCmd extends AbstractProjectCommand {
|
||||
log.debug("Properties Exception: " + e.getMessage(), e);
|
||||
throw new CommandException(e);
|
||||
} finally {
|
||||
this.setTerminated(true);
|
||||
setTerminated(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -263,7 +264,7 @@ public class DetectCutAndPasteCmd extends AbstractProjectCommand {
|
||||
|
||||
return cpd;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Renders a report using the matches of the CPD. Creates a report folder
|
||||
* and report file.
|
||||
@ -271,6 +272,8 @@ public class DetectCutAndPasteCmd extends AbstractProjectCommand {
|
||||
* @throws CommandException
|
||||
*/
|
||||
private void renderReport(Iterator<Match> matches) throws CommandException {
|
||||
InputStream contentsStream = null;
|
||||
|
||||
try {
|
||||
log.debug("Rendering CPD report");
|
||||
subTask("Rendering CPD report");
|
||||
@ -286,7 +289,7 @@ public class DetectCutAndPasteCmd extends AbstractProjectCommand {
|
||||
// Create the report file
|
||||
log.debug("Create the report file");
|
||||
final IFile reportFile = folder.getFile(reportName);
|
||||
final InputStream contentsStream = new ByteArrayInputStream(reportString.getBytes());
|
||||
contentsStream = new ByteArrayInputStream(reportString.getBytes());
|
||||
if (reportFile.exists()) {
|
||||
log.debug(" Overwritting the report file");
|
||||
reportFile.setContents(contentsStream, true, false, getMonitor());
|
||||
@ -302,6 +305,8 @@ public class DetectCutAndPasteCmd extends AbstractProjectCommand {
|
||||
} catch (IOException e) {
|
||||
log.debug("IO Exception: " + e.getMessage(), e);
|
||||
throw new CommandException(e);
|
||||
} finally {
|
||||
IOUtil.closeQuietly(contentsStream);
|
||||
}
|
||||
}
|
||||
}
|
@ -75,70 +75,70 @@ public class FakeRuleViolation implements RuleViolation {
|
||||
* @see net.sourceforge.pmd.IRuleViolation#getFilename()
|
||||
*/
|
||||
public String getFilename() {
|
||||
return this.filename;
|
||||
return filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.IRuleViolation#getBeginLine()
|
||||
*/
|
||||
public int getBeginLine() {
|
||||
return this.beginLine;
|
||||
return beginLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.IRuleViolation#getBeginColumn()
|
||||
*/
|
||||
public int getBeginColumn() {
|
||||
return this.beginColumn;
|
||||
return beginColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.IRuleViolation#getEndLine()
|
||||
*/
|
||||
public int getEndLine() {
|
||||
return this.endLine;
|
||||
return endLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.IRuleViolation#getEndColumn()
|
||||
*/
|
||||
public int getEndColumn() {
|
||||
return this.endColumn;
|
||||
return endColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.IRuleViolation#getRule()
|
||||
*/
|
||||
public Rule getRule() {
|
||||
return this.rule;
|
||||
return rule;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.IRuleViolation#getDescription()
|
||||
*/
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.IRuleViolation#getPackageName()
|
||||
*/
|
||||
public String getPackageName() {
|
||||
return this.packageName;
|
||||
return packageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.IRuleViolation#getMethodName()
|
||||
*/
|
||||
public String getMethodName() {
|
||||
return this.methodName;
|
||||
return methodName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.IRuleViolation#getClassName()
|
||||
*/
|
||||
public String getClassName() {
|
||||
return this.className;
|
||||
return className;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -152,7 +152,7 @@ public class FakeRuleViolation implements RuleViolation {
|
||||
* @see net.sourceforge.pmd.IRuleViolation#getVariableName()
|
||||
*/
|
||||
public String getVariableName() {
|
||||
return this.variableName;
|
||||
return variableName;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,6 +49,7 @@ import net.sourceforge.pmd.RuleSet;
|
||||
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
|
||||
import net.sourceforge.pmd.eclipse.runtime.PMDRuntimeConstants;
|
||||
import net.sourceforge.pmd.eclipse.runtime.builder.MarkerUtil;
|
||||
import net.sourceforge.pmd.eclipse.util.IOUtil;
|
||||
import net.sourceforge.pmd.renderers.Renderer;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
@ -106,6 +107,7 @@ public class RenderReportCmd extends AbstractProjectCommand {
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws CommandException {
|
||||
StringWriter writer = null;
|
||||
try {
|
||||
log.debug("Starting RenderReport command");
|
||||
log.debug(" Create a report object");
|
||||
@ -122,23 +124,23 @@ public class RenderReportCmd extends AbstractProjectCommand {
|
||||
final Renderer renderer = entry.getValue();
|
||||
|
||||
log.debug(" Render the report");
|
||||
final StringWriter w = new StringWriter();
|
||||
renderer.setWriter(w);
|
||||
writer = new StringWriter();
|
||||
renderer.setWriter(writer);
|
||||
renderer.start();
|
||||
renderer.renderFileReport(report);
|
||||
renderer.end();
|
||||
|
||||
final String reportString = w.toString();
|
||||
String reportString = writer.toString();
|
||||
|
||||
log.debug(" Creating the report file");
|
||||
final IFile reportFile = folder.getFile(reportName);
|
||||
final InputStream contentsStream = new ByteArrayInputStream(reportString.getBytes());
|
||||
if (reportFile.exists()) {
|
||||
reportFile.setContents(contentsStream, true, false, this.getMonitor());
|
||||
reportFile.setContents(contentsStream, true, false, getMonitor());
|
||||
} else {
|
||||
reportFile.create(contentsStream, true, this.getMonitor());
|
||||
reportFile.create(contentsStream, true, getMonitor());
|
||||
}
|
||||
reportFile.refreshLocal(IResource.DEPTH_INFINITE, this.getMonitor());
|
||||
reportFile.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
|
||||
contentsStream.close();
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
@ -148,8 +150,9 @@ public class RenderReportCmd extends AbstractProjectCommand {
|
||||
log.debug("Core Exception: " + e.getMessage(), e);
|
||||
throw new CommandException(e);
|
||||
} finally {
|
||||
IOUtil.closeQuietly(writer);
|
||||
log.debug("End of RenderReport command");
|
||||
this.setTerminated(true);
|
||||
setTerminated(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -158,9 +161,9 @@ public class RenderReportCmd extends AbstractProjectCommand {
|
||||
*/
|
||||
@Override
|
||||
public void reset() {
|
||||
this.setProject(null);
|
||||
this.renderers = new HashMap<String, Renderer>();
|
||||
this.setTerminated(false);
|
||||
setProject(null);
|
||||
renderers = new HashMap<String, Renderer>();
|
||||
setTerminated(false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,24 +118,24 @@ public class ReviewResourceForRuleCommand extends AbstractDefaultCommand {
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws CommandException {
|
||||
final IProject project = resource.getProject();
|
||||
final IFile file = (IFile) resource.getAdapter(IFile.class);
|
||||
IProject project = resource.getProject();
|
||||
IFile file = (IFile) resource.getAdapter(IFile.class);
|
||||
beginTask("PMD checking for rule: " + rule.getName(), 1);
|
||||
|
||||
if (file != null) {
|
||||
final RuleSet ruleSet = new RuleSet();
|
||||
RuleSet ruleSet = new RuleSet();
|
||||
ruleSet.addRule(rule);
|
||||
final PMDEngine pmdEngine = getPmdEngineForProject(project);
|
||||
final File sourceCodeFile = file.getFullPath().toFile();
|
||||
File sourceCodeFile = file.getFullPath().toFile();
|
||||
if (pmdEngine.applies(sourceCodeFile, ruleSet)) {
|
||||
try {
|
||||
this.context = new RuleContext();
|
||||
this.context.setSourceCodeFile(sourceCodeFile);
|
||||
this.context.setSourceCodeFilename(file.getName());
|
||||
this.context.setReport(new Report());
|
||||
context = new RuleContext();
|
||||
context.setSourceCodeFile(sourceCodeFile);
|
||||
context.setSourceCodeFilename(file.getName());
|
||||
context.setReport(new Report());
|
||||
|
||||
final Reader input = new InputStreamReader(file.getContents(), file.getCharset());
|
||||
pmdEngine.processFile(input, ruleSet, this.context);
|
||||
Reader input = new InputStreamReader(file.getContents(), file.getCharset());
|
||||
pmdEngine.processFile(input, ruleSet, context);
|
||||
input.close();
|
||||
} catch (CoreException e) {
|
||||
throw new CommandException(e);
|
||||
|
@ -62,6 +62,7 @@ import net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException;
|
||||
import net.sourceforge.pmd.eclipse.runtime.writer.IRuleSetWriter;
|
||||
import net.sourceforge.pmd.eclipse.runtime.writer.WriterException;
|
||||
import net.sourceforge.pmd.eclipse.ui.priority.PriorityDescriptor;
|
||||
import net.sourceforge.pmd.eclipse.util.IOUtil;
|
||||
import net.sourceforge.pmd.util.StringUtil;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
@ -528,17 +529,20 @@ class PreferencesManagerImpl implements IPreferencesManager {
|
||||
* Store the rule set in preference store
|
||||
*/
|
||||
private void storeRuleSetInStateLocation(RuleSet ruleSet) {
|
||||
OutputStream out = null;
|
||||
try {
|
||||
IPath ruleSetLocation = PMDPlugin.getDefault().getStateLocation().append(PREFERENCE_RULESET_FILE);
|
||||
OutputStream out = new FileOutputStream(ruleSetLocation.toOSString());
|
||||
out = new FileOutputStream(ruleSetLocation.toOSString());
|
||||
IRuleSetWriter writer = PMDPlugin.getDefault().getRuleSetWriter();
|
||||
writer.write(out, ruleSet);
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
PMDPlugin.getDefault().logError("IO Exception when storing ruleset in state location", e);
|
||||
} catch (WriterException e) {
|
||||
PMDPlugin.getDefault().logError("General PMD Eclipse Exception when storing ruleset in state location", e);
|
||||
} finally {
|
||||
IOUtil.closeQuietly(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ import net.sourceforge.pmd.eclipse.runtime.properties.IProjectPropertiesManager;
|
||||
import net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException;
|
||||
import net.sourceforge.pmd.eclipse.runtime.writer.IRuleSetWriter;
|
||||
import net.sourceforge.pmd.eclipse.runtime.writer.WriterException;
|
||||
import net.sourceforge.pmd.eclipse.util.IOUtil;
|
||||
import net.sourceforge.pmd.util.StringUtil;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
@ -220,7 +221,7 @@ public class ProjectPropertiesImpl implements IProjectProperties {
|
||||
*/
|
||||
public File getResolvedRuleSetFile() {
|
||||
// Check as project file, otherwise as standard file
|
||||
final IFile file = this.project.getFile(getRuleSetFile());
|
||||
IFile file = project.getFile(getRuleSetFile());
|
||||
boolean exists = file.exists() && file.isAccessible();
|
||||
File f;
|
||||
if (exists) {
|
||||
@ -230,7 +231,7 @@ public class ProjectPropertiesImpl implements IProjectProperties {
|
||||
f = new File(getRuleSetFile());
|
||||
}
|
||||
} else {
|
||||
f = new File(getRuleSetFile());
|
||||
f = new File(getRuleSetFile());
|
||||
}
|
||||
return f;
|
||||
}
|
||||
@ -241,13 +242,14 @@ public class ProjectPropertiesImpl implements IProjectProperties {
|
||||
*/
|
||||
public void createDefaultRuleSetFile() throws PropertiesException {
|
||||
log.info("Create a default rule set file for project " + this.project.getName());
|
||||
ByteArrayOutputStream baos = null;
|
||||
try {
|
||||
final IRuleSetWriter writer = PMDPlugin.getDefault().getRuleSetWriter();
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
writer.write(baos, this.projectRuleSet);
|
||||
IRuleSetWriter writer = PMDPlugin.getDefault().getRuleSetWriter();
|
||||
baos = new ByteArrayOutputStream();
|
||||
writer.write(baos, projectRuleSet);
|
||||
baos.close();
|
||||
|
||||
final IFile file = this.project.getFile(PROJECT_RULESET_FILE);
|
||||
final IFile file = project.getFile(PROJECT_RULESET_FILE);
|
||||
if (file.exists() && file.isAccessible()) {
|
||||
throw new PropertiesException("Project ruleset file already exists");
|
||||
} else {
|
||||
@ -261,6 +263,8 @@ public class ProjectPropertiesImpl implements IProjectProperties {
|
||||
throw new PropertiesException(e);
|
||||
} catch (CoreException e) {
|
||||
throw new PropertiesException(e);
|
||||
} finally {
|
||||
IOUtil.closeQuietly(baos);
|
||||
}
|
||||
|
||||
}
|
||||
@ -269,7 +273,7 @@ public class ProjectPropertiesImpl implements IProjectProperties {
|
||||
* @see net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties#isIncludeDerivedFiles()
|
||||
*/
|
||||
public boolean isIncludeDerivedFiles() {
|
||||
return this.includeDerivedFiles;
|
||||
return includeDerivedFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,6 +57,7 @@ import net.sourceforge.pmd.eclipse.runtime.builder.PMDNature;
|
||||
import net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties;
|
||||
import net.sourceforge.pmd.eclipse.runtime.properties.IProjectPropertiesManager;
|
||||
import net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException;
|
||||
import net.sourceforge.pmd.eclipse.util.IOUtil;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
@ -167,7 +168,7 @@ public class ProjectPropertiesManagerImpl implements IProjectPropertiesManager {
|
||||
*/
|
||||
private ProjectPropertiesTO readProjectProperties(final IProject project) throws PropertiesException {
|
||||
ProjectPropertiesTO projectProperties = null;
|
||||
|
||||
Reader reader = null;
|
||||
try {
|
||||
final Mapping mapping = new Mapping(this.getClass().getClassLoader());
|
||||
final URL mappingSpecUrl = this.getClass().getResource(PROPERTIES_MAPPING);
|
||||
@ -175,7 +176,7 @@ public class ProjectPropertiesManagerImpl implements IProjectPropertiesManager {
|
||||
|
||||
final IFile propertiesFile = project.getFile(PROPERTIES_FILE);
|
||||
if (propertiesFile.exists() && propertiesFile.isAccessible()) {
|
||||
final Reader reader = new InputStreamReader(propertiesFile.getContents());
|
||||
reader = new InputStreamReader(propertiesFile.getContents());
|
||||
final Unmarshaller unmarshaller = new Unmarshaller(mapping);
|
||||
projectProperties = (ProjectPropertiesTO) unmarshaller.unmarshal(reader);
|
||||
reader.close();
|
||||
@ -190,6 +191,8 @@ public class ProjectPropertiesManagerImpl implements IProjectPropertiesManager {
|
||||
throw new PropertiesException(e);
|
||||
} catch (CoreException e) {
|
||||
throw new PropertiesException(e);
|
||||
} finally {
|
||||
IOUtil.closeQuietly(reader);
|
||||
}
|
||||
|
||||
return projectProperties;
|
||||
@ -258,14 +261,15 @@ public class ProjectPropertiesManagerImpl implements IProjectPropertiesManager {
|
||||
*/
|
||||
private void writeProjectProperties(final IProject project, final ProjectPropertiesTO projectProperties)
|
||||
throws PropertiesException {
|
||||
StringWriter writer = null;
|
||||
try {
|
||||
LocalConfiguration.getInstance().getProperties().setProperty("org.exolab.castor.indent", "true");
|
||||
|
||||
final Mapping mapping = new Mapping(this.getClass().getClassLoader());
|
||||
final URL mappingSpecUrl = this.getClass().getResource(PROPERTIES_MAPPING);
|
||||
final Mapping mapping = new Mapping(getClass().getClassLoader());
|
||||
final URL mappingSpecUrl = getClass().getResource(PROPERTIES_MAPPING);
|
||||
mapping.loadMapping(mappingSpecUrl);
|
||||
|
||||
final StringWriter writer = new StringWriter();
|
||||
writer = new StringWriter();
|
||||
final Marshaller marshaller = new Marshaller(writer);
|
||||
marshaller.setMapping(mapping);
|
||||
marshaller.marshal(projectProperties);
|
||||
@ -288,6 +292,8 @@ public class ProjectPropertiesManagerImpl implements IProjectPropertiesManager {
|
||||
throw new PropertiesException(e);
|
||||
} catch (CoreException e) {
|
||||
throw new PropertiesException(e);
|
||||
} finally {
|
||||
IOUtil.closeQuietly(writer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.sourceforge.pmd.eclipse.ui;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
@ -43,7 +44,7 @@ public class ShapePicker<T extends Object> extends Canvas implements ISelectionP
|
||||
private Map<T, ShapeDescriptor> shapeDescriptorsByItem;
|
||||
// private Map<T, String> tooltipsByItem;
|
||||
|
||||
private Vector<ISelectionChangedListener> listeners;
|
||||
private List<ISelectionChangedListener> listeners;
|
||||
|
||||
private static Map<RGB, Color> coloursByRGB = new HashMap<RGB, Color>();
|
||||
|
||||
|
@ -45,6 +45,7 @@ import java.util.Iterator;
|
||||
import net.sourceforge.pmd.eclipse.runtime.PMDRuntimeConstants;
|
||||
import net.sourceforge.pmd.eclipse.runtime.cmd.AbstractDefaultCommand;
|
||||
import net.sourceforge.pmd.eclipse.ui.nls.StringKeys;
|
||||
import net.sourceforge.pmd.eclipse.util.IOUtil;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
@ -245,11 +246,12 @@ public class ClearReviewsAction extends AbstractUIAction implements IResourceVis
|
||||
if (!isReviewable(file)) return null;
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
PrintWriter out = null;
|
||||
boolean noChange = true;
|
||||
try {
|
||||
boolean comment = false;
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContents()));
|
||||
PrintWriter out = new PrintWriter(baos);
|
||||
out = new PrintWriter(baos);
|
||||
|
||||
while (reader.ready()) {
|
||||
String origLine = reader.readLine();
|
||||
@ -281,6 +283,9 @@ public class ClearReviewsAction extends AbstractUIAction implements IResourceVis
|
||||
logError(StringKeys.ERROR_CORE_EXCEPTION, e);
|
||||
} catch (IOException e) {
|
||||
logError(StringKeys.ERROR_IO_EXCEPTION, e);
|
||||
} finally{
|
||||
IOUtil.closeQuietly(baos);
|
||||
IOUtil.closeQuietly(out);
|
||||
}
|
||||
|
||||
return noChange ? null : baos.toString();
|
||||
|
@ -43,6 +43,7 @@ import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
|
||||
import net.sourceforge.pmd.eclipse.runtime.writer.IAstWriter;
|
||||
import net.sourceforge.pmd.eclipse.runtime.writer.WriterException;
|
||||
import net.sourceforge.pmd.eclipse.ui.nls.StringKeys;
|
||||
import net.sourceforge.pmd.eclipse.util.IOUtil;
|
||||
import net.sourceforge.pmd.lang.ast.JavaCharStream;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
|
||||
import net.sourceforge.pmd.lang.java.ast.JavaParser;
|
||||
@ -132,10 +133,12 @@ public class PMDGenerateASTAction extends AbstractUIAction implements IRunnableW
|
||||
*/
|
||||
private void generateAST(IFile file) {
|
||||
log.info("Genrating AST for file " + file.getName());
|
||||
ByteArrayOutputStream byteArrayOutputStream = null;
|
||||
ByteArrayInputStream astInputStream = null;
|
||||
try {
|
||||
JavaParser parser = new JavaParser(new JavaCharStream(file.getContents()));
|
||||
ASTCompilationUnit compilationUnit = parser.CompilationUnit();
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
IAstWriter astWriter = PMDPlugin.getDefault().getAstWriter();
|
||||
astWriter.write(byteArrayOutputStream, compilationUnit);
|
||||
byteArrayOutputStream.flush();
|
||||
@ -156,7 +159,7 @@ public class PMDGenerateASTAction extends AbstractUIAction implements IRunnableW
|
||||
if (astFile.exists()) {
|
||||
astFile.delete(false, null);
|
||||
}
|
||||
ByteArrayInputStream astInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
||||
astInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
||||
astFile.create(astInputStream, false, null);
|
||||
}
|
||||
|
||||
@ -168,6 +171,9 @@ public class PMDGenerateASTAction extends AbstractUIAction implements IRunnableW
|
||||
showErrorById( StringKeys.ERROR_PMD_EXCEPTION, e);
|
||||
} catch (IOException e) {
|
||||
showErrorById(StringKeys.ERROR_IO_EXCEPTION, e);
|
||||
} finally {
|
||||
IOUtil.closeQuietly(byteArrayOutputStream);
|
||||
IOUtil.closeQuietly(astInputStream);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ import net.sourceforge.pmd.eclipse.ui.nls.StringKeys;
|
||||
import net.sourceforge.pmd.eclipse.ui.preferences.RuleSetSelectionDialog;
|
||||
import net.sourceforge.pmd.eclipse.ui.preferences.editors.SWTUtil;
|
||||
import net.sourceforge.pmd.eclipse.ui.preferences.panelmanagers.CreateRuleWizard;
|
||||
import net.sourceforge.pmd.eclipse.util.IOUtil;
|
||||
import net.sourceforge.pmd.eclipse.util.Util;
|
||||
import net.sourceforge.pmd.util.FileUtil;
|
||||
import net.sourceforge.pmd.util.designer.Designer;
|
||||
@ -351,12 +352,16 @@ public class RuleTableManager extends AbstractTreeTableManager<Rule> implements
|
||||
}
|
||||
|
||||
if (flContinue) {
|
||||
ruleSet.setName(FileUtil.getFileNameWithoutExtension(file.getName()));
|
||||
ruleSet.setDescription(input.getValue());
|
||||
OutputStream out = new FileOutputStream(fileName);
|
||||
IRuleSetWriter writer = plugin.getRuleSetWriter();
|
||||
writer.write(out, ruleSet);
|
||||
out.close();
|
||||
OutputStream out = null;
|
||||
try {
|
||||
ruleSet.setName(FileUtil.getFileNameWithoutExtension(file.getName()));
|
||||
ruleSet.setDescription(input.getValue());
|
||||
out = new FileOutputStream(fileName);
|
||||
IRuleSetWriter writer = plugin.getRuleSetWriter();
|
||||
writer.write(out, ruleSet);
|
||||
} finally {
|
||||
IOUtil.closeQuietly(out);
|
||||
}
|
||||
MessageDialog.openInformation(shell, getMessage(StringKeys.INFORMATION_TITLE),
|
||||
getMessage(StringKeys.INFORMATION_RULESET_EXPORTED));
|
||||
}
|
||||
|
48
pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/util/IOUtil.java
Normal file
48
pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/util/IOUtil.java
Normal file
@ -0,0 +1,48 @@
|
||||
package net.sourceforge.pmd.eclipse.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
|
||||
public class IOUtil {
|
||||
|
||||
private IOUtil() {}
|
||||
|
||||
public static void closeQuietly(OutputStream stream) {
|
||||
if (stream == null) return;
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
public static void closeQuietly(InputStream stream) {
|
||||
if (stream == null) return;
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
public static void closeQuietly(Writer writer) {
|
||||
if (writer == null) return;
|
||||
try {
|
||||
writer.close();
|
||||
} catch (IOException ex) {
|
||||
// ignore it
|
||||
}
|
||||
}
|
||||
|
||||
public static void closeQuietly(Reader reader) {
|
||||
if (reader == null) return;
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException ex) {
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user