From 5d8dba35b0c44d205b5448747ed0a7f8f86ce563 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 03 May 2016 08:40:47 +0000
Subject: [PATCH] code cleanup

---
 opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/ReplLDIFOutputStream.java |   82 +++++++++++++++++-----------------------
 1 files changed, 35 insertions(+), 47 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/ReplLDIFOutputStream.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/ReplLDIFOutputStream.java
index 213a977..6fea346 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/ReplLDIFOutputStream.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/ReplLDIFOutputStream.java
@@ -30,14 +30,14 @@
        extends OutputStream
 {
   /** The number of entries to be exported. */
-  long numEntries;
+  private final long numEntries;
 
   /** The current number of entries exported. */
   private long numExportedEntries;
-  String entryBuffer = "";
+  private String entryBuffer = "";
 
   /** The checksum for computing the generation id. */
-  private GenerationIdChecksum checkSum = new GenerationIdChecksum();
+  private final GenerationIdChecksum checkSum = new GenerationIdChecksum();
 
   /**
    * Creates a new ReplLDIFOutputStream related to a replication
@@ -68,61 +68,49 @@
   @Override
   public void write(byte b[], int off, int len) throws IOException
   {
-    int endOfEntryIndex;
-    int endIndex;
-
-    String ebytes = "";
-    ebytes = ebytes.concat(entryBuffer);
+    String ebytes = entryBuffer;
     entryBuffer = "";
 
-    ebytes = ebytes.concat(new String(b, off, len));
-    endIndex = ebytes.length();
+    ebytes = ebytes + new String(b, off, len);
+    int endIndex = ebytes.length();
 
     while (true)
     {
       // if we have the bytes for an entry, let's make an entry and send it
-      endOfEntryIndex = ebytes.indexOf(ServerConstants.EOL +
-          ServerConstants.EOL);
-
-      if ( endOfEntryIndex >= 0 )
-      {
-        endOfEntryIndex += 2;
-        entryBuffer = ebytes.substring(0, endOfEntryIndex);
-
-        // Send the entry
-        if (numEntries>0 && getNumExportedEntries() > numEntries)
-        {
-          // This outputstream has reached the total number
-          // of entries to export.
-          throw new IOException();
-        }
-
-        // Add the entry bytes to the checksum
-        byte[] entryBytes = entryBuffer.getBytes();
-        checkSum.update(entryBytes, 0, entryBytes.length);
-
-        numExportedEntries++;
-        entryBuffer = "";
-
-        if (endIndex == endOfEntryIndex)
-        {
-          // no more data to process
-          break;
-        }
-        else
-        {
-          // loop to the data of the next entry
-          ebytes = ebytes.substring(endOfEntryIndex,
-                                    endIndex);
-          endIndex = ebytes.length();
-        }
-      }
-      else
+      int endOfEntryIndex = ebytes.indexOf(ServerConstants.EOL + ServerConstants.EOL);
+      if (endOfEntryIndex < 0)
       {
         // a next call to us will provide more bytes to make an entry
         entryBuffer = entryBuffer.concat(ebytes);
         break;
       }
+
+      endOfEntryIndex += 2;
+      entryBuffer = ebytes.substring(0, endOfEntryIndex);
+
+      // Send the entry
+      if (numEntries > 0 && getNumExportedEntries() > numEntries)
+      {
+        // This outputstream has reached the total number
+        // of entries to export.
+        throw new IOException();
+      }
+
+      // Add the entry bytes to the checksum
+      byte[] entryBytes = entryBuffer.getBytes();
+      checkSum.update(entryBytes, 0, entryBytes.length);
+
+      numExportedEntries++;
+      entryBuffer = "";
+
+      if (endIndex == endOfEntryIndex)
+      {
+        // no more data to process
+        break;
+      }
+      // loop to the data of the next entry
+      ebytes = ebytes.substring(endOfEntryIndex, endIndex);
+      endIndex = ebytes.length();
     }
   }
 

--
Gitblit v1.10.0