directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject [directory-ldap-api] 02/03: o Some fix for Asn1Buffer o Added a MessageFactory for encoding o Added some method for the new encoding method
Date Sat, 17 Nov 2018 18:43:42 GMT
This is an automated email from the ASF dual-hosted git repository.

elecharny pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git

commit 7c7f2ec27cfd6143f8e931e5dbebf78b0c944392
Author: elecharny <elecharny@pierreanaudsmbp>
AuthorDate: Sat Nov 17 18:56:25 2018 +0100

    o Some fix for Asn1Buffer
    o Added a MessageFactory for encoding
    o Added some method for the new encoding method
---
 .../apache/directory/api/asn1/util/Asn1Buffer.java |   9 +-
 .../directory/api/asn1/util/Asn1BufferTest.java    |  16 ++-
 .../directory/api/asn1/ber/tlv/BerValue.java       | 157 +++++++++++++++++----
 .../directory/api/ldap/codec/api/LdapEncoder.java  |  58 ++++++--
 .../api/ldap/codec/factory/BindRequestFactory.java | 107 ++++++++++++++
 .../api/ldap/codec/factory/Messagefactory.java     |  40 ++++++
 .../api/ldap/codec/bind/BindRequestPerfTest.java   |  53 +++++--
 7 files changed, 373 insertions(+), 67 deletions(-)

diff --git a/asn1/api/src/main/java/org/apache/directory/api/asn1/util/Asn1Buffer.java b/asn1/api/src/main/java/org/apache/directory/api/asn1/util/Asn1Buffer.java
index 833424e..75c207c 100644
--- a/asn1/api/src/main/java/org/apache/directory/api/asn1/util/Asn1Buffer.java
+++ b/asn1/api/src/main/java/org/apache/directory/api/asn1/util/Asn1Buffer.java
@@ -20,6 +20,8 @@
 
 package org.apache.directory.api.asn1.util;
 
+import java.nio.ByteBuffer;
+
 /**
  * A buffer used to store an encoding PDU. It's auto-extended, and
  * filled by the end.
@@ -107,11 +109,12 @@ public class Asn1Buffer
     /**
      * @return The stored encoded PDU.
      */
-    public byte[] getBytes()
+    public ByteBuffer getBytes()
     {
-        byte[] result = new byte[pos];
+        ByteBuffer result = ByteBuffer.allocate( pos );
 
-        System.arraycopy( buffer, buffer.length - pos, result, 0, pos );
+        result.put( buffer, buffer.length - pos, pos );
+        result.flip();
 
         return result;
     }
diff --git a/asn1/api/src/test/java/org/apache/directory/api/asn1/util/Asn1BufferTest.java
b/asn1/api/src/test/java/org/apache/directory/api/asn1/util/Asn1BufferTest.java
index 4a8ee2a..47eebd9 100644
--- a/asn1/api/src/test/java/org/apache/directory/api/asn1/util/Asn1BufferTest.java
+++ b/asn1/api/src/test/java/org/apache/directory/api/asn1/util/Asn1BufferTest.java
@@ -21,6 +21,8 @@ package org.apache.directory.api.asn1.util;
 
 import static org.junit.Assert.assertEquals;
 
+import java.nio.ByteBuffer;
+
 import org.junit.Ignore;
 import org.junit.Test;
 
@@ -42,12 +44,12 @@ public class Asn1BufferTest
         }
 
         assertEquals( 1024, buffer.getPos() );
-        byte[] result = buffer.getBytes();
+        ByteBuffer result = buffer.getBytes();
 
         for ( int i = 0; i < 512; i++ )
         {
-            assertEquals( 0x01, result[i + i] );
-            assertEquals( ( byte ) ( 511 - i ), result[ i + i + 1] );
+            assertEquals( 0x01, result.get( i + i ) );
+            assertEquals( ( byte ) ( 511 - i ), result.get( i + i + 1 ) );
         }
     }
 
@@ -63,11 +65,11 @@ public class Asn1BufferTest
         }
 
         assertEquals( 1024, buffer.getPos() );
-        byte[] result = buffer.getBytes();
+        ByteBuffer result = buffer.getBytes();
 
         for ( int i = 0; i < 1024; i++ )
         {
-            assertEquals( ( byte ) ( 1023 - i ), result[i] );
+            assertEquals( ( byte ) ( 1023 - i ), result.get( i ) );
         }
     }
 
