From a8a50d12008ef3b1471e4967125d36888c5cbdee Mon Sep 17 00:00:00 2001
From: pgamba <pgamba@localhost>
Date: Fri, 02 Nov 2007 14:13:02 +0000
Subject: [PATCH] Fix 2321 - Fixes specially ReplLDIFInputStream and ReplLDIFOutput stream regarding different cases of entry sizes and buffer sizes
---
opendj-sdk/opends/src/server/org/opends/server/replication/plugin/ReplLDIFOutputStream.java | 41 +++++++++++++++++++++++++++++++----------
1 files changed, 31 insertions(+), 10 deletions(-)
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/ReplLDIFOutputStream.java b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/ReplLDIFOutputStream.java
index af5f16e..5d48ea1 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/ReplLDIFOutputStream.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/ReplLDIFOutputStream.java
@@ -26,9 +26,12 @@
*/
package org.opends.server.replication.plugin;
+import static org.opends.server.loggers.debug.DebugLogger.getTracer;
+
import java.io.IOException;
import java.io.OutputStream;
+import org.opends.server.loggers.debug.DebugTracer;
import org.opends.server.util.ServerConstants;
/**
@@ -38,6 +41,11 @@
public class ReplLDIFOutputStream
extends OutputStream
{
+ /**
+ * The tracer object for the debug logger.
+ */
+ private static final DebugTracer TRACER = getTracer();
+
// The synchronization domain on which the export is done
ReplicationDomain domain;
@@ -75,21 +83,25 @@
public void write(byte b[], int off, int len) throws IOException
{
int endOfEntryIndex;
- int startOfEntryIndex = off;
- int bytesToRead = len;
+ int endIndex;
+
+ String ebytes = "";
+ ebytes = ebytes.concat(entryBuffer);
+ entryBuffer = "";
+
+ ebytes = ebytes.concat(new String(b, off, len));
+ endIndex = ebytes.length();
while (true)
{
// if we have the bytes for an entry, let's make an entry and send it
- String ebytes = new String(b,startOfEntryIndex,bytesToRead);
endOfEntryIndex = ebytes.indexOf(ServerConstants.EOL +
ServerConstants.EOL);
if ( endOfEntryIndex >= 0 )
{
-
endOfEntryIndex += 2;
- entryBuffer = entryBuffer + ebytes.substring(0, endOfEntryIndex);
+ entryBuffer = ebytes.substring(0, endOfEntryIndex);
// Send the entry
if ((numEntries>0) && (getNumExportedEntries() > numEntries))
@@ -100,16 +112,25 @@
}
domain.exportLDIFEntry(entryBuffer);
numExportedEntries++;
-
- startOfEntryIndex = startOfEntryIndex + endOfEntryIndex;
entryBuffer = "";
- bytesToRead -= endOfEntryIndex;
- if (bytesToRead==0)
+
+ 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
{
- entryBuffer = new String(b, startOfEntryIndex, bytesToRead);
+ // a next call to us will provide more bytes to make an entry
+ entryBuffer = entryBuffer.concat(ebytes);
break;
}
}
--
Gitblit v1.10.0