diff options
author | Keith Wall <kwall@apache.org> | 2015-02-22 19:11:13 +0000 |
---|---|---|
committer | Keith Wall <kwall@apache.org> | 2015-02-22 19:11:13 +0000 |
commit | 234eda18a504639c270a36d5cd631ba88ce10ff7 (patch) | |
tree | 4c759dc1f147a14bb484f724a3e6d1ff09982158 | |
parent | bb5263996f655225de56d0af467de2b166865634 (diff) | |
download | qpid-python-234eda18a504639c270a36d5cd631ba88ce10ff7.tar.gz |
QPID-6247: [Java Broker] Use try-with-resources to avoid some repeated cleanup code
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1661530 13f79535-47bb-0310-9956-ffa450edef68
4 files changed, 5 insertions, 37 deletions
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/FileSystemPreferencesProviderImpl.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/FileSystemPreferencesProviderImpl.java index a69589c58a..7046f2973e 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/FileSystemPreferencesProviderImpl.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/FileSystemPreferencesProviderImpl.java @@ -39,7 +39,6 @@ import java.util.TreeMap; import org.apache.log4j.Logger; import org.apache.qpid.server.configuration.BrokerProperties; -import org.apache.qpid.server.store.StoreException; import org.apache.qpid.server.util.BaseAction; import org.apache.qpid.server.util.FileHelper; import org.codehaus.jackson.JsonParser; diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/database/AbstractPasswordFilePrincipalDatabase.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/database/AbstractPasswordFilePrincipalDatabase.java index 2f4f48076e..2c692ddf4d 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/database/AbstractPasswordFilePrincipalDatabase.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/database/AbstractPasswordFilePrincipalDatabase.java @@ -249,13 +249,9 @@ public abstract class AbstractPasswordFilePrincipalDatabase<U extends PasswordPr private void writeToFile(File tmp) throws IOException { - BufferedReader reader = null; - PrintStream writer = null; - - try + try(PrintStream writer = new PrintStream(tmp); + BufferedReader reader = new BufferedReader(new FileReader(_passwordFile))) { - writer = new PrintStream(tmp); - reader = new BufferedReader(new FileReader(_passwordFile)); String line; while ((line = reader.readLine()) != null) @@ -313,25 +309,6 @@ public abstract class AbstractPasswordFilePrincipalDatabase<U extends PasswordPr getLogger().error("Unable to create the new password file: " + e); throw new IOException("Unable to create the new password file",e); } - finally - { - - try - { - if (reader != null) - { - reader.close(); - } - } - finally - { - if (writer != null) - { - writer.close(); - } - } - - } } protected abstract U createUserFromPassword(Principal principal, char[] passwd); diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/group/FileGroupDatabase.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/group/FileGroupDatabase.java index e6565eee60..1e9e646e35 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/group/FileGroupDatabase.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/group/FileGroupDatabase.java @@ -34,7 +34,6 @@ import java.util.concurrent.ConcurrentSkipListSet; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; -import org.apache.qpid.server.util.Action; import org.apache.qpid.server.util.BaseAction; import org.apache.qpid.server.util.FileHelper; import org.apache.qpid.server.util.ServerScopedRuntimeException; @@ -254,18 +253,10 @@ public class FileGroupDatabase implements GroupDatabase public void performAction(File file) throws IOException { String comment = "Written " + new Date(); - FileOutputStream fileOutputStream = new FileOutputStream(file); - try + try(FileOutputStream fileOutputStream = new FileOutputStream(file)) { propertiesFile.store(fileOutputStream, comment); } - finally - { - if(fileOutputStream != null) - { - fileOutputStream.close(); - } - } } }); } diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/util/FileHelper.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/util/FileHelper.java index b585af3f85..0e1a28f220 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/util/FileHelper.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/util/FileHelper.java @@ -125,7 +125,8 @@ public class FileHelper } else { - throw new RuntimeException("Atomic move is unsupported and rename failed"); + throw new RuntimeException("Atomic move is unsupported and rename from : '" + + sourceFile + "' to: '" + targetFile + "' failed."); } } } |