@@ -84,11 +86,11 @@ public class Asn1BufferTest
 
         assertEquals( 1025, buffer.getPos() );
         assertEquals( 2048, buffer.getSize() );
-        byte[] result = buffer.getBytes();
+        ByteBuffer result = buffer.getBytes();
 
         for ( int i = 0; i < 1025; i++ )
         {
-            assertEquals( ( byte ) ( 1024 - i ), result[i] );
+            assertEquals( ( byte ) ( 1024 - i ), result.get( i ) );
         }
     }
 
diff --git a/asn1/ber/src/main/java/org/apache/directory/api/asn1/ber/tlv/BerValue.java b/asn1/ber/src/main/java/org/apache/directory/api/asn1/ber/tlv/BerValue.java
index 72ebbe4..814cd5e 100644
--- a/asn1/ber/src/main/java/org/apache/directory/api/asn1/ber/tlv/BerValue.java
+++ b/asn1/ber/src/main/java/org/apache/directory/api/asn1/ber/tlv/BerValue.java
@@ -29,6 +29,7 @@ import org.apache.directory.api.asn1.util.Asn1StringUtils;
 import org.apache.directory.api.asn1.util.BitString;
 import org.apache.directory.api.asn1.util.Oid;
 import org.apache.directory.api.i18n.I18n;
+import org.apache.directory.api.util.Strings;
 
 
 /**
@@ -624,6 +625,133 @@ public class BerValue
 
 
     /**
+     * Encode an integer value
+     *
+     * @param buffer The PDU in which the value will be put
+     * @param value The integer to be encoded
+     */
+    public static void encodeInteger( Asn1Buffer buffer, int value )
+    {
+        buffer.put( getBytes( value ) );
+        buffer.put( ( byte ) getNbBytes( value ) );
+        buffer.put( UniversalTag.INTEGER.getValue() );
+    }
+
+
+    /**
+     * Encode an integer value, with a specific tag
+     *
+     * @param buffer The PDU in which the value will be put
+     * @param tag The tag to use
+     * @param value The integer to be encoded
+     */
+    public static void encodeInteger( Asn1Buffer buffer, byte tag, int value )
+    {
+        buffer.put( getBytes( value ) );
+        buffer.put( ( byte ) getNbBytes( value ) );
+        buffer.put( tag );
+    }
+
+
+    /**
+     * Encode an OctetString
+     *
+     * @param buffer The PDU in which the value will be put
+     * @param value The integer to be encoded
+     */
+    public static void encodeOctetString( Asn1Buffer buffer, byte[] data )
+    {
+        if ( Strings.isEmpty( data ) )
+        {
+            buffer.put( ( byte ) 0 );
+        }
+        else
+        {
+            buffer.put( data );
+            buffer.put( TLV.getBytes( data.length ) );
+        }
+
+        buffer.put( UniversalTag.OCTET_STRING.getValue() );
+    }
+
+
+    /**
+     * Encode an OctetString
+     *
+     * @param buffer The PDU in which the value will be put
+     * @param tag The tag to use
+     * @param data The OctetString to be encoded
+     */
+    public static void encodeOctetString( Asn1Buffer buffer, byte tag, byte[] data )
+    {
+        if ( Strings.isEmpty( data ) )
+        {
+            buffer.put( ( byte ) 0 );
+        }
+        else
+        {
+            buffer.put( data );
+            buffer.put( TLV.getBytes( data.length ) );
+        }
+
+        buffer.put( tag );
+    }
+
+
+    /**
+     * Encode a Sequence
+     *
+     * @param buffer The PDU in which the value will be put
+     * @param value The integer to be encoded
+     */
+    public static void encodeSequence( Asn1Buffer buffer )
+    {
+        buffer.put( TLV.getBytes( buffer.getPos() ) );
+        buffer.put( UniversalTag.SEQUENCE.getValue() );
+    }
+
+
+    /**
+     * Encode a Sequence, with a specific length
+     *
+     * @param buffer The PDU in which the value will be put
+     * @param start The Sequence length
+     */
+    public static void encodeSequence( Asn1Buffer buffer, int start )
+    {
+        buffer.put( TLV.getBytes( buffer.getPos() - start ) );
+        buffer.put( UniversalTag.SEQUENCE.getValue() );
+    }
+
+
+    /**
+     * Encode a Sequence, with a specific tag
+     *
+     * @param buffer The PDU in which the value will be put
+     * @param tag The tag to use
+     */
+    public static void encodeSequence( Asn1Buffer buffer, byte tag )
+    {
+        buffer.put( TLV.getBytes( buffer.getPos() ) );
+        buffer.put( tag );
+    }
+
+
+    /**
+     * Encode a Sequence, with a specific length and tag
+     *
+     * @param buffer The PDU in which the value will be put
+     * @param tag The tag to use
+     * @param start The position in the buffer this Sequence starts
+     */
+    public static void encodeSequence( Asn1Buffer buffer, byte tag, int start )
+    {
+        buffer.put( TLV.getBytes( buffer.getPos() - start ) );
+        buffer.put( tag );
+    }
+
+
+    /**
      * Encode a String value
      *
      * @param buffer The PDU in which the value will be put
@@ -789,35 +917,6 @@ public class BerValue
 
 
     /**
-     * Encode an integer value
-     *
-     * @param buffer The PDU in which the value will be put
-     * @param value The integer to be encoded
-     */
-    public static void encodeInteger( Asn1Buffer buffer, int value )
-    {
-        buffer.put( getBytes( value ) );
-        buffer.put( ( byte ) getNbBytes( value ) );
-        buffer.put( UniversalTag.INTEGER.getValue() );
-    }
-
-
-    /**
-     * Encode an integer value, with a specific tag
-     *
-     * @param buffer The PDU in which the value will be put
-     * @param tag The tag to use
-     * @param value The integer to be encoded
-     */
-    public static void encodeInteger( Asn1Buffer buffer, byte tag, int value )
-    {
-        buffer.put( getBytes( value ) );
-        buffer.put( ( byte ) getNbBytes( value ) );
-        buffer.put( tag );
-    }
-
-
-    /**
      * Encode a long value
      *
      * @param buffer The PDU in which the value will be put
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapEncoder.java
b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapEncoder.java
index d2807c0..bb78301 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapEncoder.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapEncoder.java
@@ -31,6 +31,7 @@ import org.apache.directory.api.asn1.ber.tlv.TLV;
 import org.apache.directory.api.asn1.ber.tlv.UniversalTag;
 import org.apache.directory.api.asn1.util.Asn1Buffer;
 import org.apache.directory.api.i18n.I18n;
+import org.apache.directory.api.ldap.codec.factory.BindRequestFactory;
 import org.apache.directory.api.ldap.model.message.Control;
 import org.apache.directory.api.ldap.model.message.Message;
 import org.apache.directory.api.ldap.model.message.Referral;
@@ -52,7 +53,6 @@ public final class LdapEncoder
         // Nothing to do
     }
 
-
     /**
      * Compute the control's encoded length
      *
@@ -134,9 +134,48 @@ public final class LdapEncoder
      * @param codec The LdapApiService instance
      * @param controls The control to encode
      */
