From fdd9be22de1808af9159a95ae6dd64e6573f5310 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Fri, 29 Mar 2013 14:49:41 +0000
Subject: [PATCH] Very minor code cleanup to LDIF package:

---
 opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/LDIFEntryWriter.java |   37 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/LDIFEntryWriter.java b/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/LDIFEntryWriter.java
index 60d76c8..86bf289 100644
--- a/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/LDIFEntryWriter.java
+++ b/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/LDIFEntryWriter.java
@@ -22,13 +22,15 @@
  *
  *
  *      Copyright 2009-2010 Sun Microsystems, Inc.
- *      Portions copyright 2012 ForgeRock AS.
+ *      Portions copyright 2012-2013 ForgeRock AS.
  */
 
 package org.forgerock.opendj.ldif;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.io.StringWriter;
+import java.io.Writer;
 import java.util.List;
 
 import org.forgerock.opendj.ldap.Attribute;
@@ -50,6 +52,24 @@
 public final class LDIFEntryWriter extends AbstractLDIFWriter implements EntryWriter {
 
     /**
+     * Returns the LDIF string representation of the provided entry.
+     *
+     * @param entry
+     *            The entry.
+     * @return The LDIF string representation of the provided entry.
+     */
+    public static String toString(final Entry entry) {
+        final StringWriter writer = new StringWriter(128);
+        try {
+            new LDIFEntryWriter(writer).setAddUserFriendlyComments(true).writeEntry(entry).close();
+        } catch (final IOException e) {
+            // Should never happen.
+            throw new IllegalStateException(e);
+        }
+        return writer.toString();
+    }
+
+    /**
      * Creates a new LDIF entry writer which will append lines of LDIF to the
      * provided list.
      *
@@ -72,8 +92,20 @@
     }
 
     /**
+     * Creates a new LDIF entry writer whose destination is the provided
+     * character stream writer.
+     *
+     * @param writer
+     *            The character stream writer to use.
+     */
+    public LDIFEntryWriter(final Writer writer) {
+        super(writer);
+    }
+
+    /**
      * {@inheritDoc}
      */
+    @Override
     public void close() throws IOException {
         close0();
     }
@@ -81,6 +113,7 @@
     /**
      * {@inheritDoc}
      */
+    @Override
     public void flush() throws IOException {
         flush0();
     }
@@ -235,6 +268,7 @@
     /**
      * {@inheritDoc}
      */
+    @Override
     public LDIFEntryWriter writeComment(final CharSequence comment) throws IOException {
         writeComment0(comment);
         return this;
@@ -243,6 +277,7 @@
     /**
      * {@inheritDoc}
      */
+    @Override
     public LDIFEntryWriter writeEntry(final Entry entry) throws IOException {
         Validator.ensureNotNull(entry);
 

--
Gitblit v1.10.0