From aaf660339c369fb678d83cd044d7d762c9bbf610 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Thu, 06 Feb 2014 17:49:07 +0000
Subject: [PATCH] OPENDJ-1307 Migrate server ASN1 classes to SDK

---
 opendj-grizzly/src/main/java/org/forgerock/opendj/grizzly/ASN1BufferWriter.java |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/opendj-grizzly/src/main/java/org/forgerock/opendj/grizzly/ASN1BufferWriter.java b/opendj-grizzly/src/main/java/org/forgerock/opendj/grizzly/ASN1BufferWriter.java
index ad57ccf..47e6edc 100644
--- a/opendj-grizzly/src/main/java/org/forgerock/opendj/grizzly/ASN1BufferWriter.java
+++ b/opendj-grizzly/src/main/java/org/forgerock/opendj/grizzly/ASN1BufferWriter.java
@@ -50,17 +50,14 @@
 final class ASN1BufferWriter extends AbstractASN1Writer implements Cacheable {
     private class ChildSequenceBuffer implements SequenceBuffer {
         private SequenceBuffer parent;
-
         private ChildSequenceBuffer child;
-
         private final ByteStringBuilder buffer = new ByteStringBuilder(BUFFER_INIT_SIZE);
 
         public SequenceBuffer endSequence() throws IOException {
             writeLength(parent, buffer.length());
             parent.writeByteArray(buffer.getBackingArray(), 0, buffer.length());
-
+            buffer.clearAndTruncate(DEFAULT_MAX_INTERNAL_BUFFER_SIZE, BUFFER_INIT_SIZE);
             logger.trace("WRITE ASN.1 END SEQUENCE(length=%d)", buffer.length());
-
             return parent;
         }
 
@@ -69,10 +66,8 @@
                 child = new ChildSequenceBuffer();
                 child.parent = this;
             }
-
             buffer.append(type);
             child.buffer.clear();
-
             return child;
         }
 
@@ -130,11 +125,9 @@
                 child = new ChildSequenceBuffer();
                 child.parent = this;
             }
-
             outBuffer.ensureAdditionalCapacity(1);
             outBuffer.put(type);
             child.buffer.clear();
-
             return child;
         }
 
@@ -162,9 +155,17 @@
 
     private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
 
+    /**
+     * Initial size of newly created buffers.
+     */
     private static final int BUFFER_INIT_SIZE = 1024;
 
     /**
+     * Default maximum size for cached protocol/entry encoding buffers.
+     */
+    private static final int DEFAULT_MAX_INTERNAL_BUFFER_SIZE = 32 * 1024;
+
+    /**
      * Reset the writer.
      */
     void reset() {
@@ -177,7 +178,6 @@
 
     private SequenceBuffer sequenceBuffer;
     private RecyclableBuffer outBuffer;
-
     private final RootSequenceBuffer rootBuffer;
 
     /**

--
Gitblit v1.10.0