-    public static void encodeControlsReverse( Asn1Buffer buffer, LdapApiService codec, Map<String,
Control> controls )
+    private static void encodeControlsReverse( Asn1Buffer buffer, LdapApiService codec, Map<String,
Control> controls )
+    {
+        // Encode each control
+        /*for ( Control control : controls.values() )
+        {
+            encodeControlReverse( buffer, control );
+
+            // The OctetString tag if the value is not null
+            int controlValueLength = ( ( CodecControl<?> ) control ).computeLength();
+
+            if ( controlValueLength > 0 )
+            {
+                buffer.put( UniversalTag.OCTET_STRING.getValue() );
+                buffer.put( TLV.getBytes( controlValueLength ) );
+
+                // And now, the value
+                ( ( org.apache.directory.api.ldap.codec.api.CodecControl<?> ) control
).encode( buffer );
+            }
+        }
+        */
+
+        BerValue.encodeSequence( buffer, ( byte ) LdapCodecConstants.CONTROLS_TAG );
+    }
+
+
+    /**
+     * Encode the protocolOp part of a message
+     *
+     * @param buffer The buffer that will contain the encoded control
+     * @param codec The LdapApiService instance
+     * @param message The message to encode
+     */
+    private static void encodeProtocolOp( Asn1Buffer buffer, LdapApiService codec, Message
message )
     {
+        switch ( message.getClass().getName() )
+        {
+            case "BindRequestImpl" :
+                BindRequestFactory.INSTANCE.encodeReverse( buffer, message );
 
+                default:
+                    // Nothing to do
+        }
     }
 
 
@@ -165,10 +204,8 @@ public final class LdapEncoder
      * @return A ByteBuffer that contains the PDU
      * @throws EncoderException If anything goes wrong.
      */
