From 22094368c2865dcfb6daf8366425212b721a4657 Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Thu, 05 Feb 2009 17:42:14 +0000
Subject: [PATCH] Merge ASN1 branch to trunk

---
 opends/src/server/org/opends/server/backends/jeb/SortValuesSet.java |   49 +++++++++++++++++--------------------------------
 1 files changed, 17 insertions(+), 32 deletions(-)

diff --git a/opends/src/server/org/opends/server/backends/jeb/SortValuesSet.java b/opends/src/server/org/opends/server/backends/jeb/SortValuesSet.java
index 98beeff..e3ec15a 100644
--- a/opends/src/server/org/opends/server/backends/jeb/SortValuesSet.java
+++ b/opends/src/server/org/opends/server/backends/jeb/SortValuesSet.java
@@ -27,15 +27,11 @@
 package org.opends.server.backends.jeb;
 
 import org.opends.server.types.*;
-import org.opends.server.protocols.asn1.ASN1OctetString;
-import org.opends.server.protocols.asn1.ASN1Element;
-
-import java.util.LinkedList;
 
 import com.sleepycat.je.DatabaseException;
 
 /**
- * This class representsa  partial sorted set of sorted entries in a VLV
+ * This class represents a partial sorted set of sorted entries in a VLV
  * index.
  */
 public class SortValuesSet
@@ -469,35 +465,23 @@
   private byte[] attributeValuesToDatabase(AttributeValue[] values)
       throws DirectoryException
   {
-    int totalValueBytes = 0;
-    LinkedList<byte[]> valueBytes = new LinkedList<byte[]>();
+    ByteStringBuilder builder = new ByteStringBuilder();
+
     for (AttributeValue v : values)
     {
-      byte[] vBytes;
       if(v == null)
       {
-        vBytes = new byte[0];
+        builder.appendBERLength(0);
       }
       else
       {
-        vBytes = v.getNormalizedValueBytes();
+        builder.appendBERLength(v.getNormalizedValue().length());
+        builder.append(v.getNormalizedValue());
       }
-      byte[] vLength = ASN1Element.encodeLength(vBytes.length);
-      valueBytes.add(vLength);
-      valueBytes.add(vBytes);
-      totalValueBytes += vLength.length + vBytes.length;
     }
+    builder.trimToSize();
 
-    byte[] attrBytes = new byte[totalValueBytes];
-
-    int pos = 0;
-    for (byte[] b : valueBytes)
-    {
-      System.arraycopy(b, 0, attrBytes, pos, b.length);
-      pos += b.length;
-    }
-
-    return attrBytes;
+    return builder.getBackingArray();
   }
 
   /**
@@ -570,8 +554,9 @@
          i < entryIDs.length * numValues;
          i++, j++)
     {
-      values[j] = new AttributeValue(sortKeys[j].getAttributeType(),
-                                     new ASN1OctetString(getValue(i)));
+      values[j] = AttributeValues.create(
+          sortKeys[j].getAttributeType(),
+          getValue(i));
     }
 
     return new SortValues(id, values, vlvIndex.sortOrder);
@@ -603,12 +588,12 @@
          i < (index + 1) * numValues;
          i++, j++)
     {
-      byte[] value = getValue(i);
+      ByteString value = getValue(i);
 
       if(value != null)
       {
-        values[j] = new AttributeValue(sortKeys[j].getAttributeType(),
-                                       new ASN1OctetString(value));
+        values[j] = AttributeValues.create(
+            sortKeys[j].getAttributeType(), value);
       }
     }
 
@@ -653,7 +638,7 @@
    * @throws DirectoryException If a Directory Server error occurs.
    * @throws DatabaseException If an error occurs in the JE database.
    */
-  public byte[] getValue(int index)
+  public ByteString getValue(int index)
       throws DatabaseException, DirectoryException
   {
     if(valuesBytesOffsets == null)
@@ -689,7 +674,7 @@
         {
           byte[] valueBytes = new byte[valueLength];
           System.arraycopy(valuesBytes, vBytesPos, valueBytes, 0, valueLength);
-          return valueBytes;
+          return ByteString.wrap(valueBytes);
         }
       }
       else
@@ -697,6 +682,6 @@
         vBytesPos += valueLength;
       }
     }
-    return new byte[0];
+    return ByteString.wrap(new byte[0]);
   }
 }

--
Gitblit v1.10.0