summaryrefslogtreecommitdiff
path: root/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/group/FileGroupDatabase.java
diff options
context:
space:
mode:
Diffstat (limited to 'qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/group/FileGroupDatabase.java')
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/group/FileGroupDatabase.java26
1 files changed, 14 insertions, 12 deletions
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 0a02ce38fc..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,6 +34,8 @@ import java.util.concurrent.ConcurrentSkipListSet;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
+import org.apache.qpid.server.util.BaseAction;
+import org.apache.qpid.server.util.FileHelper;
import org.apache.qpid.server.util.ServerScopedRuntimeException;
/**
@@ -232,9 +234,9 @@ public class FileGroupDatabase implements GroupDatabase
}
}
- private synchronized void writeGroupFile(String groupFile) throws IOException
+ private synchronized void writeGroupFile(final String groupFile) throws IOException
{
- Properties propertiesFile = new Properties();
+ final Properties propertiesFile = new Properties();
for (String group : _groupToUserMap.keySet())
{
@@ -244,19 +246,19 @@ public class FileGroupDatabase implements GroupDatabase
propertiesFile.setProperty(group + ".users", userList);
}
- String comment = "Written " + new Date();
- FileOutputStream fileOutputStream = new FileOutputStream(groupFile);
- try
- {
- propertiesFile.store(fileOutputStream, comment);
- }
- finally
+
+ new FileHelper().writeFileSafely(new File(groupFile).toPath(), new BaseAction<File, IOException>()
{
- if(fileOutputStream != null)
+ @Override
+ public void performAction(File file) throws IOException
{
- fileOutputStream.close();
+ String comment = "Written " + new Date();
+ try(FileOutputStream fileOutputStream = new FileOutputStream(file))
+ {
+ propertiesFile.store(fileOutputStream, comment);
+ }
}
- }
+ });
}
private void validatePropertyNameIsGroupName(String propertyName)