-    public static ByteBuffer encodeMessageReverse( LdapApiService codec, Message message
) throws EncoderException
+    public static ByteBuffer encodeMessageReverse( Asn1Buffer buffer, LdapApiService codec,
Message message ) throws EncoderException
     {
-        Asn1Buffer buffer = new Asn1Buffer();
-
         // The controls, if any
         Map<String, Control> controls = message.getControls();
 
@@ -177,21 +214,16 @@ public final class LdapEncoder
             encodeControlsReverse( buffer, codec, message.getControls() );
         }
 
-
         // The protocolOp part
+        encodeProtocolOp( buffer, codec, message );
 
         // The message Id
         BerValue.encodeInteger( buffer, message.getMessageId() );
 
         // The LdapMessage Sequence
-        // BerValue.encodeSequence( buffer );
-
-        byte[] result = buffer.getBytes();
-        ByteBuffer bb = ByteBuffer.allocate( result.length );
-        bb.put( result );
-        bb.flip();
+        BerValue.encodeSequence( buffer );
 
-        return bb;
+        return buffer.getBytes();
     }
 
 
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/BindRequestFactory.java
b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/BindRequestFactory.java
new file mode 100644
index 0000000..de6763a
--- /dev/null
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/BindRequestFactory.java
@@ -0,0 +1,107 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.directory.api.ldap.codec.factory;
+
+import org.apache.directory.api.asn1.ber.tlv.BerValue;
+import org.apache.directory.api.asn1.util.Asn1Buffer;
+import org.apache.directory.api.ldap.codec.api.LdapCodecConstants;
+import org.apache.directory.api.ldap.model.message.BindRequest;
+import org.apache.directory.api.ldap.model.message.Message;
+import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.api.util.Strings;
+
+/**
+ * The BindRequest factory.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+
+public final class BindRequestFactory implements Messagefactory
+{
+    public static final BindRequestFactory INSTANCE = new BindRequestFactory();
+
+    private BindRequestFactory()
+    {
+        // Nothing to do
+    }
+
+    /**
+     * Encode the BindRequest message to a PDU.
+     * <br>
+     * BindRequest :
+     * <pre>
+     * 0x60 LL
+     *   0x02 LL version         0x80 LL simple
+     *   0x04 LL name           /
+     *   authentication.encode()
+     *                          \ 0x83 LL 0x04 LL mechanism [0x04 LL credential]
+     * </pre>
+     *
+     * @param buffer The buffer where to put the PDU
+     * @param message the BindRequest to encode
+     */
+    @Override
+    public void encodeReverse( Asn1Buffer buffer, Message message )
+    {
+        BindRequest bindMessage = ( BindRequest ) message;
+
+        // The authentication
+        if ( bindMessage.isSimple() )
+        {
+            // Simple authentication
+            BerValue.encodeOctetString( buffer, ( byte ) LdapCodecConstants.BIND_REQUEST_SIMPLE_TAG,
bindMessage.getCredentials() );
+        }
+        else
+        {
+            // SASL Bind
+            // The credentials, if any
+            if ( !Strings.isEmpty( bindMessage.getCredentials() ) )
+            {
+                BerValue.encodeOctetString( buffer, bindMessage.getCredentials() );
+            }
+
+            // The mechanism
+            BerValue.encodeOctetString( buffer, Strings.getBytesUtf8( bindMessage.getSaslMechanism()
) );
+
+            // The SASL tag
+            BerValue.encodeSequence( buffer, ( byte ) LdapCodecConstants.BIND_REQUEST_SASL_TAG
);
+        }
+
+        // The name
+        Dn dn = bindMessage.getDn();
+
+        if ( !Dn.isNullOrEmpty( dn ) )
+        {
+            // A DN has been provided
+            BerValue.encodeOctetString( buffer, Strings.getBytesUtf8( dn.getName() ) );
+        }
+        else
+        {
+            // No DN has been provided, let's use the name as a string instead
+            BerValue.encodeOctetString( buffer, Strings.getBytesUtf8( bindMessage.getName()
) );
+        }
+
+        // The version (LDAP V3 only)
+        BerValue.encodeInteger( buffer, 3 );
+
+        // The BindRequest Tag
+        BerValue.encodeSequence( buffer, LdapCodecConstants.BIND_REQUEST_TAG );
+    }
+}
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/Messagefactory.java
b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/Messagefactory.java
new file mode 100644
index 0000000..7aac5cd
--- /dev/null
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/Messagefactory.java
@@ -0,0 +1,40 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.directory.api.ldap.codec.factory;
+
+import org.apache.directory.api.asn1.util.Asn1Buffer;
+import org.apache.directory.api.ldap.model.message.Message;
+
+/**
+ * An interface that needs to be implemented by messages to
+ * be encoded.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface Messagefactory
+{
+    /**
+     * Encode a message, in a reverse way (ie, starting from the end of the PDU.
+     *
+     * @param buffer The buffer where to put the PDU
+     * @param message The message to encode
+     */
+    void encodeReverse( Asn1Buffer buffer, Message message );
+}
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/bind/BindRequestPerfTest.java
b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/bind/BindRequestPerfTest.java
index 69f6d12..d3a5298 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/bind/BindRequestPerfTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/bind/BindRequestPerfTest.java
@@ -30,6 +30,7 @@ import java.util.Map;
 import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
