From 2dc104de03990454132bd41e3b9f4fe1a47f9ffd Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 19 Apr 2016 16:44:22 +0000
Subject: [PATCH] Converted try/finally Closeable.close() (or Utils.closeSilently()) into try-with-resources
---
opendj-config/src/main/java/org/forgerock/opendj/config/client/ldap/LDAPManagementContext.java | 31 +++++++++++--------------------
1 files changed, 11 insertions(+), 20 deletions(-)
diff --git a/opendj-config/src/main/java/org/forgerock/opendj/config/client/ldap/LDAPManagementContext.java b/opendj-config/src/main/java/org/forgerock/opendj/config/client/ldap/LDAPManagementContext.java
index a953b78..0e1f294 100644
--- a/opendj-config/src/main/java/org/forgerock/opendj/config/client/ldap/LDAPManagementContext.java
+++ b/opendj-config/src/main/java/org/forgerock/opendj/config/client/ldap/LDAPManagementContext.java
@@ -179,23 +179,19 @@
return context;
}
- private static ManagementContext newLDIFManagementContext(final File ldifFile, final LDAPProfile profile,
- final List<IOException> exceptions) throws IOException {
- final BufferedReader configReader = new BufferedReader(new FileReader(ldifFile));
- try {
+ private static ManagementContext newLDIFManagementContext(final File ldifFile, final List<IOException> exceptions)
+ throws IOException {
+ try (final FileReader fileReader = new FileReader(ldifFile);
+ final BufferedReader configReader = new BufferedReader(fileReader)) {
final MemoryBackend memoryBackend = new MemoryBackend(new LDIFEntryReader(configReader));
final Connection co = new AbstractConnectionWrapper<Connection>(newInternalConnection(memoryBackend)) {
@Override
public void close() {
- try {
- final BufferedWriter configWriter = new BufferedWriter(new FileWriter(ldifFile));
- try {
- final Iterator<Entry> entries = memoryBackend.getAll().iterator();
- entries.next(); // skip RootDSE
- LDIF.copyTo(LDIF.newEntryIteratorReader(entries), new LDIFEntryWriter(configWriter));
- } finally {
- configWriter.close();
- }
+ try (final FileWriter fileWriter = new FileWriter(ldifFile);
+ final BufferedWriter configWriter = new BufferedWriter(fileWriter)) {
+ final Iterator<Entry> entries = memoryBackend.getAll().iterator();
+ entries.next(); // skip RootDSE
+ LDIF.copyTo(LDIF.newEntryIteratorReader(entries), new LDIFEntryWriter(configWriter));
} catch (IOException e) {
if (exceptions != null) {
exceptions.add(e);
@@ -215,8 +211,6 @@
// We need to add the root dse entry to make the configuration framework work.
co.add(LDIFEntryReader.valueOfLDIFEntry("dn:", "objectClass:top", "objectClass:ds-root-dse"));
return LDAPManagementContext.newManagementContext(co, LDAPProfile.getInstance());
- } finally {
- configReader.close();
}
}
@@ -225,16 +219,13 @@
*
* @param ldifFile
* The LDIF file to manage
- * @param profile
- * The LDAP profile
* @return A LDIF file management context
* @throws IOException
* If problems occurs while reading the file.
*/
- public static ManagementContext newLDIFManagementContext(final File ldifFile, final LDAPProfile profile)
- throws IOException {
+ public static ManagementContext newLDIFManagementContext(final File ldifFile) throws IOException {
final List<IOException> exceptions = new ArrayList<>();
- return new ManagementContextWrapper(newLDIFManagementContext(ldifFile, profile, exceptions), exceptions);
+ return new ManagementContextWrapper(newLDIFManagementContext(ldifFile, exceptions), exceptions);
}
/** The LDAP management context driver. */
--
Gitblit v1.10.0