+import org.apache.directory.api.asn1.util.Asn1Buffer;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
 import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
@@ -38,7 +39,6 @@ import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
 import org.apache.directory.api.ldap.model.message.BindRequest;
 import org.apache.directory.api.ldap.model.message.BindRequestImpl;
 import org.apache.directory.api.ldap.model.message.Control;
-import org.apache.directory.api.ldap.model.message.controls.OpaqueControl;
 import org.apache.directory.api.ldap.model.name.Dn;
 import org.apache.directory.api.util.Strings;
 import org.junit.Ignore;
@@ -54,7 +54,7 @@ import com.mycila.junit.concurrent.ConcurrentJunitRunner;
  */
 @RunWith(ConcurrentJunitRunner.class)
 @Concurrency()
-@Ignore("Ignore performance tests: should not be with integration tests")
+//@Ignore("Ignore performance tests: should not be with integration tests")
 public class BindRequestPerfTest extends AbstractCodecServiceTest
 {
     /**
@@ -232,26 +232,27 @@ public class BindRequestPerfTest extends AbstractCodecServiceTest
      * controls
      */
     @Test
-    @Ignore
+    //@Ignore
     public void testEncodeBindRequestPerf() throws Exception
     {
         Dn dn = new Dn( "uid=akarasulu,dc=example,dc=com" );
-        int nbLoops = 1000000;
-        long t0 = System.currentTimeMillis();
+        int nbLoops = 100_000_000;
 
-        for ( int i = 0; i < nbLoops; i++ )
-        {
-            // Check the decoded BindRequest
-            BindRequest bindRequest = new BindRequestImpl();
-            bindRequest.setMessageId( 1 );
+        // Check the decoded BindRequest
+        BindRequest bindRequest = new BindRequestImpl();
+        bindRequest.setMessageId( 1 );
+
+        bindRequest.setSimple( true );
+        bindRequest.setDn( dn );
+        bindRequest.setCredentials( Strings.getBytesUtf8( "password" ) );
+        //Control control = new ManageDsaITImpl();
 
-            bindRequest.setSimple( true );
-            bindRequest.setDn( dn );
-            bindRequest.setCredentials( Strings.getBytesUtf8( "password" ) );
-            Control control = new OpaqueControl( "2.16.840.1.113730.3.4.2" );
+        //bindRequest.addControl( control );
 
-            bindRequest.addControl( control );
+        long t0 = System.currentTimeMillis();
 
+        for ( int i = 0; i < nbLoops; i++ )
+        {
             // Check the encoding
             try
             {
@@ -266,5 +267,27 @@ public class BindRequestPerfTest extends AbstractCodecServiceTest
 
         long t1 = System.currentTimeMillis();
         System.out.println( "BindRequest testEncodeBindRequestPerf, " + nbLoops + " loops,
Delta = " + ( t1 - t0 ) );
+
+        Asn1Buffer buffer = new Asn1Buffer();
+
+        long t2 = System.currentTimeMillis();
+
+        for ( int i = 0; i < nbLoops; i++ )
+        {
+            // Check the encoding
+            try
+            {
+                LdapEncoder.encodeMessageReverse( buffer, codec, bindRequest );
+                buffer.clear();
+            }
+            catch ( EncoderException ee )
+            {
+                ee.printStackTrace();
+                fail( ee.getMessage() );
+            }
+        }
+
+        long t3 = System.currentTimeMillis();
+        System.out.println( "BindRequest testEncodeBindRequestPerf reverse, " + nbLoops +
" loops, Delta = " + ( t3 - t2 ) );
     }
 }


Mime
View raw message