directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 9766 - in incubator/directory/snickers/trunk: ber ber/src/java/org/apache/snickers/asn ber/src/java/org/apache/snickers/ber ber/src/java/org/apache/snickers/ber/primitives ber/src/test/org/apache/snickers/ber codec-stateful
Date Sat, 27 Mar 2004 01:29:49 GMT
Author: akarasulu
Date: Fri Mar 26 17:29:48 2004
New Revision: 9766

Added:
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/primitives/
      - copied from rev 9765, incubator/directory/snickers/branches/chunking/ber/src/java/org/apache/snickers/ber/primitives/
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/primitives/BERDecoderUtils.java   (props changed)
      - copied unchanged from rev 9765, incubator/directory/snickers/branches/chunking/ber/src/java/org/apache/snickers/ber/primitives/BERDecoderUtils.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/primitives/Primitive.java   (props changed)
      - copied unchanged from rev 9765, incubator/directory/snickers/branches/chunking/ber/src/java/org/apache/snickers/ber/primitives/Primitive.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/primitives/PrimitiveType.java
      - copied unchanged from rev 9765, incubator/directory/snickers/branches/chunking/ber/src/java/org/apache/snickers/ber/primitives/PrimitiveType.java
Removed:
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/asn/
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/AbstractBufferedDecoderTestCase.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/AbstractChunkingBERDecoderTestCase.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERBufferedDecoder.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/ChunkingBERDecoder.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/ChunkingTuple.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/IntStack.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleTreeAnalyzer.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/BERBufferedDecoderTest.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/IntStackTest.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/ObjectVersePrimitiveTest.java
Modified:
   incubator/directory/snickers/trunk/ber/   (props changed)
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/AbstractDecoderTestCase.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoder.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoderMonitor.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/DefaultMutableTupleNode.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/MutableTupleNode.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/Tag.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/Tuple.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleNode.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleTreeDecoder.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TypeClass.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/AbstractDecoderTestCaseTest.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/BERDecoderCallbackAdapterTest.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/BERDecoderTest.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/ConstructedTLVTests.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/DefaultMutableTupleNodeTest.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/EncodeDecodeTests.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/MultiByteTagTests.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/SimplePrimitiveTLVTests.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/SingleByteLengthTests.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/TagTest.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/TupleTest.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/TupleTreeDecoderTest.java
   incubator/directory/snickers/trunk/codec-stateful/   (props changed)
Log:
merged branch chunking changes r9749:9764 to trunk

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/AbstractDecoderTestCase.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/AbstractDecoderTestCase.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/AbstractDecoderTestCase.java	Fri Mar 26 17:29:48 2004
@@ -49,6 +49,8 @@
     protected ArrayList tlvList = new ArrayList() ;
     /** the decoder that is constructed every time */
     protected BERDecoder decoder = null ;
+    /** value accumulator */
+    ByteBuffer buf = ByteBuffer.allocate(11111) ;
     
 
     /*
@@ -57,7 +59,7 @@
     protected void setUp() throws Exception
     {
         super.setUp() ;
-        decoder = new BERDecoder( 1024 ) ;
+        decoder = new BERDecoder() ;
         decoder.setCallback( this ) ;
         decoder.setDecoderMonitor( this ) ;
     }
@@ -139,6 +141,60 @@
     
     
     /**
+     * Fragments a byte buffer into multiple buffer 'attempting' to keep 
+     * them the same size however the last fragment will be an array 
+     * bites.length%size which may or may not be of the requested fragment size.
+     * However it will never be greater.  Use this method to break appart TLV 
+     * bytes to feed them into the decoder for testing.
+     * 
+     * @param bites the bites to fragment
+     * @param size the maximum size of a fragment
+     * @return the buffer fragment
+     */
+    public ByteBuffer[] fragment( ByteBuffer bites, int size )
+    {
+        bites = bites.duplicate() ;
+        ByteBuffer[] fragments = null ;
+        
+        if ( size <= 0 )
+        {    
+            throw new IllegalArgumentException( 
+                    "fragment size should be 1 or more but was " + size ) ;
+        }
+        
+        int wholeFrags = bites.remaining()/size ;
+        int partialFragSize = bites.remaining() % size ; 
+
+        /*
+         * Allocate what we need depending on the size of our remainder
+         */
+        if ( partialFragSize == 0 ) 
+        {
+            fragments = new ByteBuffer[wholeFrags] ;
+        }
+        else
+        {
+            fragments = new ByteBuffer[wholeFrags+1] ;
+            fragments[wholeFrags] = ByteBuffer.allocate( partialFragSize ) ;
+        }
+        
+        for ( int ii = 0; ii < wholeFrags; ii++ )
+        {
+            fragments[ii] = ( ByteBuffer ) bites.slice().limit( size ) ;
+            bites.position( bites.position() + size ) ;
+        }
+        
+        if ( partialFragSize != 0 )
+        {
+            fragments[wholeFrags].put( bites ) ;
+            fragments[wholeFrags].flip() ;
+        }
+        
+        return fragments ;
+    }
+    
+    
+    /**
      * BER decodes a string of 0's and 1's.
      * 
      * @param bitString a string of ascii 0's and 1's
@@ -207,15 +263,38 @@
 
     
     /**
+     * BER decodes a byte buffer.
+     * 
+     * @param bites a byte buffer to decode
+     * @return a copy of the decoded tuple or the partially decoded current tlv
+     * @throws DecoderException if there are errors while decoding.
+     */
+    public Tuple decode( ByteBuffer bites ) throws DecoderException
+    {
+        int lastSize = tlvList.size() ;
+        decoder.decode( bites ) ;
+        
+        if ( tlvList.isEmpty() || tlvList.size() == lastSize )
+        {
+            return decoder.getCurrentTuple() ;
+        }
+        
+        return ( Tuple ) tlvList.get( tlvList.size() - 1 ) ;
+    }
+
+    
+    /**
      * First BER encodes then BER decodes a Tuple.
      * 
      * @param tlv a tuple to encode then decode
      * @return a copy of the decoded tuple or the partially decoded current tlv
      * @throws DecoderException if there are errors while decoding
      */
-    public Tuple decode( Tuple tlv ) throws DecoderException
+    public Tuple decode( Tuple tlv, ByteBuffer value ) throws DecoderException
     {
-        ByteBuffer buf = ByteBuffer.wrap( tlv.toEncodedArray() ) ;
+        ArrayList list = new ArrayList() ;
+        list.add( value ) ;
+        ByteBuffer buf = tlv.toEncodedBuffer( list ) ;
         int lastSize = tlvList.size() ;
         decoder.decode( buf ) ;
         
@@ -244,13 +323,14 @@
      * @return a copy of the decoded tuple or the partially decoded current tlv
      * @throws DecoderException if there are errors while decoding
      */
-    public Tuple decode( Tuple[] tlvs ) throws DecoderException
+    public Tuple decode( Tuple[] tlvs, ByteBuffer[] values ) 
+        throws DecoderException
     {
         int lastSize = tlvList.size() ;
 
         for ( int ii = 0; ii < tlvs.length; ii++ )
         {
-            decode( tlvs[ii] ) ;
+            decode( tlvs[ii], values[ii] ) ;
         }
         
         if ( tlvList.isEmpty() || tlvList.size() == lastSize )
@@ -303,15 +383,6 @@
         assertTrue( decoder.getCurrentTuple().equals( tlv ) ) ;
         assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
     }
-    
-    
-    /* (non-Javadoc)
-     * @see org.apache.snickers.ber.BERDecoderCallback#partialValueDecoded(
-     * org.apache.snickers.ber.Tuple)
-     */
-    public void partialValueDecoded( Tuple tlv )
-    {
-    }
 
 
     /* (non-Javadoc)
@@ -322,8 +393,19 @@
     {
         assertTrue( decoder.getCurrentTuple().equals( tlv ) ) ;
         assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
+        buf.clear() ;
     }
 
+    
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.BERDecoderCallback#partialValueDecoded(
+     * org.apache.snickers.ber.Tuple)
+     */
+    public void partialValueDecoded( Tuple tlv )
+    {
+        buf.put( tlv.valueChunk ) ;
+    }
+    
 
     /* (non-Javadoc)
      * @see org.apache.commons.codec.stateful.DecoderCallback#decodeOccurred(
@@ -334,6 +416,7 @@
         Tuple t = ( Tuple ) decoded ;
         tlvList.add( t.clone() ) ;
         assertEquals( BERDecoderState.VALUE, this.decoder.getState() ) ;
+        buf.flip() ;
     }
     
     
@@ -406,6 +489,6 @@
      */
     public void warning( StatefulDecoder decoder, Exception exception )
     {
-        fail( ExceptionUtils.getFullStackTrace( exception ) ) ;
+        assertNotNull( exception ) ;
     }
 }

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoder.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoder.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoder.java	Fri Mar 26 17:29:48 2004
@@ -31,36 +31,48 @@
 
 
 /**
- * Low level BER encoded bytes to Tag Value Length (TLV) tuple decoder.  
+ * A decoder that decodes BER encoded bytes to Tag Value Length (TLV) tuples.  
  * This decoder is a low level event based parser which operates in a fashion 
  * similar to the way SAX works except the elements of concern are the tag, 
- * length, and value entities.
+ * length, and value entities.  The decoder is a state machine which processes
+ * input as it is made available.
  * <p>
- * Instance variables and a Stack is used to track the state of the decoder 
- * between decode calls.  The stack maintains the nesting of TLV tuples.  Rather
- * than creating new TLV tuple instances every time a single tuple is reused for
- * primitive types and new tlv tuples are cloned for constructed types.  The 
- * tuple fed to the callback must therefore be used very carefully - its values
- * must be copied to prevent their loss.
+ * A Stack is used to track the state of the decoder between decode calls.  It 
+ * maintains the nesting of TLV tuples.  Rather than creating new TLV tuple 
+ * instances every time a single tuple is reused for primitive types and new 
+ * tlv tuples are cloned for constructed types which are pushed onto the stack.
+ * The tuple fed to the callback must therefore be used very carefully - its 
+ * values must be copied to prevent their loss if they are to be used later 
+ * after the callback invokation has returned.
  * </p>
  * <p>
  * Note that all tuples are not created equal.  Constructed TLVs nesting others
- * will have null value members.  Only TLV tuples of primitive types or the 
- * leaf TLV tuples of the TLV tuple tree will only contain non null values.  
- * Therefore the nature of a TLV tuple should be investigated by callbacks 
- * before attempting to interpret their values.
+ * will have null value members or empty buffers.  Only TLV tuples of primitive 
+ * types or the leaf TLV tuples of the TLV tuple tree will contain non null 
+ * values.  Therefore the nature of a TLV tuple should be investigated by 
+ * callbacks before attempting to interpret their values.  Also this decoder
+ * chunks value data returning it in parts rather than in one complete peice
+ * in the end.  The value of the TLV Tuple returned is the part of the value
+ * that was read from the input fed into the decoder.  These 'chuncks' returned
+ * by callback makes it so there are no size limits to the value of a TLV. Again
+ * to reiterate chunking on values is only performed on primitive TLV Tuple 
+ * types. 
  * </p>
  * 
- * @see Tuple for TLV tuple value size limitations
  * @author <a href="mailto:directory-dev@incubator.apache.org">
  * Apache Directory Project</a>
  * @version $Rev$
  */
 public class BERDecoder implements StatefulDecoder, DecoderCallback
 {
-    public static final BERDecoderCallback DEFAULT_CALLBACK = 
+    /** empty byte buffer to be reused */
+    private static final ByteBuffer EMPTY_BUFFER = 
+        ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ;
+    /** the callback used by this decoder */
+    private static final BERDecoderCallback DEFAULT_CALLBACK = 
         new BERDecoderCallbackAdapter() ;
-    public static final DecoderMonitor DEFAULT_MONITOR =
+    /** the monitor used by this decoder */
+    private static final DecoderMonitor DEFAULT_MONITOR =
         new DecoderMonitorAdapter() ;
     
     /** this decoder's callback */
@@ -75,8 +87,6 @@
     private final TagDecoder tagDecoder = new TagDecoder() ;
     /** a decoder used to decode length octets */ 
     private final LengthDecoder lengthDecoder = new LengthDecoder() ;
-    /** a place to store value data - this is reused */
-    private final ByteBuffer buffer ;
     
     /** stack of nested/constructed TLV tuples */
     private final Stack tlvStack = new Stack() ;
@@ -87,14 +97,11 @@
     
     /**
      * Creates a stateful BER decoder which limits the tuple's value size.
-     * 
-     * @param valueMax the maximum tuple value size handled by this decoder
      */
-    public BERDecoder( int valueMax )
+    public BERDecoder()
     {
         tagDecoder.setCallback( this ) ;
         lengthDecoder.setCallback( this ) ;
-        buffer = ByteBuffer.allocate( valueMax ) ;
     }
     
     
@@ -166,7 +173,7 @@
     {
         this.cb = ( BERDecoderCallback ) cb ;
     }
-    
+
 
     /* (non-Javadoc)
      * @see org.apache.commons.codec.stateful.StatefulDecoder#setDecoderMonitor(
@@ -188,24 +195,22 @@
      * 
      * @param buf the byte byffer containing BER encoded data 
      */
-    private void decodeValue( ByteBuffer buf ) throws DecoderException
+    private void decodeValue( ByteBuffer buf )
     {
-        byte[] value = ( byte [] ) tlv.value ;
-        int offset = Length.UNDEFINED ;
         int needToRead = Length.UNDEFINED ;
 
         /*
-         * setup to start decoding the value
+         * setup to start decoding the value by figuring how much we need to
+         * read at this point - previous reads of the value may have already
+         * occurred.
          */
         if ( tlv.valueIndex == Length.UNDEFINED )
         {
             needToRead = tlv.length ;
-            offset = 0 ;
         }
         else
         {
             needToRead = tlv.length - tlv.valueIndex ;
-            offset = tlv.valueIndex ;
         }
         
         /*
@@ -214,10 +219,12 @@
          */
         if ( buf.remaining() >= needToRead )
         {
-            buf.get( value, offset, needToRead ) ;
+            tlv.valueChunk = ( ByteBuffer ) buf.slice().limit( needToRead ) ;
+            buf.position( buf.position() + needToRead ) ;
             tlv.valueIndex = tlv.length ;
             tlv.index += tlv.length ;
             
+            cb.partialValueDecoded( tlv ) ;
             fireDecodeOccurred( tlv ) ;
             updateStack( needToRead ) ;
             tlv.clear() ;
@@ -237,10 +244,12 @@
             }
             
             int remaining = buf.remaining() ;
-            buf.get( value, offset, remaining ) ;
+            tlv.valueChunk = buf.slice() ;
+            buf.position( buf.limit() ) ;
             tlv.valueIndex += remaining ;
             tlv.index +=remaining ;
             
+            cb.partialValueDecoded( tlv ) ;
             updateStack( remaining ) ;
         }
     }
@@ -283,8 +292,6 @@
             fireLengthDecoded() ;
             updateStack( length.size() ) ;
             
-            
-            
             if ( ! tlv.isPrimitive )
             {
                 if ( tlv.isIndefinate() || tlv.length > 0 )
@@ -306,13 +313,15 @@
             }
             else if ( tlv.length > 0 )
             {
-                tlv.value = new byte[tlv.length] ;
                 state = BERDecoderState.VALUE ;
             }
             else
             {
-                tlv.value = ArrayUtils.EMPTY_BYTE_ARRAY ;
                 state = BERDecoderState.VALUE ;
+                tlv.valueChunk = EMPTY_BUFFER ;
+                cb.partialValueDecoded( tlv ) ;
+                fireDecodeOccurred( tlv ) ;
+                state = BERDecoderState.TAG ;
             }
         }
         else
@@ -341,11 +350,11 @@
         {
             cb.tagDecoded( tlv ) ;
         }
-        
+
         if ( monitor != null && monitor instanceof BERDecoderMonitor )
         {
             BERDecoderMonitor berMonitor = ( BERDecoderMonitor ) monitor ;
-            //berMonitor.tagDecoded( tlv, tagDecoder.getOctets() ) ;
+            berMonitor.tagDecoded( tlv ) ;
         }
     }
     
@@ -368,7 +377,7 @@
         if ( monitor != null && monitor instanceof BERDecoderMonitor )
         {
             BERDecoderMonitor berMonitor = ( BERDecoderMonitor ) monitor ;
-            //berMonitor.lengthDecoded( tlv, lengthBuffer.toArray() ) ;
+            berMonitor.lengthDecoded( tlv ) ;
         }
     }
     

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoderMonitor.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoderMonitor.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoderMonitor.java	Fri Mar 26 17:29:48 2004
@@ -40,9 +40,8 @@
      * </ul>
      * 
      * @param tlv the TLV tuple
-     * @param tagData the tag data collected
      */
-    void tagDecoded( Tuple tlv, byte[] tagData ) ;
+    void tagDecoded( Tuple tlv ) ;
     
     /**
      * Method used to receive notification that a length was decoded.  The 
@@ -55,7 +54,6 @@
      * </ul>
      * 
      * @param tlv the TLV tuple
-     * @param lengthData the length data collected
      */
-    void lengthDecoded( Tuple tlv, byte[] lengthData ) ;
+    void lengthDecoded( Tuple tlv ) ;
 }

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/DefaultMutableTupleNode.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/DefaultMutableTupleNode.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/DefaultMutableTupleNode.java	Fri Mar 26 17:29:48 2004
@@ -19,14 +19,11 @@
 
 import java.nio.ByteBuffer ;
 
+import java.util.List ;
 import java.util.Iterator ;
 import java.util.ArrayList ;
-import java.util.Enumeration ;
 import java.util.Collections ;
 
-import javax.swing.tree.TreeNode ;
-import javax.swing.tree.MutableTreeNode ;
-
 import org.apache.commons.lang.StringUtils ;
 
 
@@ -37,8 +34,7 @@
  * Apache Directory Project</a>
  * @version $Rev$
  */
-public class DefaultMutableTupleNode 
-    implements MutableTupleNode, MutableTreeNode
+public class DefaultMutableTupleNode implements MutableTupleNode
 {
     /** this node's tuple user object */
     private Tuple tuple ;
@@ -46,6 +42,8 @@
     private ArrayList children = new ArrayList() ;
     /** this node's parent node */
     private DefaultMutableTupleNode parent ;
+    /** this node's accumulated ByteBuffer value chunks */
+    private List valueChunks = new ArrayList( 2 ) ;
     
     
     /**
@@ -67,6 +65,18 @@
     }
     
 
+    /**
+     * Creates a node without a parent.
+     * 
+     * @param tuple the tuple to set for this node
+     */
+    public DefaultMutableTupleNode( Tuple tuple, List valueChunks )
+    {
+        this.tuple = tuple ;
+        this.valueChunks.addAll( valueChunks ) ;
+    }
+    
+
     /* (non-Javadoc)
      * @see org.apache.snickers.ber.MutableTupleNode#insert(
      * org.apache.snickers.ber.MutableTupleNode, int)
@@ -151,16 +161,6 @@
 
     
     /* (non-Javadoc)
-     * @see org.apache.snickers.ber.MutableTupleNode#setTuple(
-     * org.apache.snickers.ber.Tuple)
-     */
-    public void setTuple( Tuple t )
-    {
-        tuple = t ;
-    }
-    
-
-    /* (non-Javadoc)
      * @see org.apache.snickers.ber.TupleNode#getParent()
      */
     public TupleNode getParentTupleNode()
@@ -255,6 +255,51 @@
     }
     
     
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.MutableTupleNode#setTuple(
+     * org.apache.snickers.ber.Tuple)
+     */
+    public void setTuple( Tuple t )
+    {
+        tuple = t ;
+        valueChunks.clear() ;
+    }
+    
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.snickers.ber.MutableTupleNode#setTuple(
+     * org.apache.snickers.ber.Tuple, java.util.List)
+     */
+    public void setTuple( Tuple t, List valueChunks )
+    {
+        tuple = t ;
+        this.valueChunks.clear() ;
+        this.valueChunks.addAll( valueChunks ) ;
+    }
+    
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.snickers.ber.TupleNode#getValueChunks()
+     */
+    public List getValueChunks()
+    {
+        return valueChunks ;
+    }
+    
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.snickers.ber.MutableTupleNode#addValueChunk(
+     * java.nio.ByteBuffer)
+     */
+    public void addValueChunk( ByteBuffer valueChunk )
+    {
+        valueChunks.add( valueChunk ) ;
+    }
+
+    
     /**
      * Depth first generation of this tlv tuple node's encoded image.
      * 
@@ -262,7 +307,7 @@
      */
     public void encode( ByteBuffer dest )
     {
-        dest.put( tuple.toEncodedArray() ) ;
+        dest.put( tuple.toEncodedBuffer( this.valueChunks ) ) ;
         
         if ( tuple.isPrimitive() )
         {
@@ -306,7 +351,7 @@
         buf.append( tuple.getId() ) ;
         buf.append( ' ' ).append( tuple.typeClass ) ;
         buf.append( '[' ).append( tuple.length ).append( ']' ) ;
-        buf.append( '[' ).append( new String( (byte[]) tuple.getValue() ) ) ;
+        buf.append( '[' ).append( new String( tuple.getLastValueChunk().array() ) ) ;
         buf.append( ']' ) ;
         
         return buf.toString() ;
@@ -327,16 +372,6 @@
     
     
     /**
-     * Start analyzing the tree rooted at this node.
-     */
-    public void analyze()
-    {
-        TupleTreeAnalyzer analyzer = new TupleTreeAnalyzer( this ) ;
-        analyzer.startup() ;
-    }
-    
-    
-    /**
      * Generates a depth first traversal of this node.
      * 
      * @param buf the buffer to capture the traversal into
@@ -355,8 +390,6 @@
         buf.append( levelTab ).append( tuple.getId() ) ;
         buf.append( ' ' ).append( tuple.typeClass ) ;
         buf.append( '[' ).append( tuple.length ).append( ']' ) ;
-        buf.append( '[' ).append( new String( (byte[]) tuple.getValue() ) ) ;
-        buf.append( ']' ) ;
         for ( int ii = 0; ii < children.size(); ii++ )
         {
             child = ( DefaultMutableTupleNode ) children.get( ii ) ;
@@ -366,114 +399,6 @@
     
     
     // ------------------------------------------------------------------------
-    // MutableTreeNode implementations
-    // ------------------------------------------------------------------------
-    
-    
-    /* (non-Javadoc)
-     * @see javax.swing.tree.TreeNode#children()
-     */
-    public Enumeration children()
-    {
-        return Collections.enumeration( children ) ;
-    }
-    
-    
-    /* (non-Javadoc)
-     * @see javax.swing.tree.TreeNode#getAllowsChildren()
-     */
-    public boolean getAllowsChildren()
-    {
-        return ! tuple.isPrimitive() ;
-    }
-    
-    
-    /* (non-Javadoc)
-     * @see javax.swing.tree.TreeNode#getChildAt(int)
-     */
-    public TreeNode getChildAt( int childIndex )
-    {
-        return ( TreeNode ) getChildTupleNodeAt( childIndex ) ;
-    }
-    
-    
-    /* (non-Javadoc)
-     * @see javax.swing.tree.TreeNode#getIndex(javax.swing.tree.TreeNode)
-     */
-    public int getIndex( TreeNode node )
-    {
-        return getIndex( ( TupleNode ) node ) ;
-    }
-    
-    
-    /* (non-Javadoc)
-     * @see javax.swing.tree.TreeNode#getParent()
-     */
-    public TreeNode getParent()
-    {
-        return parent ;
-    }
-    
-    
-    /* (non-Javadoc)
-     * @see javax.swing.tree.MutableTreeNode#insert(
-     * javax.swing.tree.MutableTreeNode, int)
-     */
-    public void insert( MutableTreeNode child, int index )
-    {
-        insert( ( MutableTupleNode ) child, index ) ;
-    }
-    
-    
-    /* (non-Javadoc)
-     * @see javax.swing.tree.TreeNode#isLeaf()
-     */
-    public boolean isLeaf()
-    {
-        if ( tuple != null && tuple.isPrimitive() )
-        {    
-            return true ;
-        }
-        
-        if ( children.isEmpty() )
-        {
-            return true ;
-        }
-
-        return false ;
-    }
-    
-    
-    /* (non-Javadoc)
-     * @see javax.swing.tree.MutableTreeNode#remove(
-     * javax.swing.tree.MutableTreeNode)
-     */
-    public void remove( MutableTreeNode node )
-    {
-        remove( ( MutableTupleNode ) node ) ;
-    }
-    
-    
-    /* (non-Javadoc)
-     * @see javax.swing.tree.MutableTreeNode#setParent(
-     * javax.swing.tree.MutableTreeNode)
-     */
-    public void setParent( MutableTreeNode newParent )
-    {
-        parent = ( DefaultMutableTupleNode ) newParent ;
-    }
-    
-    
-    /* (non-Javadoc)
-     * @see javax.swing.tree.MutableTreeNode#setUserObject(java.lang.Object)
-     */
-    public void setUserObject( Object object )
-    {
-        tuple = ( Tuple ) object ;
-    }
-    
-    
-    // ------------------------------------------------------------------------
     // java.lang.Object overrides & overloads 
     // ------------------------------------------------------------------------
     
@@ -525,8 +450,10 @@
         DefaultMutableTupleNode n2Child = null ;
         for ( int ii = 0; ii < n1.getChildCount() ; ii++ )
         {
-            n1Child = ( DefaultMutableTupleNode  ) n1.getChildAt( ii ) ; 
-            n2Child = ( DefaultMutableTupleNode  ) n2.getChildAt( ii ) ;
+            n1Child = ( DefaultMutableTupleNode  ) 
+                n1.getChildTupleNodeAt( ii ) ; 
+            n2Child = ( DefaultMutableTupleNode  ) 
+                n2.getChildTupleNodeAt( ii ) ;
             
             if ( ! equals( n1Child, n2Child ) )
             {

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/MutableTupleNode.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/MutableTupleNode.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/MutableTupleNode.java	Fri Mar 26 17:29:48 2004
@@ -16,6 +16,9 @@
  */
 package org.apache.snickers.ber ;
 
+import java.nio.ByteBuffer;
+import java.util.List;
+
 
 /**
  * A mutable TupleNode used for building TLV Tuple trees.
@@ -60,11 +63,27 @@
       */
      void setParent( MutableTupleNode newParent ) ; 
               
+    /**
+     * Resets the Tuple of the receiver object.  Also clears the value chunk 
+     * buffers accumulated for the previous tuple if any.
+     * 
+     * @param t the tuple to set for this node
+     */
+    void setTuple( Tuple t ) ;  
+     
+    /**
+     * Resets the Tuple of the receiver object.  Also clears the value chunk 
+     * buffers accumulated for the previous tuple if any.
+     * 
+     * @param t the tuple to set for this node
+     * @param valueChunks the list of value chunk buffers
+     */
+    void setTuple( Tuple t, List valueChunks ) ;  
+     
      /**
-      * Resets the Tuple of the receiver object.
-      * 
-      * @param t the tuple to set for this node
+      * Adds a buffer containing the entire buffer or a chunked peice of it.
+      *
+      * @param valueChunk a chunk of the value as a byte buffer
       */
-     void setTuple( Tuple t ) ;  
-               
+     void addValueChunk( ByteBuffer valueChunk ) ;
 }

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/Tag.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/Tag.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/Tag.java	Fri Mar 26 17:29:48 2004
@@ -31,11 +31,11 @@
 public class Tag
 {
     /** tag mask for the primitive/constructed bit - 0010 0000 - 0x20 */
-    private static final int PRIMITIVE_MASK = 0x20;
+    private static final int PRIMITIVE_MASK = 0x20 ;
     /** tag mask for the short tag format - 0001 1111 - 0x1F */
     public static final int SHORT_MASK = 0x1F ;
     /** tag mask for the long tag format - 0111 1111 - 0x7F */
-    public static final int LONG_MASK = 0x7F ; 
+    public static final int LONG_MASK = 0x7F ;
 
     /** tag id */
     private int id = 0 ;
@@ -45,7 +45,7 @@
     private boolean isFixated = false ;
     /** the type class of this tag */
     private TypeClass typeClass = TypeClass.APPLICATION ;
-    /** a byte buffer used to collect the arriving tag octets */ 
+    /** a byte buffer used to collect the arriving tag octets */
     private final ArrayByteList buf = new ArrayByteList( 10 ) ;
 
 

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/Tuple.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/Tuple.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/Tuple.java	Fri Mar 26 17:29:48 2004
@@ -17,22 +17,25 @@
 package org.apache.snickers.ber ;
 
 
+import java.util.List ;
+
 import java.nio.ByteBuffer ;
 
 import org.apache.commons.lang.ArrayUtils ;
 
 
 /**
- * Simple TLV Tuple.  Because the length field is a primitive int it's maximum
- * value is 2,147,483,647 a single TLV's tuple cannot have a length over this
- * amount or a value size over 2 GB.
+ * TLV Tuple used by the value chunking decoder.  Because the length field is 
+ * a primitive int it's maximum value is 2,147,483,647 a single TLV's tuple 
+ * cannot have a length over this amount or a value size over 2 GB.
  * 
  * @author <a href="mailto:directory-dev@incubator.apache.org">
  * Apache Directory Project</a>
  * @version $Rev$
  */
-public class Tuple
+public class Tuple 
 {
+    /** empty buffer reused for handling null */
     private static final ByteBuffer EMPTY_BUFFER =
         ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ;
     
@@ -44,15 +47,15 @@
     private static final int BIT_7 = 0x80 ;
     
     /** precalculated left shift of 1 by 14 places */
-    static final int BIT_13 = 1 << 14 ;
+    private static final int BIT_13 = 1 << 14 ;
     /** precalculated left shift of 1 by 16 places */
-    static final int BIT_15 = 1 << 16 ;
+    private static final int BIT_15 = 1 << 16 ;
     /** precalculated left shift of 1 by 21 places */
-    static final int BIT_20 = 1 << 21 ;
+    private static final int BIT_20 = 1 << 21 ;
     /** precalculated left shift of 1 by 24 places */
-    static final int BIT_23 = 1 << 24 ;
+    private static final int BIT_23 = 1 << 24 ;
     /** precalculated left shift of 1 by 28 places */
-    static final int BIT_27 = 1 << 28 ;
+    private static final int BIT_27 = 1 << 28 ;
     
     /** the tag id for this TLV tuple */
     int id = 0 ;
@@ -62,8 +65,8 @@
     TypeClass typeClass = TypeClass.APPLICATION ;
     /** the length for this TLV tuple */
     int length = 0 ;
-    /** the value for this TLV tuple */
-    Object value ;
+    /** the present value chunk buffer read for this TLV tuple */
+    ByteBuffer valueChunk = EMPTY_BUFFER ;
     
     /** tlv byte index */
     int index = Length.UNDEFINED ;
@@ -81,7 +84,6 @@
      */
     Tuple() 
     {
-        value = ArrayUtils.EMPTY_BYTE_ARRAY ;
     }
     
     
@@ -113,7 +115,7 @@
     {
         this.id = id ;
         this.length = length ;
-        value = ArrayUtils.EMPTY_BYTE_ARRAY ;
+        valueChunk = EMPTY_BUFFER ;
         isPrimitive = false ;
         
         if ( typeClass != null )
@@ -124,104 +126,21 @@
     
     
     /**
-     * Creates primitive application type tlv tuples.  This will be the primary
-     * constructor used to build primitives.
-     * 
-     * @param id the tag id of the tlv
-     * @param value the value portion for this Tuple
-     */
-    public Tuple( int id, byte[] value )
-    {
-        this( id, TypeClass.APPLICATION, true, value ) ;
-    }
-    
-    
-    /**
-     * Creates primitive application type tlv tuples.  This will be the primary
-     * constructor used to build primitives.
-     * 
-     * @param id the tag id of the tlv
-     * @param value the value portion for this Tuple
-     */
-    public Tuple( int id, ByteBuffer value )
-    {
-        this( id, TypeClass.APPLICATION, true, value ) ;
-    }
-    
-    
-    /**
-     * Creates an application type tlv with a set value and length.  
-     * 
-     * @param id the tag id of the tlv
-     * @param isPrimitive whether or not the tlv is primitive or constructed
-     * @param value the value portion for this Tuple
-     */
-    public Tuple( int id, boolean isPrimitive, byte[] value )
-    {
-        this( id, TypeClass.APPLICATION, isPrimitive, value ) ;
-    }
-    
-    
-    /**
-     * Creates an application type tlv with a set value and length.  
-     * 
-     * @param id the tag id of the tlv
-     * @param isPrimitive whether or not the tlv is primitive or constructed
-     * @param value the value portion for this Tuple
-     */
-    public Tuple( int id, boolean isPrimitive, ByteBuffer value )
-    {
-        this( id, TypeClass.APPLICATION, isPrimitive, value ) ;
-    }
-    
-    
-    /**
-     * Creates a tuple where the length is indefinate.  The tuple according to
-     * the BER encoding must be of the constructed type.
-     * 
-     * @param id the tag id of the tlv
-     * @param typeClass the type class for the tlv
-     * @param isPrimitive whether or not the tlv is primitive or constructed
-     * @param value the value portion for this Tuple
-     */
-    public Tuple( int id, TypeClass typeClass )
-    {
-        this.id = id ;
-        this.isPrimitive = false ;
-        value = ArrayUtils.EMPTY_BYTE_ARRAY ;
-        length = Length.INDEFINATE ;
-        
-        if ( typeClass != null )
-        {
-            this.typeClass = typeClass ;
-        }
-    }
-    
-    
-    /**
-     * Creates a tuple where every member is specified including the length 
-     * which is taken from the value array.
+     * Creates constructed application type tlv tuples.  Constructed TLV's with
+     * a definate length will use this constructor predominantly.
      * 
      * @param id the tag id of the tlv
-     * @param typeClass the type class for the tlv
-     * @param isPrimitive whether or not the tlv is primitive or constructed
-     * @param value the value portion for this Tuple
+     * @param length the length of the value which is the length of all the 
+     *      nested tuples.
+     * @param isPrimitive whether or not this Tuple is primitive or constructed
+     * @param typeClass the type class of this tlv tuple
      */
-    public Tuple( int id, TypeClass typeClass, boolean isPrimitive, 
-                  byte[] value )
+    public Tuple( int id, int length, boolean isPrimitive, TypeClass typeClass )
     {
         this.id = id ;
-        this.isPrimitive = isPrimitive ;
-        
-        if ( value != null )
-        {
-            this.value = value ;
-            this.length = value.length ;
-        }
-        else
-        {
-            this.value = ArrayUtils.EMPTY_BYTE_ARRAY ;
-        }
+        this.length = length ;
+        valueChunk = EMPTY_BUFFER ;
+        isPrimitive = false ;
         
         if ( typeClass != null )
         {
@@ -231,29 +150,18 @@
     
     
     /**
-     * Creates a tuple where every member is specified including the length 
-     * which is taken from the value array.
+     * Creates a tuple where the length is indefinate.  The tuple according to
+     * the BER encoding must be of the constructed type.
      * 
      * @param id the tag id of the tlv
      * @param typeClass the type class for the tlv
-     * @param isPrimitive whether or not the tlv is primitive or constructed
-     * @param value the value portion for this Tuple
      */
-    public Tuple( int id, TypeClass typeClass, boolean isPrimitive, 
-                  ByteBuffer value )
+    public Tuple( int id, TypeClass typeClass )
     {
         this.id = id ;
-        this.isPrimitive = isPrimitive ;
-        
-        if ( value != null )
-        {
-            this.value = value ;
-            this.length = value.remaining() ;
-        }
-        else
-        {
-            this.value = EMPTY_BUFFER ;
-        }
+        this.isPrimitive = false ;
+        valueChunk = EMPTY_BUFFER ;
+        length = Length.INDEFINATE ;
         
         if ( typeClass != null )
         {
@@ -337,13 +245,13 @@
 
     
     /**
-     * Gets the value field (V-part) for this TLV Tuple.
+     * Gets the last chunk read for the value field (V-part) for this TLV Tuple.
      * 
-     * @return the value field for this TLV Tuple
+     * @return the last valueChunk field for this TLV Tuple
      */
-    public Object getValue()
+    public ByteBuffer getLastValueChunk()
     {
-        return value ;
+        return valueChunk ;
     }
     
     
@@ -382,16 +290,18 @@
         this.isPrimitive = true ;
         this.length = Length.UNDEFINED ;
         this.typeClass = TypeClass.APPLICATION ;
-        this.value = ArrayUtils.EMPTY_BYTE_ARRAY ;
+        this.valueChunk = EMPTY_BUFFER ;
         this.valueIndex = Length.UNDEFINED ;
     }
 
     
     /**
-     * Does not take into account the index or the valueIndex values when
+     * Does not take into account the value, index or the valueIndex values when
      * checking for equality.  Technically if both are being constructed by
      * the decoder then they should only be equal when these values are equal
-     * because the tag, length or value would not be correct.
+     * because the tag, length or value would not be correct.  Plus since this
+     * is a chunking tuple the valueChunk means nothing with respect to the
+     * final value.
      *
      * @see java.lang.Object#equals(java.lang.Object)
      */
@@ -426,41 +336,7 @@
                 return false ;
             }
             
-            if ( t.value == null && value == null )
-            {
-                return true ;
-            }
-            else if ( t.value == null || value == null )
-            {
-                return false ;
-            }
-            else if ( t.value == value )
-            {
-                return true ;
-            }
-            else if ( t.value.getClass() != value.getClass() )
-            {
-                if ( t.value instanceof ByteBuffer && value instanceof byte[] )
-                {
-                    ByteBuffer bb = ByteBuffer.wrap( ( byte[] ) value ) ;
-                    return bb.equals( t.value ) ;
-                }
-                else if ( value instanceof ByteBuffer && 
-                            t.value instanceof byte[] )
-                {
-                    ByteBuffer bb = ByteBuffer.wrap( ( byte[] ) t.value ) ;
-                    return bb.equals( value ) ;
-                }
-                
-                return false ;
-            }
-            else if ( t.value instanceof byte[] &&
-                        ArrayUtils.isEquals( t.value, value ) )
-            {  
-                return true ;
-            }
-            
-            return t.value.equals( value ) ;
+            return true ;
         }
         
         return false ;
@@ -479,27 +355,22 @@
         t.typeClass = typeClass ;
         t.length = length ;
         
-        if ( value instanceof byte[] )
-        {
-            byte[] bites = ( byte[] ) value ;
-            t.value = bites.clone() ;
-        }
-        else if ( value instanceof ByteBuffer )
-        {
-            ByteBuffer bb = ( ByteBuffer ) value ;
-            ByteBuffer cloned = ByteBuffer.allocate( bb.capacity() ) ;
-            int oldPos = bb.position() ;
-            bb.rewind() ;
-            cloned.put( bb ) ;
-            cloned.limit( bb.limit() ) ;
-            bb.position( oldPos ) ;
-            cloned.rewind() ;
-            t.value = cloned ;
-        }
-        else
-        {    
-            t.value = value ;
-        }
+        /* ------------------------------------------------------------------ +/
+         * @todo figure out if we should remove this section
+         * 
+         * Do think we need this anymore since the last valueChunk does not 
+         * factor into the result returned by the equals(Object) method?
+         * ------------------------------------------------------------------ */
+        ByteBuffer bb = ( ByteBuffer ) valueChunk ;
+        ByteBuffer cloned = ByteBuffer.allocate( bb.capacity() ) ;
+        int oldPos = bb.position() ;
+        bb.rewind() ;
+        cloned.put( bb ) ;
+        cloned.limit( bb.limit() ) ;
+        bb.position( oldPos ) ;
+        cloned.rewind() ;
+        t.valueChunk = cloned ;
+        /* ------------------------------------------------------------------ */
         
         t.index = index ;
         t.valueIndex = valueIndex ;
@@ -514,67 +385,28 @@
     
     
     /**
-     * If this is a primitive TLV then it is encoded fully.  If it is not then
-     * only the TL part of the tuple is encoded leaving the value to be encoded
-     * by the set of child TLVs.
+     * @todo this should produce chunking output and needs to be removed from
+     * here actually and made into a standalone encoder.  You give it a buffer
+     * and it fills it as much as it can remembering where the encode stopped.
+     * Hence it is stateful as expected from the statemachine.
      * 
-     * @return partial encoded image if constructed or complete TLV if primitive
-     */
-    public byte[] toEncodedArray()
-    {
-        byte[] octets = null ;
-        int tagLength = getTagLength() ;
-        int lengthLength = getLengthLength() ;
-        int valueLength = 0 ;
-        int total = tagLength + lengthLength ;
-
-        if ( isPrimitive )
-        {
-            valueLength = ( ( byte[] ) value ).length ;
-            total += valueLength ;
-        }
-        
-        octets = new byte[total] ;
-        setTag( octets, tagLength ) ;
-        setLength( octets, tagLength, lengthLength ) ;
-        
-        if ( isPrimitive )
-        {
-            int destPos = tagLength + lengthLength ;
-            System.arraycopy( value, 0, octets, destPos, valueLength ) ;
-        }
-        
-        return octets ;
-    }
-    
-    
-    /**
-     * If this is a primitive TLV then it is encoded fully.  If it is not then
+     * If this is a primitive TLV then the valueBytes argument is used to 
+     * produce an encoded image of this TLV.  If it is constructed then
      * only the TL part of the tuple is encoded leaving the value to be encoded
      * by the set of child TLVs.
      * 
      * @return partial encoded image if constructed or complete TLV if primitive
      */
-    public ByteBuffer toEncodedBuffer()
+    public ByteBuffer toEncodedBuffer( List valueChunks )
     {
         ByteBuffer octets = null ;
         int tagLength = getTagLength() ;
         int lengthLength = getLengthLength() ;
-        int valueLength = 0 ;
         int total = tagLength + lengthLength ;
-
+        
         if ( isPrimitive )
         {
-            if ( value instanceof ByteBuffer )
-            {
-                valueLength = ( ( ByteBuffer ) value ).remaining() ;
-            }
-            else if ( value instanceof byte[] )
-            {    
-                valueLength = ( ( byte[] ) value ).length ;
-            }
-            
-            total += valueLength ;
+            total += length ;
         }
         
         octets = ByteBuffer.allocate( total ) ;
@@ -583,15 +415,9 @@
         
         if ( isPrimitive )
         {
-            int destPos = tagLength + lengthLength ;
-            
-            if ( value instanceof ByteBuffer )
+            for ( int ii = 0; ii < valueChunks.size(); ii++ )
             {    
-                octets.put( ( ByteBuffer ) value ) ;
-            }
-            else if ( value instanceof byte[] )
-            {    
-                octets.put( ( byte [] ) value ) ;
+                octets.put( ( ByteBuffer ) valueChunks.get(ii) ) ;
             }
         }
         
@@ -600,118 +426,6 @@
     
     
     /**
-     * Sets the tag section within the array at the start of the array.
-     * 
-     * @param octets the array of bytes to set the tag in
-     * @param tagLength the length of the tag section
-     */
-    void setTag( byte[] octets, int tagLength )
-    {
-        octets[0] = ( byte ) typeClass.getValue() ;
-        
-        if ( ! isPrimitive )
-        {
-            octets[0] |= BIT_5 ;
-        }
-        
-        if ( tagLength == 1 )
-        {
-            octets[0] |= id ;
-        }
-        else
-        {
-            octets[0] |= Tag.SHORT_MASK ;
-        }
-        
-        if ( tagLength >= 2 )
-        {
-            octets[1] = ( byte ) ( ( int ) 0x7f & id ) ;
-            
-            if ( tagLength > 2 )
-            {
-                octets[1] |= BIT_7 ;
-            }
-        }
-        else
-        {
-            return ;
-        }
-        
-        /* 
-         * Take bits [8-14] (1 based bit indexing) inclusive in id and set the
-         * value for the second byte to this when shifted down 7 positions so
-         * we need the following mask:
-         * 
-         * 0011 1111 1000 0000 => 0x3f80
-         * 
-         */
-        if ( tagLength >= 3 )
-        {
-            octets[2] = ( byte ) ( ( ( int ) 0x3f80 & id ) >> 7 ) ;
-            
-            if ( tagLength > 3 )
-            {
-                octets[2] |= BIT_7 ;
-            }
-        }
-        else
-        {
-            return ;
-        }
-        
-        /* 
-         * Take bits [15-21] (1 based bit indexing) inclusive in id and set the
-         * value for the second byte to this when shifted down 14 positions so
-         * we need the following mask:
-         * 
-         * 0001 1111 1100 0000 0000 0000 => 0x1fc000
-         * 
-         */
-        if ( tagLength >= 4 )
-        {
-            octets[3] = ( byte ) ( ( ( int ) 0x1fc000 & id ) >> 14 ) ;
-            
-            if ( tagLength > 4 )
-            {
-                octets[3] |= BIT_7 ;
-            }
-        }
-        else
-        {
-            return ;
-        }
-        
-        /* 
-         * Take bits [22-28] (1 based bit indexing) inclusive in id and set the
-         * value for the second byte to this when shifted down 21 positions so
-         * we need the following mask:
-         * 
-         * 0000 1111 1110 0000 0000 0000 0000 0000 => 0x0fe00000
-         * 
-         */
-        if ( tagLength >= 5 )
-        {
-            octets[4] = ( byte ) ( ( ( int ) 0x0fe00000 & id ) >> 21 ) ;
-            
-            if ( tagLength > 5 )
-            {
-                octets[4] |= BIT_7 ;
-            }
-        }
-        else
-        {
-            return ;
-        }
-        
-        if ( tagLength >= 6 )
-        {    
-            throw new IllegalArgumentException( "cannot support id's as large "
-                    + "as " + id + " unless we start using longs for the id" ) ;
-        }
-    }
-
-
-    /**
      * Sets the tag section within the buffer.
      * 
      * @param octets the buffer to set the tag in
@@ -885,84 +599,6 @@
         if ( lengthBytes >= 5 )
         {
             octets.put( ( byte ) ( ( 0xff000000 & length ) >> 24 ) ) ;
-        }
-        else
-        {
-            return ;
-        }
-        
-        if ( lengthBytes >= 6 )
-        {    
-            throw new IllegalArgumentException( "cannot support lengths as "
-                    + "large as " + length 
-                    + " unless we start using longs for the length" ) ;
-        }
-    }
-
-
-    /**
-     * Sets the length bytes.
-     * 
-     * @param octets the byte [] to set length in
-     * @param offset the offset in the array to start the length section in
-     * @param lengthBytes the number bytes for the length section
-     */
-    void setLength( byte[] octets, int offset, int lengthBytes )
-    {
-        if ( length == Length.INDEFINATE )
-        {
-            octets[offset] = ( byte ) BIT_7 ;
-            return ;
-        }
-        else if ( lengthBytes == 1 )
-        {
-            octets[offset] = ( byte ) length ;
-            return ;
-        }
-        else
-        {
-            /*
-             * the lengthBytes argument is the number of octets for the L field
-             * total which for the long form includes the first octet for the 
-             * length of length (N) value where N < 127.  Technically with the 
-             * 7 bits we can specify an N of up to 127 but this value of N is 
-             * reserved.  Anyway below we subtract one from lengthBytes to get
-             * N which is set as the last 7 bits of the first octet of the L
-             * field. 
-             */
-            octets[offset] |= BIT_7 | lengthBytes - 1 ;
-        }
-        
-        if ( lengthBytes >= 2 )
-        {
-            octets[offset + 1] =  ( byte ) ( 0xff & length ) ;
-        }
-        else
-        {
-            return ;
-        }
-        
-        if ( lengthBytes >= 3 )
-        {
-            octets[offset + 2] = ( byte ) ( ( 0xff00 & length ) >> 8 ) ;
-        }
-        else
-        {
-            return ;
-        }
-        
-        if ( lengthBytes >= 4 )
-        {
-            octets[offset + 3] = ( byte ) ( ( 0xff0000 & length ) >> 16 ) ;
-        }
-        else
-        {
-            return ;
-        }
-        
-        if ( lengthBytes >= 5 )
-        {
-            octets[offset + 4] = ( byte ) ( ( 0xff000000 & length ) >> 24 ) ;
         }
         else
         {

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleNode.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleNode.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleNode.java	Fri Mar 26 17:29:48 2004
@@ -17,7 +17,9 @@
 package org.apache.snickers.ber ;
 
 
+import java.util.List ;
 import java.util.Iterator ;
+
 import java.nio.ByteBuffer ;
 
 
@@ -58,6 +60,13 @@
     TupleNode getChildTupleNodeAt( int index ) ;
     
     /**
+     * Gets the chunked value buffer fragments collected within this node.  
+     * 
+     * @return the value buffer parts for this node
+     */
+    List getValueChunks() ;
+    
+    /**
      * Gets the index of a child if the child node if it exists.  The analog
      * within <code>TreeNode<code> takes a <code>TreeNode</code> instead of a 
      * <code>TupleNode</code>.
@@ -82,7 +91,6 @@
      * @return the number of children
      */
     int size() ;
-    
     
     /**
      * Gets the Tuple this node represents.   This is the analogous to <code>

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleTreeDecoder.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleTreeDecoder.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleTreeDecoder.java	Fri Mar 26 17:29:48 2004
@@ -17,6 +17,7 @@
 package org.apache.snickers.ber ;
 
 
+import java.util.ArrayList;
 import java.util.Stack ;
 import java.nio.ByteBuffer ;
 
@@ -42,11 +43,13 @@
     /** a stack of nested constructed tuples used to track state */
     Stack stack = new Stack() ;
     /** the underlying BER data stream to TLV stream decoder */
-    BERDecoder decoder = new BERDecoder( 1024 ) ;
+    BERDecoder decoder = new BERDecoder() ;
     /** the callback to use for this StatefulDecoder */
     DecoderCallback cb = null ;
     /** the monitor to use for this StatefulDecoder */
     DecoderMonitor monitor = new DecoderMonitorAdapter() ;
+    /** the value chunks buffer collection */
+    ArrayList valueChunks = new ArrayList() ;
 
     
     /**
@@ -58,7 +61,15 @@
         {
             public void tagDecoded( Tuple tlv ) { }
             
-            public void partialValueDecoded( Tuple tlv ) { }
+            public void partialValueDecoded( Tuple tlv ) 
+            {
+                ByteBuffer copy = ByteBuffer.allocate( 
+                        tlv.getLastValueChunk().remaining() ) ;
+                copy.put( tlv.getLastValueChunk() ) ;
+                tlv.getLastValueChunk().rewind() ;
+                copy.rewind() ;
+                valueChunks.add( copy ) ;
+            }
         
             public void lengthDecoded( Tuple tlv )
             {
@@ -107,7 +118,9 @@
         
         if ( t.isPrimitive )
         {
-            node = new DefaultMutableTupleNode( ( Tuple ) t.clone() ) ;
+            node = new DefaultMutableTupleNode( ( Tuple ) t.clone(), 
+                    valueChunks ) ;
+            valueChunks.clear() ;
                 
             if ( ! stack.isEmpty() )
             {    

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TypeClass.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TypeClass.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TypeClass.java	Fri Mar 26 17:29:48 2004
@@ -20,7 +20,6 @@
 import java.util.Map ;
 import java.util.List ;
 
-import org.apache.commons.codec.binary.Binary ;
 import org.apache.commons.lang.enum.EnumUtils ;
 import org.apache.commons.lang.enum.ValuedEnum ;
 
@@ -44,11 +43,11 @@
     /** value for the universal type class */
     public static final int UNIVERSAL_VAL = 0 ;
     /** value for the application type class */
-    public static final int APPLICATION_VAL = Binary.BIT_6 ;
+    public static final int APPLICATION_VAL = 0x40 ;
     /** value for the context specific type class */
-    public static final int CONTEXT_SPECIFIC_VAL = Binary.BIT_7 ;
+    public static final int CONTEXT_SPECIFIC_VAL = 0x80 ;
     /** value for the private type class */
-    public static final int PRIVATE_VAL = Binary.BIT_6 | Binary.BIT_7 ;
+    public static final int PRIVATE_VAL = 0xc0 ;
 
     /** enum for the universal type class */
     public static final TypeClass UNIVERSAL = 

Modified: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/AbstractDecoderTestCaseTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/AbstractDecoderTestCaseTest.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/AbstractDecoderTestCaseTest.java	Fri Mar 26 17:29:48 2004
@@ -17,6 +17,8 @@
 package org.apache.snickers.ber ;
 
 
+import java.nio.ByteBuffer;
+
 import org.apache.commons.lang.ArrayUtils ;
 
 
@@ -68,20 +70,26 @@
     public void testDecodeTupleArray() throws Exception
     {
         Tuple [] tuples = new Tuple[2] ;
-        tuples[0] = new Tuple(1, ArrayUtils.EMPTY_BYTE_ARRAY ) ;
-        tuples[1] = new Tuple(1, ArrayUtils.EMPTY_BYTE_ARRAY ) ;
-        decode(tuples) ;
+        tuples[0] = new Tuple( 1, 0 ) ;
+        tuples[1] = new Tuple( 1, 0 ) ;
         
-        decode( new Tuple[0] ) ;
+        ByteBuffer[] buffers = new ByteBuffer[2] ; 
+        buffers[0] = ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ;
+        buffers[1] = ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ;
+        decode( tuples, buffers ) ;
+        decode( tuples[0], ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ) ;
     }
 
     public void testCallbackOccured() throws Exception
     {
         decoder.setDecoderMonitor( this ) ;
         Tuple [] tuples = new Tuple[2] ;
-        tuples[0] = new Tuple(1, ArrayUtils.EMPTY_BYTE_ARRAY ) ;
-        tuples[1] = new Tuple(1, ArrayUtils.EMPTY_BYTE_ARRAY ) ;
-        decode(tuples) ;
+        tuples[0] = new Tuple(1, 0) ;
+        tuples[1] = new Tuple(1, 0) ;
+        ByteBuffer[] buffers = new ByteBuffer[2] ; 
+        buffers[0] = ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ;
+        buffers[1] = ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ;
+        decode(tuples, buffers) ;
         callbackOccured(decoder, this, tuples[1]) ;
     }
 

Modified: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/BERDecoderCallbackAdapterTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/BERDecoderCallbackAdapterTest.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/BERDecoderCallbackAdapterTest.java	Fri Mar 26 17:29:48 2004
@@ -74,6 +74,11 @@
         adapter.lengthDecoded( null ) ;
     }
 
+    public void testPartialValueDecoded()
+    {
+        adapter.partialValueDecoded( null ) ;
+    }
+
     public void testDecodeOccurred()
     {
         adapter.decodeOccurred( null, null ) ;

Modified: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/BERDecoderTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/BERDecoderTest.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/BERDecoderTest.java	Fri Mar 26 17:29:48 2004
@@ -18,13 +18,14 @@
 
 
 import java.nio.ByteBuffer ;
+import java.util.ArrayList ;
 
 import org.apache.commons.lang.ArrayUtils ;
 import org.apache.commons.lang.RandomStringUtils ;
 
-import org.apache.commons.codec.stateful.DecoderCallback;
+import org.apache.commons.codec.stateful.DecoderCallback ;
+import org.apache.commons.codec.stateful.StatefulDecoder ;
 import org.apache.commons.codec.stateful.DecoderMonitorAdapter ;
-import org.apache.commons.codec.stateful.StatefulDecoder;
 
 
 /**
@@ -37,6 +38,10 @@
  */
 public class BERDecoderTest extends AbstractDecoderTestCase
 {
+    private static final ByteBuffer EMPTY_BUFFER = 
+        ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ;
+    
+    
     public BERDecoderTest()
     {
         super( BERDecoderTest.class.getName() ) ;
@@ -47,86 +52,96 @@
     {
         decoder.setDecoderMonitor( new DecoderMonitorAdapter() ) ;
         decoder.decode( null ) ;
-        decoder.decode( ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ) ;
+        decoder.decode( EMPTY_BUFFER ) ;
     }
     
     
     public void testPrimitives() throws Exception
     {
-        byte[] bites = null ;
         Tuple decoded = null ;
-        Tuple t = new Tuple( 45, ArrayUtils.EMPTY_BYTE_ARRAY ) ;
-        assertTrue( decode( t ).equals( t ) ) ; 
+        Tuple t = new Tuple( 45, 0, true, TypeClass.APPLICATION ) ;
+        assertTrue( decode( t, EMPTY_BUFFER ).equals( t ) ) ; 
         
-        t = new Tuple( 45, "Hello world!".getBytes() ) ;
-        decoded = decode( t ) ;
+        t = new Tuple( 45, "Hello world!".length(), true, 
+                TypeClass.APPLICATION ) ;
+        decoded = decode( t, ByteBuffer.wrap( "Hello world!".getBytes() ) ) ;
         assertTrue( decoded.equals( t ) ) ;
-        assertEquals( "Hello world!", new String( (byte[]) 
-                        decoded.getValue() ) ) ;
+        assertEquals( "Hello world!", toString( decoded.getLastValueChunk() ) ) ;
 
         String mesg = RandomStringUtils.randomAlphanumeric(1000) ;
-        t = new Tuple( 1234233, mesg.getBytes() ) ;
-        decoded = decode( t ) ;
+        t = new Tuple( 1234233, mesg.length(), true, TypeClass.APPLICATION ) ;
+        decoded = decode( t, ByteBuffer.wrap( mesg.getBytes() ) ) ;
         assertTrue( decoded.equals( t ) ) ;
-        assertEquals( mesg, new String( (byte[]) 
-                        decoded.getValue() ) ) ;
+        assertEquals( mesg, toString( decoded.getLastValueChunk() ) ) ;
+    }
+    
+    
+    String toString(ByteBuffer buf)
+    {
+        buf = buf.slice() ;
+        byte[] bites = new byte[buf.remaining()] ;
+        buf.get( bites ) ;
+        return new String( bites ) ; 
     }
     
     
     public void testConstructedIndefinate() throws Exception
     {
         Tuple top = new Tuple( 1, TypeClass.APPLICATION ) ;
-        Tuple t0 = new Tuple( 2, "Hello".getBytes() ) ;
-        Tuple t1 = new Tuple( 3, "World".getBytes() ) ;
-        Tuple terminator = new Tuple( 0, TypeClass.UNIVERSAL, true, 
-                ArrayUtils.EMPTY_BYTE_ARRAY ) ;
-        assertTrue( decode( top ).equals( top ) ) ;
+        Tuple t0 = new Tuple( 2, "Hello".length(),
+                true, TypeClass.APPLICATION ) ;
+        Tuple t1 = new Tuple( 3, "World".length(),
+                true, TypeClass.APPLICATION ) ;
+        Tuple terminator = new Tuple( 0, 0, true, TypeClass.UNIVERSAL ) ;
+        assertTrue( decode( top, EMPTY_BUFFER ).equals( top ) ) ;
 
-        Tuple decoded = decode( t0 ) ; 
+        Tuple decoded = decode( t0, ByteBuffer.wrap( "Hello".getBytes() ) ) ; 
         assertTrue( decoded.equals( t0 ) ) ;
-        assertEquals( "Hello", new String( ( byte[] ) decoded.getValue() ) ) ;
+        assertEquals( "Hello", toString( decoded.getLastValueChunk() ) ) ;
         
-        decoded = decode( t1 ) ; 
+        decoded = decode( t1, ByteBuffer.wrap( "World".getBytes() ) ) ; 
         assertTrue( decoded.equals( t1 ) ) ;
-        assertEquals( "World", new String( ( byte[] ) decoded.getValue() ) ) ;
+        assertEquals( "World", toString( decoded.getLastValueChunk() ) ) ;
         
-        decoded = decode( terminator ) ;
+        decoded = decode( terminator, EMPTY_BUFFER ) ;
         assertTrue( decoded.equals( top ) ) ;
     }
     
     
     public void testConstructedLongLengthForm() throws Exception
     {
-        String str0 = RandomStringUtils.randomAlphanumeric(10000) ;
-        Tuple t0 = new Tuple( 2, str0.getBytes() ) ;
-        String str1 = RandomStringUtils.randomAlphanumeric(10000) ;
-        Tuple t1 = new Tuple( 3, str1.getBytes() ) ;
+        String str0 = RandomStringUtils.randomAlphanumeric(128) ;
+        Tuple t0 = new Tuple( 2, 128, true, TypeClass.APPLICATION ) ;
+        String str1 = RandomStringUtils.randomAlphanumeric(128) ;
+        Tuple t1 = new Tuple( 3, 128, true, TypeClass.APPLICATION ) ;
         Tuple top = new Tuple( 1, t0.size() + t1.size() ) ;
-        assertTrue( decode( top ).equals( top ) ) ;
+        assertTrue( decode( top, EMPTY_BUFFER ).equals( top ) ) ;
 
-        Tuple decoded = decode( t0 ) ; 
+        Tuple decoded = decode( t0, ByteBuffer.wrap( str0.getBytes() ) ) ; 
         assertTrue( decoded.equals( t0 ) ) ;
-        assertEquals( str0, new String( ( byte[] ) decoded.getValue() ) ) ;
+        assertEquals( str0, toString( decoded.getLastValueChunk() ) ) ;
         
         // automatically set to top because after t1 is delivered top is 
-        decoded = decode( t1 ) ; 
+        decoded = decode( t1, ByteBuffer.wrap( str1.getBytes() ) ) ; 
         assertTrue( decoded.equals( top ) ) ;
     }
 
 
     public void testConstructedShortLengthForm() throws Exception
     {
-        Tuple t0 = new Tuple( 2, "Hello".getBytes() ) ;
-        Tuple t1 = new Tuple( 3, "World".getBytes() ) ;
+        Tuple t0 = new Tuple( 2, "Hello".length(), true, 
+                TypeClass.APPLICATION ) ;
+        Tuple t1 = new Tuple( 3, "World".length(), true, 
+                TypeClass.APPLICATION ) ;
         Tuple top = new Tuple( 1, t0.size() + t1.size() ) ;
-        assertTrue( decode( top ).equals( top ) ) ;
+        assertTrue( decode( top, EMPTY_BUFFER ).equals( top ) ) ;
 
-        Tuple decoded = decode( t0 ) ; 
+        Tuple decoded = decode( t0, ByteBuffer.wrap( "Hello".getBytes() ) ) ; 
         assertTrue( decoded.equals( t0 ) ) ;
-        assertEquals( "Hello", new String( ( byte[] ) decoded.getValue() ) ) ;
+        assertEquals( "Hello", toString( decoded.getLastValueChunk() ) ) ;
         
         // automatically set to top because after t1 is delivered top is 
-        decoded = decode( t1 ) ; 
+        decoded = decode( t1, ByteBuffer.wrap( "World".getBytes() ) ) ; 
         assertTrue( decoded.equals( top ) ) ;
     }
     
@@ -134,14 +149,16 @@
     public void testFragmentedValue() throws Exception
     {
         String str0 = RandomStringUtils.randomAlphanumeric(20) ;
-        Tuple t0 = new Tuple( 2, str0.getBytes() ) ;
+        Tuple t0 = new Tuple( 2, str0.length(), true, TypeClass.APPLICATION ) ;
         String str1 = RandomStringUtils.randomAlphanumeric(20) ;
-        Tuple t1 = new Tuple( 3, str1.getBytes() ) ;
+        Tuple t1 = new Tuple( 3, str1.length(), true, TypeClass.APPLICATION ) ;
         Tuple top = new Tuple( 1, t0.size() + t1.size() ) ;
-        assertTrue( decode( top ).equals( top ) ) ;
+        assertTrue( decode( top, EMPTY_BUFFER ).equals( top ) ) ;
 
-        byte[] all = t0.toEncodedArray() ;
-        byte[][] fragments = fragment( all, 10 ) ;
+        ArrayList list = new ArrayList() ;
+        list.add( ByteBuffer.wrap( str0.getBytes() ) ) ;
+        ByteBuffer all = t0.toEncodedBuffer( list ) ;
+        ByteBuffer[] fragments = fragment( all, 10 ) ;
         Tuple decoded = null ;
         
         for ( int ii = 0; ii < fragments.length; ii++ )
@@ -150,10 +167,10 @@
         }
         
         assertTrue( decoded.equals( t0 ) ) ;
-        assertEquals( str0, new String( ( byte[] ) decoded.getValue() ) ) ;
+        assertEquals( str0, toString( buf ) ) ;
         
         // automatically set to top because after t1 is delivered top is 
-        decoded = decode( t1 ) ; 
+        decoded = decode( t1, ByteBuffer.wrap( str1.getBytes() ) ) ; 
         assertTrue( decoded.equals( top ) ) ;
     }
     
@@ -176,17 +193,27 @@
     {
         decoder.setDecoderMonitor( new BERMonitor() ) ;
         String str0 = RandomStringUtils.randomAlphanumeric(20) ;
-        Tuple t0 = new Tuple( 2, str0.getBytes() ) ;
+        Tuple t0 = new Tuple( 2, str0.length() ) ;
         String str1 = RandomStringUtils.randomAlphanumeric(20) ;
-        Tuple t1 = new Tuple( 3, str1.getBytes() ) ;
+        Tuple t1 = new Tuple( 3, str1.length() ) ;
         Tuple top = new Tuple( 1, t0.size() + t1.size() ) ;
-        Tuple decoded = decode( t0 ) ; 
+        Tuple decoded = decode( t0, ByteBuffer.wrap( str0.getBytes() ) ) ; 
         assertTrue( decoded.equals( t0 ) ) ;
         
         // automatically set to top because after t1 is delivered top is 
-        decoded = decode( t1 ) ; 
+        decoded = decode( t1, ByteBuffer.wrap( str1.getBytes() ) ) ; 
+        
+        assertTrue( decode( top, EMPTY_BUFFER ).equals( top ) ) ;
         
-        assertTrue( decode( top ).equals( top ) ) ;
+        decoder.setDecoderMonitor(null) ;
+        decoded = decode( t0, ByteBuffer.wrap( str0.getBytes() ) ) ; 
+        assertTrue( decoded.equals( t0 ) ) ;
+
+        tlvList.clear() ;
+        decoder.setDecoderMonitor(null) ;
+        decoder.setCallback(null) ;
+        decoded = decode( t0, ByteBuffer.wrap( str0.getBytes() ) ) ;
+        assertTrue(tlvList.isEmpty()) ;
     }
 
 
@@ -194,16 +221,16 @@
     {
         decoder.setDecoderMonitor( null ) ;
         String str0 = RandomStringUtils.randomAlphanumeric(20) ;
-        Tuple t0 = new Tuple( 2, str0.getBytes() ) ;
+        Tuple t0 = new Tuple( 2, str0.length() ) ;
         String str1 = RandomStringUtils.randomAlphanumeric(20) ;
-        Tuple t1 = new Tuple( 3, str1.getBytes() ) ;
+        Tuple t1 = new Tuple( 3, str1.length() ) ;
         Tuple top = new Tuple( 1, t0.size() + t1.size() ) ;
-        Tuple decoded = decode( t0 ) ; 
+        Tuple decoded = decode( t0, ByteBuffer.wrap( str0.getBytes() ) ) ; 
         assertTrue( decoded.equals( t0 ) ) ;
         
         // automatically set to top because after t1 is delivered top is 
-        decoded = decode( t1 ) ; 
-        assertTrue( decode( top ).equals( top ) ) ;
+        decoded = decode( t1, ByteBuffer.wrap( str1.getBytes() ) ) ; 
+        assertTrue( decode( top, EMPTY_BUFFER ).equals( top ) ) ;
     }
 
 
@@ -212,15 +239,15 @@
         decoder.setDecoderMonitor( new BERMonitor() ) ;
         decoder.setCallback( null ) ;
         String str0 = RandomStringUtils.randomAlphanumeric(20) ;
-        Tuple t0 = new Tuple( 2, str0.getBytes() ) ;
+        Tuple t0 = new Tuple( 2, str0.length() ) ;
         String str1 = RandomStringUtils.randomAlphanumeric(20) ;
-        Tuple t1 = new Tuple( 3, str1.getBytes() ) ;
+        Tuple t1 = new Tuple( 3, str1.length() ) ;
         Tuple top = new Tuple( 1, t0.size() + t1.size() ) ;
-        Tuple decoded = decode( t0 ) ; 
+        decode( t0, ByteBuffer.wrap( str0.getBytes() ) ) ;
         
         // automatically set to top because after t1 is delivered top is 
-        decoded = decode( t1 ) ; 
-        assertTrue( decode( top ).equals( top ) ) ;
+        decode( t1, ByteBuffer.wrap( str1.getBytes() ) ) ; 
+        assertTrue( decode( top, EMPTY_BUFFER ).equals( top ) ) ;
     }
 
 
@@ -229,15 +256,15 @@
         decoder.setDecoderMonitor( null ) ;
         decoder.setCallback( null ) ;
         String str0 = RandomStringUtils.randomAlphanumeric(20) ;
-        Tuple t0 = new Tuple( 2, str0.getBytes() ) ;
+        Tuple t0 = new Tuple( 2, str0.length() ) ;
         String str1 = RandomStringUtils.randomAlphanumeric(20) ;
-        Tuple t1 = new Tuple( 3, str1.getBytes() ) ;
+        Tuple t1 = new Tuple( 3, str1.length() ) ;
         Tuple top = new Tuple( 1, t0.size() + t1.size() ) ;
-        Tuple decoded = decode( t0 ) ; 
+        decode( t0, ByteBuffer.wrap( str0.getBytes() ) );
         
         // automatically set to top because after t1 is delivered top is 
-        decoded = decode( t1 ) ; 
-        assertTrue( decode( top ).equals( top ) ) ;
+        decode( t1, ByteBuffer.wrap( str1.getBytes() ) ) ;
+        assertTrue( decode( top, EMPTY_BUFFER ).equals( top ) ) ;
     }
 
 
@@ -253,10 +280,10 @@
         
         public void fatalError(StatefulDecoder decoder, Exception exception){}
         
-        public void lengthDecoded(Tuple tlv, byte[] lengthData) { }
+        public void lengthDecoded( Tuple tlv ) { }
         
-        public void tagDecoded(Tuple tlv, byte[] tagData) { }
+        public void tagDecoded( Tuple tlv ) { }
         
-        public void warning(StatefulDecoder decoder, Exception exception) { }
+        public void warning( StatefulDecoder decoder, Exception exception ) { }
     }
 }

Modified: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/ConstructedTLVTests.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/ConstructedTLVTests.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/ConstructedTLVTests.java	Fri Mar 26 17:29:48 2004
@@ -108,8 +108,8 @@
         tlv = decode( "01010101" ) ;
         assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
         assertEquals( 1, tlvList.size() ) ;
-        assertNotNull( tlv.value ) ;
-        assertEquals( 0x0055, 0x00ff & ( int ) ( (byte[]) tlv.value)[0] ) ;
+        assertNotNull( tlv.valueChunk ) ;
+        assertEquals( 0x0055, 0x00ff & tlv.valueChunk.get( 0 ) ) ;
 
         
         // --------------------------------------------------------------------
@@ -132,8 +132,8 @@
         tlv = decode( "01010101" ) ;
         assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
         assertEquals( 2, tlvList.size() ) ;
-        assertNotNull( tlv.value ) ;
-        assertEquals( 0x0055, 0x00ff & ( int ) ( (byte[]) tlv.value)[0] ) ;
+        assertNotNull( tlv.valueChunk ) ;
+        assertEquals( 0x0055, 0x00ff & tlv.valueChunk.get( 0 ) ) ;
 
     
         // --------------------------------------------------------------------
@@ -156,8 +156,8 @@
         tlv = decode( "01010101" ) ;
         assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
         assertEquals( 3, tlvList.size() ) ;
-        assertNotNull( tlv.value ) ;
-        assertEquals( 0x0055, 0x00ff & ( int ) ( (byte[]) tlv.value)[0] ) ;
+        assertNotNull( tlv.valueChunk ) ;
+        assertEquals( 0x0055, 0x00ff & tlv.valueChunk.get( 0 ) ) ;
 
         decode( "00000000" ) ;
         decode( "00000000" ) ;

Modified: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/DefaultMutableTupleNodeTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/DefaultMutableTupleNodeTest.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/DefaultMutableTupleNodeTest.java	Fri Mar 26 17:29:48 2004
@@ -17,16 +17,10 @@
 package org.apache.snickers.ber ;
 
 
-import java.nio.ByteBuffer ;
-import java.util.ArrayList ;
-import java.util.Enumeration ;
-
-import javax.swing.tree.MutableTreeNode ;
+import java.util.Collections;
+import java.util.Iterator ;
 
-import org.apache.commons.codec.stateful.DecoderCallback ;
-import org.apache.commons.codec.stateful.StatefulDecoder ;
-
-import org.apache.commons.lang.ArrayUtils ;
+import java.nio.ByteBuffer ;
 
 
 /**
@@ -45,22 +39,6 @@
 
 
     /*
-     * Class to test for void DefaultMutableTupleNode()
-     */
-    public void testDefaultMutableTupleNode()
-    {
-        DefaultMutableTupleNode node = new DefaultMutableTupleNode() ;
-        assertNotNull( node ) ;
-    }
-
-    /*
-     * Class to test for void DefaultMutableTupleNode(Tuple)
-     */
-    public void testDefaultMutableTupleNodeTuple()
-    {
-    }
-
-    /*
      * Class to test for void insert(MutableTupleNode, int)
      */
     public void testInsertMutableTupleNodeint()
@@ -92,9 +70,9 @@
         parent.remove( (MutableTupleNode) node ) ;
         assertEquals(0,parent.getChildCount()) ;
 
-        parent.insert( (MutableTreeNode) node, 0 ) ;
+        parent.insert( node, 0 ) ;
         assertEquals(1,parent.getChildCount()) ;
-        parent.remove( (MutableTreeNode) node ) ;
+        parent.remove( node ) ;
         assertEquals(0,parent.getChildCount()) ;
     }
 
@@ -119,9 +97,9 @@
         DefaultMutableTupleNode node = new DefaultMutableTupleNode() ;
         parent.insert( (MutableTupleNode) node, 0 ) ;
         node.setParent( (MutableTupleNode) parent) ;
-        assertEquals(parent, node.getParent()) ;
+        assertEquals(parent, node.getParentTupleNode()) ;
         node.setParent((MutableTupleNode)new DefaultMutableTupleNode()) ;
-        assertNotSame(parent, node.getParent()) ;
+        assertNotSame(parent, node.getParentTupleNode()) ;
     }
 
     /*
@@ -131,11 +109,11 @@
     {
         DefaultMutableTupleNode parent = new DefaultMutableTupleNode() ;
         DefaultMutableTupleNode node = new DefaultMutableTupleNode() ;
-        parent.insert( (MutableTreeNode) node, 0 ) ;
-        node.setParent( (MutableTreeNode) parent) ;
-        assertEquals(parent, node.getParent()) ;
-        node.setParent((MutableTreeNode)new DefaultMutableTupleNode()) ;
-        assertNotSame(parent, node.getParent()) ;
+        parent.insert( node, 0 ) ;
+        node.setParent( parent) ;
+        assertEquals(parent, node.getParentTupleNode()) ;
+        node.setParent( new DefaultMutableTupleNode()) ;
+        assertNotSame( parent, node.getParentTupleNode() ) ;
     }
 
     public void testSetTuple()
@@ -153,7 +131,7 @@
         parent.insert( (MutableTupleNode) node, 0 ) ;
         node.setParent( (MutableTupleNode) parent) ;
         assertSame(parent, node.getParentTupleNode()) ;
-        assertSame(parent, node.getParent()) ;
+        assertSame(parent, node.getParentTupleNode()) ;
     }
 
     public void testGetChildren()
@@ -181,7 +159,7 @@
         parent.insert( (MutableTupleNode) node, 0 ) ;
         node.setParent( (MutableTupleNode) parent) ;
         assertEquals( 0, parent.getIndex((MutableTupleNode)node));
-        assertEquals( 0, parent.getIndex((MutableTreeNode)node));
+        assertEquals( 0, parent.getIndex(node));
     }
 
     public void testGetChildCount()
@@ -195,7 +173,7 @@
         parent.insert( (MutableTupleNode) node, 0 ) ;
         node.setParent( (MutableTupleNode) parent) ;
         
-        Tuple primitive = new Tuple( 1, new byte[3] ) ;
+        Tuple primitive = new Tuple( 1, 3, true, TypeClass.APPLICATION ) ;
         Tuple constructed = new Tuple ( 2, TypeClass.APPLICATION ) ;
         parent.setTuple( constructed ) ;
         node.setTuple( primitive ) ;
@@ -212,7 +190,7 @@
         parent.insert( (MutableTupleNode) node, 0 ) ;
         node.setParent( (MutableTupleNode) parent) ;
         
-        Tuple primitive = new Tuple( 1, new byte[3] ) ;
+        Tuple primitive = new Tuple( 1, 3, true, TypeClass.APPLICATION ) ;
         Tuple constructed = new Tuple ( 2, 5, TypeClass.APPLICATION ) ;
         parent.setTuple( constructed ) ;
         node.setTuple( primitive ) ;
@@ -234,12 +212,12 @@
         DefaultMutableTupleNode parent = new DefaultMutableTupleNode() ;
         Tuple constructed = new Tuple ( 2, TypeClass.APPLICATION ) ;
         parent.setTuple( constructed ) ;
-        
         assertEquals(4, parent.size()) ;
-        
         ByteBuffer buf = ByteBuffer.allocate( 4 ) ;
         parent.encode( buf ) ;
 
+        
+        /*
         final ArrayList list = new ArrayList() ;
         TupleTreeDecoder decoder = new TupleTreeDecoder() ;
         decoder.setCallback( new DecoderCallback(){
@@ -252,6 +230,7 @@
         DefaultMutableTupleNode decoded = ( DefaultMutableTupleNode ) 
             list.get(0); 
         assertEquals( decoded.getTuple(), parent.getTuple()) ;
+        */
     }
 
     public void testGetTuple()
@@ -266,15 +245,16 @@
     {
         DefaultMutableTupleNode parent = new DefaultMutableTupleNode() ;
         DefaultMutableTupleNode node = new DefaultMutableTupleNode() ;
+        
         DefaultMutableTupleNode end = new DefaultMutableTupleNode() ;
         parent.insert( (MutableTupleNode) end, 0 ) ;
         end.setParent( (MutableTupleNode) parent) ;
         parent.insert( (MutableTupleNode) node, 0 ) ;
         node.setParent( (MutableTupleNode) parent) ;
         
-        Tuple primitive = new Tuple( 1, new byte[3] ) ;
+        Tuple primitive = new Tuple( 1, 3, true, TypeClass.APPLICATION ) ;
         Tuple constructed = new Tuple ( 2, TypeClass.APPLICATION ) ;
-        Tuple terminator = new Tuple( 0, true, ArrayUtils.EMPTY_BYTE_ARRAY) ;
+        Tuple terminator = new Tuple( 0, 0, true, TypeClass.UNIVERSAL ) ;
         terminator.typeClass = TypeClass.UNIVERSAL ;
         parent.setTuple( constructed ) ;
         node.setTuple( primitive ) ;
@@ -285,6 +265,7 @@
         ByteBuffer buf = ByteBuffer.allocate( 9 ) ;
         parent.encode( buf ) ;
 
+        /**
         final ArrayList list = new ArrayList() ;
         TupleTreeDecoder decoder = new TupleTreeDecoder() ;
         decoder.setCallback( new DecoderCallback(){
@@ -297,6 +278,7 @@
         DefaultMutableTupleNode decoded = ( DefaultMutableTupleNode ) 
             list.get(0); 
         assertEquals( decoded.getTuple(), parent.getTuple()) ;
+        */
     }
 
     public void testEncode1() throws Exception
@@ -306,7 +288,7 @@
         parent.insert( (MutableTupleNode) node, 0 ) ;
         node.setParent( (MutableTupleNode) parent) ;
         
-        Tuple primitive = new Tuple( 1, new byte[3] ) ;
+        Tuple primitive = new Tuple( 1, 3, true, TypeClass.APPLICATION ) ;
         Tuple constructed = new Tuple ( 2, TypeClass.APPLICATION ) ;
         parent.setTuple( constructed ) ;
         node.setTuple( primitive ) ;
@@ -317,6 +299,7 @@
         ByteBuffer buf = ByteBuffer.allocate( 9 ) ;
         parent.encode( buf ) ;
 
+        /*
         final ArrayList list = new ArrayList() ;
         TupleTreeDecoder decoder = new TupleTreeDecoder() ;
         decoder.setCallback( new DecoderCallback(){
@@ -329,6 +312,7 @@
         DefaultMutableTupleNode decoded = ( DefaultMutableTupleNode ) 
             list.get(0); 
         assertEquals( decoded.getTuple(), parent.getTuple()) ;
+        */
     }
 
     public void testEncode2() throws Exception
@@ -343,7 +327,7 @@
         
         Tuple middleTuple = new Tuple( 1, 3, TypeClass.APPLICATION  ) ;
         Tuple topTuple = new Tuple ( 2, 5, TypeClass.APPLICATION ) ;
-        Tuple bottomTuple = new Tuple( 3, new byte[1]) ;
+        Tuple bottomTuple = new Tuple( 3, 1, true, TypeClass.APPLICATION ) ;
         
         bottomTuple.typeClass = TypeClass.UNIVERSAL ;
         top.setTuple( topTuple ) ;
@@ -355,6 +339,7 @@
         ByteBuffer buf = ByteBuffer.allocate( 7 ) ;
         top.encode( buf ) ;
 
+        /*
         final ArrayList list = new ArrayList() ;
         TupleTreeDecoder decoder = new TupleTreeDecoder() ;
         decoder.setCallback( new DecoderCallback(){
@@ -367,6 +352,7 @@
         DefaultMutableTupleNode decoded = ( DefaultMutableTupleNode ) 
             list.get(0); 
         assertEquals( decoded.getTuple(), top.getTuple()) ;
+        */
     }
 
     
@@ -382,7 +368,7 @@
         
         Tuple middleTuple = new Tuple( 1, 3, TypeClass.APPLICATION  ) ;
         Tuple topTuple = new Tuple ( 2, 5, TypeClass.APPLICATION ) ;
-        Tuple bottomTuple = new Tuple( 3, new byte[1]) ;
+        Tuple bottomTuple = new Tuple( 3, 1, true, TypeClass.APPLICATION ) ;
         
         bottomTuple.typeClass = TypeClass.UNIVERSAL ;
         top.setTuple( topTuple ) ;
@@ -409,7 +395,7 @@
         
         Tuple middleTupleClone = new Tuple( 1, 3, TypeClass.APPLICATION  ) ;
         Tuple topTupleClone = new Tuple ( 2, 5, TypeClass.APPLICATION ) ;
-        Tuple bottomTupleClone= new Tuple( 3, new byte[1]) ;
+        Tuple bottomTupleClone= new Tuple( 3, 1, true, TypeClass.APPLICATION ) ;
         
         bottomTupleClone.typeClass = TypeClass.UNIVERSAL ;
         topClone.setTuple( topTupleClone ) ;
@@ -434,7 +420,7 @@
         
         Tuple middleTuple = new Tuple( 1, 3, TypeClass.APPLICATION  ) ;
         Tuple topTuple = new Tuple ( 2, 5, TypeClass.APPLICATION ) ;
-        Tuple bottomTuple = new Tuple( 3, new byte[1]) ;
+        Tuple bottomTuple = new Tuple( 3, 1, true, TypeClass.APPLICATION ) ;
         
         bottomTuple.typeClass = TypeClass.UNIVERSAL ;
         top.setTuple( topTuple ) ;
@@ -463,7 +449,7 @@
         
         Tuple middleTupleClone = new Tuple( 1, 3, TypeClass.APPLICATION  ) ;
         Tuple topTupleClone = new Tuple ( 2, 5, TypeClass.APPLICATION ) ;
-        Tuple bottomTupleClone= new Tuple( 3, new byte[1]) ;
+        Tuple bottomTupleClone= new Tuple( 3, 1, true, TypeClass.APPLICATION ) ;
         
         bottomTupleClone.typeClass = TypeClass.UNIVERSAL ;
         topClone.setTuple( topTupleClone ) ;
@@ -483,11 +469,48 @@
      */
     public void testToString()
     {
+        DefaultMutableTupleNode parent = new DefaultMutableTupleNode() ;
+        DefaultMutableTupleNode node = new DefaultMutableTupleNode() ;
+        DefaultMutableTupleNode end = new DefaultMutableTupleNode() ;
+        parent.insert( end, 0 ) ;
+        end.setParent( parent) ;
+        parent.insert( node, 0 ) ;
+        node.setParent( parent) ;
+        
+        Tuple primitive = new Tuple( 1, 3, true, TypeClass.APPLICATION ) ;
+        Tuple constructed = new Tuple ( 2, TypeClass.APPLICATION ) ;
+        Tuple terminator = new Tuple( 0, 0, true, TypeClass.UNIVERSAL ) ;
+        terminator.typeClass = TypeClass.UNIVERSAL ;
+        parent.setTuple( constructed ) ;
+        node.setTuple( primitive ) ;
+        end.setTuple( terminator ) ;
+        
+        assertNotNull( parent.toString() ) ;
     }
 
-    public void testPrintDepthFirst()
+    public void testSetTupleTupleList()
     {
+        DefaultMutableTupleNode parent = new DefaultMutableTupleNode() ;
+        DefaultMutableTupleNode node = new DefaultMutableTupleNode() ;
+        DefaultMutableTupleNode end = new DefaultMutableTupleNode() ;
+        parent.insert( end, 0 ) ;
+        end.setParent( parent) ;
+        parent.insert( node, 0 ) ;
+        node.setParent( parent) ;
         
+        Tuple primitive = new Tuple( 1, 3, true, TypeClass.APPLICATION ) ;
+        Tuple constructed = new Tuple ( 2, TypeClass.APPLICATION ) ;
+        Tuple terminator = new Tuple( 0, 0, true, TypeClass.UNIVERSAL ) ;
+        terminator.typeClass = TypeClass.UNIVERSAL ;
+        parent.setTuple( constructed ) ;
+        node.setTuple( primitive, Collections.EMPTY_LIST ) ;
+        end.setTuple( terminator ) ;
+        
+        assertTrue( node.getValueChunks().isEmpty() ) ;
+
+
+        node.addValueChunk( ByteBuffer.allocate( 3 ) ) ;
+        assertFalse( node.getValueChunks().isEmpty() ) ;
     }
 
     public void testChildren()
@@ -495,27 +518,27 @@
         DefaultMutableTupleNode parent = new DefaultMutableTupleNode() ;
         DefaultMutableTupleNode node = new DefaultMutableTupleNode() ;
         DefaultMutableTupleNode end = new DefaultMutableTupleNode() ;
-        parent.insert( (MutableTupleNode) end, 0 ) ;
-        end.setParent( (MutableTupleNode) parent) ;
-        parent.insert( (MutableTupleNode) node, 0 ) ;
-        node.setParent( (MutableTupleNode) parent) ;
+        parent.insert( end, 0 ) ;
+        end.setParent( parent) ;
+        parent.insert( node, 0 ) ;
+        node.setParent( parent) ;
         
-        Tuple primitive = new Tuple( 1, new byte[3] ) ;
+        Tuple primitive = new Tuple( 1, 3, true, TypeClass.APPLICATION ) ;
         Tuple constructed = new Tuple ( 2, TypeClass.APPLICATION ) ;
-        Tuple terminator = new Tuple( 0, true, ArrayUtils.EMPTY_BYTE_ARRAY) ;
+        Tuple terminator = new Tuple( 0, 0, true, TypeClass.UNIVERSAL ) ;
         terminator.typeClass = TypeClass.UNIVERSAL ;
         parent.setTuple( constructed ) ;
         node.setTuple( primitive ) ;
-        end.setTuple(terminator) ;
+        end.setTuple( terminator ) ;
         
-        Enumeration list = parent.children() ;
+        Iterator list = parent.getChildren() ;
         
-        assertEquals( node, list.nextElement() ) ;
-        assertEquals( end, list.nextElement() ) ;
+        assertEquals( node, list.next() ) ;
+        assertEquals( end, list.next() ) ;
         
         try
         {
-            list.nextElement() ;
+            list.next() ;
             fail( "should never get here due to thrown exception" ) ;
         }
         catch( Throwable t ) 
@@ -529,115 +552,38 @@
         DefaultMutableTupleNode parent = new DefaultMutableTupleNode() ;
         DefaultMutableTupleNode node = new DefaultMutableTupleNode() ;
         DefaultMutableTupleNode end = new DefaultMutableTupleNode() ;
-        parent.insert( (MutableTupleNode) end, 0 ) ;
-        end.setParent( (MutableTupleNode) parent) ;
-        parent.insert( (MutableTupleNode) node, 0 ) ;
-        node.setParent( (MutableTupleNode) parent) ;
+        parent.insert( end, 0 ) ;
+        end.setParent( parent) ;
+        parent.insert( node, 0 ) ;
+        node.setParent( parent) ;
         
-        Tuple primitive = new Tuple( 1, new byte[3] ) ;
+        Tuple primitive = new Tuple( 1, 3, true, TypeClass.APPLICATION ) ;
         Tuple constructed = new Tuple ( 2, TypeClass.APPLICATION ) ;
-        Tuple terminator = new Tuple( 0, true, ArrayUtils.EMPTY_BYTE_ARRAY) ;
+        Tuple terminator = new Tuple( 0, 0, true, TypeClass.UNIVERSAL ) ;
         terminator.typeClass = TypeClass.UNIVERSAL ;
         parent.setTuple( constructed ) ;
         node.setTuple( primitive ) ;
-        end.setTuple(terminator) ;
-        
-        assertFalse( end.getAllowsChildren() ) ;
-        assertFalse( node.getAllowsChildren() ) ;
-        assertTrue( parent.getAllowsChildren() ) ;
-    }
-
-    public void testGetChildAt()
-    {
+        end.setTuple( terminator ) ;
     }
 
-    /*
-     * Class to test for int getIndex(TreeNode)
-     */
-    public void testGetIndexTreeNode()
-    {
-    }
-
-    public void testGetParent()
-    {
-    }
-
-    /*
-     * Class to test for void insert(MutableTreeNode, int)
-     */
-    public void testInsertMutableTreeNodeint()
-    {
-    }
-
-    public void testIsLeaf0()
-    {
-        DefaultMutableTupleNode parent = new DefaultMutableTupleNode() ;
-        assertTrue( parent.isLeaf() ) ;
-    }
-
-    public void testIsLeaf1()
-    {
-        DefaultMutableTupleNode parent = new DefaultMutableTupleNode() ;
-        parent.setTuple(new Tuple()) ;
-        assertTrue( parent.isLeaf() ) ;
-    }
-
-    public void testIsLeaf2()
-    {
-        DefaultMutableTupleNode parent = new DefaultMutableTupleNode() ;
-        DefaultMutableTupleNode node = new DefaultMutableTupleNode() ;
-        DefaultMutableTupleNode end = new DefaultMutableTupleNode() ;
-        parent.insert( (MutableTupleNode) end, 0 ) ;
-        end.setParent( (MutableTupleNode) parent) ;
-        parent.insert( (MutableTupleNode) node, 0 ) ;
-        node.setParent( (MutableTupleNode) parent) ;
-        
-        Tuple primitive = new Tuple( 1, new byte[3] ) ;
-        Tuple constructed = new Tuple ( 2, TypeClass.APPLICATION ) ;
-        Tuple terminator = new Tuple( 0, true, ArrayUtils.EMPTY_BYTE_ARRAY) ;
-        terminator.typeClass = TypeClass.UNIVERSAL ;
-        parent.setTuple( constructed ) ;
-        node.setTuple( primitive ) ;
-        end.setTuple(terminator) ;
-        
-        assertFalse( parent.isLeaf() ) ;
-    }
-
-    /*
-     * Class to test for void remove(MutableTreeNode)
-     */
-    public void testRemoveMutableTreeNode()
-    {
-    }
-
-    public void testSetUserObject()
-    {
-        DefaultMutableTupleNode node = new DefaultMutableTupleNode() ;
-        node.setUserObject( new Tuple() ) ;
-    }
-    
-    
     public void testAddFirst()
     {
         DefaultMutableTupleNode parent = new DefaultMutableTupleNode() ;
         DefaultMutableTupleNode node = new DefaultMutableTupleNode() ;
         DefaultMutableTupleNode end = new DefaultMutableTupleNode() ;
         parent.addFront( end ) ;
-        end.setParent( (MutableTupleNode) parent) ;
+        end.setParent( parent) ;
         parent.addFront( node ) ;
-        node.setParent( (MutableTupleNode) parent) ;
+        node.setParent( parent) ;
         
-        Tuple primitive = new Tuple( 1, new byte[3] ) ;
+        Tuple primitive = new Tuple( 1, 3, true, TypeClass.APPLICATION ) ;
         Tuple constructed = new Tuple ( 2, TypeClass.APPLICATION ) ;
-        Tuple terminator = new Tuple( 0, true, ArrayUtils.EMPTY_BYTE_ARRAY) ;
+        Tuple terminator = new Tuple( 0, 0, true, TypeClass.UNIVERSAL ) ;
         terminator.typeClass = TypeClass.UNIVERSAL ;
         parent.setTuple( constructed ) ;
         node.setTuple( primitive ) ;
-        end.setTuple(terminator) ;
-
+        end.setTuple( terminator ) ;
         parent.toDepthFirstString() ;
-        parent.analyze() ;
-        assertFalse( parent.isLeaf() ) ;
     }
 
     
@@ -651,14 +597,12 @@
         parent.addLast( end ) ;
         end.setParent( (MutableTupleNode) parent) ;
         
-        Tuple primitive = new Tuple( 1, new byte[3] ) ;
+        Tuple primitive = new Tuple( 1, 3, true, TypeClass.APPLICATION ) ;
         Tuple constructed = new Tuple ( 2, TypeClass.APPLICATION ) ;
-        Tuple terminator = new Tuple( 0, true, ArrayUtils.EMPTY_BYTE_ARRAY) ;
+        Tuple terminator = new Tuple( 0, 0, true, TypeClass.UNIVERSAL ) ;
         terminator.typeClass = TypeClass.UNIVERSAL ;
         parent.setTuple( constructed ) ;
         node.setTuple( primitive ) ;
         end.setTuple(terminator) ;
-
-        assertFalse( parent.isLeaf() ) ;
     }
 }

Modified: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/EncodeDecodeTests.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/EncodeDecodeTests.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/EncodeDecodeTests.java	Fri Mar 26 17:29:48 2004
@@ -61,7 +61,6 @@
         
         root = ( DefaultMutableTupleNode ) 
             TupleTreeDecoder.treeDecode( ByteBuffer.wrap( snaccBytes ) ) ;
-        //root.analyze() ;
         
         if ( root == null )
         {

Modified: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/MultiByteTagTests.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/MultiByteTagTests.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/MultiByteTagTests.java	Fri Mar 26 17:29:48 2004
@@ -27,6 +27,17 @@
  */
 public class MultiByteTagTests extends AbstractDecoderTestCase
 {
+    /** precalculated left shift of 1 by 14 places */
+    private static final int BIT_13 = 1 << 14 ;
+    /** precalculated left shift of 1 by 16 places */
+    private static final int BIT_15 = 1 << 16 ;
+    /** precalculated left shift of 1 by 21 places */
+    private static final int BIT_20 = 1 << 21 ;
+    /** precalculated left shift of 1 by 24 places */
+    private static final int BIT_23 = 1 << 24 ;
+    /** precalculated left shift of 1 by 28 places */
+    private static final int BIT_27 = 1 << 28 ;
+    
 
     /**
      * @param arg0
@@ -140,7 +151,7 @@
         assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
 
         tlv = decode( "00000001" ) ;
-        assertEquals( Tuple.BIT_13, tlv.id ) ;
+        assertEquals( BIT_13, tlv.id ) ;
         assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
     }
 
@@ -159,7 +170,7 @@
         assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
 
         tlv = decode( "01111111" ) ;
-        assertEquals( Tuple.BIT_13 - 1, tlv.id ) ;
+        assertEquals( BIT_13 - 1, tlv.id ) ;
         assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
     }
 
@@ -182,7 +193,7 @@
         assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
 
         tlv = decode( "00000001" ) ;
-        assertEquals( Tuple.BIT_13 + 1, tlv.id ) ;
+        assertEquals( BIT_13 + 1, tlv.id ) ;
         assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
     }
 
@@ -209,7 +220,7 @@
         assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
 
         tlv = decode( "00000001" ) ;
-        assertEquals( Tuple.BIT_20, tlv.id ) ;
+        assertEquals( BIT_20, tlv.id ) ;
         assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
     }
 
@@ -232,7 +243,7 @@
         assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
 
         tlv = decode( "01111111" ) ;
-        assertEquals( Tuple.BIT_20 - 1, tlv.id ) ;
+        assertEquals( BIT_20 - 1, tlv.id ) ;
         assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
     }
 
@@ -259,7 +270,7 @@
         assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
 
         tlv = decode( "00000001" ) ;
-        assertEquals( Tuple.BIT_20 + 1, tlv.id ) ;
+        assertEquals( BIT_20 + 1, tlv.id ) ;
         assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
     }
 
@@ -290,7 +301,7 @@
         assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
 
         tlv = decode( "00000001" ) ;
-        assertEquals( Tuple.BIT_27, tlv.id ) ;
+        assertEquals( BIT_27, tlv.id ) ;
         assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
     }
 
@@ -317,7 +328,7 @@
         assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
 
         tlv = decode( "01111111" ) ;
-        assertEquals( Tuple.BIT_27 - 1, tlv.id ) ;
+        assertEquals( BIT_27 - 1, tlv.id ) ;
         assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
     }
 
@@ -348,7 +359,7 @@
         assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
 
         tlv = decode( "00000001" ) ;
-        assertEquals( Tuple.BIT_27 + 1, tlv.id ) ;
+        assertEquals( BIT_27 + 1, tlv.id ) ;
         assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
     }
 }

Modified: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/SimplePrimitiveTLVTests.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/SimplePrimitiveTLVTests.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/SimplePrimitiveTLVTests.java	Fri Mar 26 17:29:48 2004
@@ -16,6 +16,8 @@
  */
 package org.apache.snickers.ber ;
 
+import java.nio.ByteBuffer;
+
 
 /**
  * Performs simple primitive tlv tests.
@@ -55,8 +57,8 @@
         tlv = decode( "01010101" ) ;
         assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
         assertEquals( 1, tlvList.size() ) ;
-        assertNotNull( tlv.value ) ;
-        assertEquals( 0x0055, 0x00ff & ( int ) ( (byte[]) tlv.value)[0] ) ;
+        assertNotNull( tlv.valueChunk ) ;
+        assertEquals( 0x0055, 0x00ff & tlv.valueChunk.get( 0 ) ) ;
     }
 
 
@@ -79,8 +81,8 @@
         tlv = decode( "01010101" ) ;
         assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
         assertEquals( 1, tlvList.size() ) ;
-        assertNotNull( tlv.value ) ;
-        assertEquals( 0x0055, 0x00ff & ( int ) ( (byte[]) tlv.value)[0] ) ;
+        assertNotNull( tlv.valueChunk ) ;
+        assertEquals( 0x0055, 0x00ff & tlv.valueChunk.get( 0 ) ) ;
 
     
         // decode tag
@@ -100,8 +102,8 @@
         tlv = decode( "01010101" ) ;
         assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
         assertEquals( 2, tlvList.size() ) ;
-        assertNotNull( tlv.value ) ;
-        assertEquals( 0x0055, 0x00ff & ( int ) ( (byte[]) tlv.value)[0] ) ;
+        assertNotNull( tlv.valueChunk ) ;
+        assertEquals( 0x0055, 0x00ff & tlv.valueChunk.get( 0 ) ) ;
 
     
         // decode tag
@@ -121,8 +123,8 @@
         tlv = decode( "01010101" ) ;
         assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
         assertEquals( 3, tlvList.size() ) ;
-        assertNotNull( tlv.value ) ;
-        assertEquals( 0x0055, 0x00ff & ( int ) ( (byte[]) tlv.value)[0] ) ;
+        assertNotNull( tlv.valueChunk ) ;
+        assertEquals( 0x0055, 0x00ff & tlv.valueChunk.get( 0 ) ) ;
     }
 
 
@@ -150,13 +152,13 @@
                 + "01010101" + "01010101" + "01010101" ) ;
         assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
         assertEquals( 1, tlvList.size() ) ;
-        assertNotNull( tlv.value ) ;
-        assertEquals( 7, ((byte[]) tlv.value).length) ;
+        assertNotNull( tlv.valueChunk ) ;
+        assertEquals( 7, tlv.valueChunk.capacity() ) ;
         
-        byte[] value = (byte[]) tlv.value ;
+        ByteBuffer value = tlv.valueChunk.duplicate() ;
         for ( int ii = 0 ; ii < 7; ii++ )
         {    
-            assertEquals( 0x0055, 0x00ff & ( int ) value[ii] ) ;
+            assertEquals( 0x0055, 0x00ff & value.get( ii ) ) ;
         }
     }
 }

Modified: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/SingleByteLengthTests.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/SingleByteLengthTests.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/SingleByteLengthTests.java	Fri Mar 26 17:29:48 2004
@@ -41,10 +41,10 @@
     {
         Tuple tlv = decode( "00000000" + "01000001" ) ;
         assertEquals( 1, tlv.id ) ;
-        assertEquals( 0, tlvList.size() ) ;
+        assertEquals( 1, tlvList.size() ) ;
         assertEquals( true, tlv.isPrimitive ) ;
         assertEquals( TypeClass.APPLICATION, tlv.typeClass ) ;
-        assertEquals( BERDecoderState.VALUE, decoder.getState() ) ;
+        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
         assertEquals( 0, tlv.length ) ;
     }
 

Modified: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/TagTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/TagTest.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/TagTest.java	Fri Mar 26 17:29:48 2004
@@ -18,7 +18,6 @@
 
 
 import org.apache.commons.lang.ArrayUtils ;
-import org.apache.commons.codec.binary.Binary ;
 import org.apache.commons.collections.primitives.ArrayByteList ;
 
 import junit.framework.TestCase ;
@@ -34,6 +33,14 @@
 public class TagTest extends TestCase
 {
 
+    private static final int BIT_7 = 0x80;
+    private static final int BIT_6 = 0x40;
+    private static final int BIT_4 = 0x10;
+    private static final int BIT_3 = 0x08;
+    private static final int BIT_2 = 0x04;
+    private static final int BIT_1 = 0x02;
+    private static final int BIT_0 = 0x01;
+    private static final int BIT_5 = 0x20;
     public static void main(String[] args)
     {
         junit.textui.TestRunner.run(TagTest.class);
@@ -72,37 +79,37 @@
     
     public void testIsPrimitive() throws Exception
     {
-        byte octet = Binary.BIT_5 ;
+        byte octet = BIT_5 ;
         
         assertFalse( Tag.isPrimitive( octet ) ) ;
-        assertFalse( Tag.isPrimitive( Binary.BIT_5 ) ) ;
+        assertFalse( Tag.isPrimitive( BIT_5 ) ) ;
         
         assertTrue( Tag.isPrimitive( 0 ) ) ;
-        assertTrue( Tag.isPrimitive( Binary.BIT_0 ) ) ;
-        assertTrue( Tag.isPrimitive( Binary.BIT_1 ) ) ;
-        assertTrue( Tag.isPrimitive( Binary.BIT_2 ) ) ;
-        assertTrue( Tag.isPrimitive( Binary.BIT_3 ) ) ;
-        assertTrue( Tag.isPrimitive( Binary.BIT_4 ) ) ;
-        assertTrue( Tag.isPrimitive( Binary.BIT_6 ) ) ;
-        assertTrue( Tag.isPrimitive( Binary.BIT_7 ) ) ;
+        assertTrue( Tag.isPrimitive( BIT_0 ) ) ;
+        assertTrue( Tag.isPrimitive( BIT_1 ) ) ;
+        assertTrue( Tag.isPrimitive( BIT_2 ) ) ;
+        assertTrue( Tag.isPrimitive( BIT_3 ) ) ;
+        assertTrue( Tag.isPrimitive( BIT_4 ) ) ;
+        assertTrue( Tag.isPrimitive( BIT_6 ) ) ;
+        assertTrue( Tag.isPrimitive( BIT_7 ) ) ;
     }
 
 
     public void testIsConstructed() throws Exception
     {
-        byte octet = Binary.BIT_5 ;
+        byte octet = BIT_5 ;
         
         assertTrue( Tag.isConstructed( octet ) ) ;
-        assertTrue( Tag.isConstructed( Binary.BIT_5 ) ) ;
+        assertTrue( Tag.isConstructed( BIT_5 ) ) ;
         
         assertFalse( Tag.isConstructed( 0 ) ) ;
-        assertFalse( Tag.isConstructed( Binary.BIT_0 ) ) ;
-        assertFalse( Tag.isConstructed( Binary.BIT_1 ) ) ;
-        assertFalse( Tag.isConstructed( Binary.BIT_2 ) ) ;
-        assertFalse( Tag.isConstructed( Binary.BIT_3 ) ) ;
-        assertFalse( Tag.isConstructed( Binary.BIT_4 ) ) ;
-        assertFalse( Tag.isConstructed( Binary.BIT_6 ) ) ;
-        assertFalse( Tag.isConstructed( Binary.BIT_7 ) ) ;
+        assertFalse( Tag.isConstructed( BIT_0 ) ) ;
+        assertFalse( Tag.isConstructed( BIT_1 ) ) ;
+        assertFalse( Tag.isConstructed( BIT_2 ) ) ;
+        assertFalse( Tag.isConstructed( BIT_3 ) ) ;
+        assertFalse( Tag.isConstructed( BIT_4 ) ) ;
+        assertFalse( Tag.isConstructed( BIT_6 ) ) ;
+        assertFalse( Tag.isConstructed( BIT_7 ) ) ;
     }
     
     

Modified: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/TupleTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/TupleTest.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/TupleTest.java	Fri Mar 26 17:29:48 2004
@@ -18,6 +18,8 @@
 
 
 import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collections;
 
 import org.apache.commons.lang.ArrayUtils ;
 import org.apache.commons.codec.binary.Binary ;
@@ -34,6 +36,20 @@
  */
 public class TupleTest extends TestCase
 {
+    /** precalculated left shift of 1 by 14 places */
+    private static final int BIT_13 = 1 << 14 ;
+    /** precalculated left shift of 1 by 16 places */
+    private static final int BIT_15 = 1 << 16 ;
+    /** precalculated left shift of 1 by 21 places */
+    private static final int BIT_20 = 1 << 21 ;
+    /** precalculated left shift of 1 by 24 places */
+    private static final int BIT_23 = 1 << 24 ;
+    /** precalculated left shift of 1 by 28 places */
+    private static final int BIT_27 = 1 << 28 ;
+
+    /** for convenience in handling nulls */
+    private static final ByteBuffer EMPTY_BUFFER =
+        ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ;
 
     public static void main(String[] args)
     {
@@ -118,169 +134,6 @@
     /*
      * Class to test for void Tuple(int, int, TypeClass, boolean, byte[])
      */
-    public void testTupleintTypeClassbooleanbyteArray()
-    {
-        Tuple t = new Tuple( 2, TypeClass.PRIVATE, true, 
-                ArrayUtils.EMPTY_BYTE_ARRAY ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.PRIVATE, t.getTypeClass() ) ;
-        assertEquals( true, t.isPrimitive() ) ;
-        assertEquals( 0, t.getLength() ) ;
-        assertEquals( ArrayUtils.EMPTY_BYTE_ARRAY, t.getValue() ) ;
-
-        t = new Tuple( 2, TypeClass.PRIVATE, true, (byte[]) null ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.PRIVATE, t.getTypeClass() ) ;
-        assertEquals( true, t.isPrimitive() ) ;
-        assertEquals( 0, t.getLength() ) ;
-        assertEquals( ArrayUtils.EMPTY_BYTE_ARRAY, t.getValue() ) ;
-
-        byte[] bites = new byte[7] ;
-        t = new Tuple( 2, (TypeClass) null, false, bites ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( false, t.isPrimitive() ) ;
-        assertEquals( 7, t.getLength() ) ;
-        assertEquals( bites, t.getValue() ) ;
-        
-        t = new Tuple( 2, null, false, (byte[]) null ) ; 
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( false, t.isPrimitive() ) ;
-        assertEquals( 0, t.getLength() ) ;
-        assertEquals( ArrayUtils.EMPTY_BYTE_ARRAY, t.getValue() ) ;
-    }
-
-    /*
-     * Class to test for void Tuple(int, int, TypeClass, boolean, byte[])
-     */
-    public void testTupleintTypeClassbooleanBuffer()
-    {
-        Tuple t = new Tuple( 2, TypeClass.PRIVATE, true, 
-                ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.PRIVATE, t.getTypeClass() ) ;
-        assertEquals( true, t.isPrimitive() ) ;
-        assertEquals( 0, t.getLength() ) ;
-        assertEquals( ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ), 
-                t.getValue() ) ;
-
-        t = new Tuple( 2, TypeClass.PRIVATE, true, (ByteBuffer) null ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.PRIVATE, t.getTypeClass() ) ;
-        assertEquals( true, t.isPrimitive() ) ;
-        assertEquals( 0, t.getLength() ) ;
-        assertEquals( ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ), 
-                t.getValue() ) ;
-
-        ByteBuffer bites = ByteBuffer.allocate( 7 ) ;
-        t = new Tuple( 2, (TypeClass) null, false, bites ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( false, t.isPrimitive() ) ;
-        assertEquals( 7, t.getLength() ) ;
-        assertEquals( bites, t.getValue() ) ;
-        
-        t = new Tuple( 2, null, false, (ByteBuffer) null ) ; 
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( false, t.isPrimitive() ) ;
-        assertEquals( 0, t.getLength() ) ;
-        assertEquals( ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ), 
-                t.getValue() ) ;
-    }
-
-    /*
-     * Class to test for void Tuple(int, int, TypeClass, boolean, byte[])
-     */
-    public void testTupleintbyteArray()
-    {
-        Tuple t = new Tuple( 2, ArrayUtils.EMPTY_BYTE_ARRAY ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( true, t.isPrimitive() ) ;
-        assertEquals( 0, t.getLength() ) ;
-        assertEquals( ArrayUtils.EMPTY_BYTE_ARRAY, t.getValue() ) ;
-        
-        byte[] bites = new byte[5] ;
-        t = new Tuple( 2, bites ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( true, t.isPrimitive() ) ;
-        assertEquals( 5, t.getLength() ) ;
-        assertEquals( bites, t.getValue() ) ;
-    }
-
-    /*
-     * Class to test for void Tuple(int, int, TypeClass, boolean, byte[])
-     */
-    public void testTupleintBuffer()
-    {
-        Tuple t = new Tuple( 2, 
-                ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( true, t.isPrimitive() ) ;
-        assertEquals( 0, t.getLength() ) ;
-        assertEquals( ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ), 
-                t.getValue() ) ;
-        
-        ByteBuffer bites = ByteBuffer.allocate( 5 ) ;
-        t = new Tuple( 2, bites ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( true, t.isPrimitive() ) ;
-        assertEquals( 5, t.getLength() ) ;
-        assertEquals( bites, t.getValue() ) ;
-    }
-
-    /*
-     * Class to test for void Tuple(int, int, TypeClass, boolean, byte[])
-     */
-    public void testTupleintbooleanbyteArray()
-    {
-        Tuple t = new Tuple( 2, false, ArrayUtils.EMPTY_BYTE_ARRAY ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( false, t.isPrimitive() ) ;
-        assertEquals( 0, t.getLength() ) ;
-        assertEquals( ArrayUtils.EMPTY_BYTE_ARRAY, t.getValue() ) ;
-        
-        byte[] bites = new byte[5] ;
-        t = new Tuple( 2, false, bites ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( false, t.isPrimitive() ) ;
-        assertEquals( 5, t.getLength() ) ;
-        assertEquals( bites, t.getValue() ) ;
-    }
-
-    /*
-     * Class to test for void Tuple(int, int, TypeClass, boolean, byte[])
-     */
-    public void testTupleintbooleanBuffer()
-    {
-        Tuple t = new Tuple( 2, false, 
-                ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( false, t.isPrimitive() ) ;
-        assertEquals( 0, t.getLength() ) ;
-        assertEquals( ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ), 
-                t.getValue() ) ;
-        
-        ByteBuffer bites = ByteBuffer.allocate( 5 ) ;
-        t = new Tuple( 2, false, bites ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( false, t.isPrimitive() ) ;
-        assertEquals( 5, t.getLength() ) ;
-        assertEquals( bites, t.getValue() ) ;
-    }
-
-    /*
-     * Class to test for void Tuple(int, int, TypeClass, boolean, byte[])
-     */
     public void testTupleintTypeClass()
     {
         Tuple t = new Tuple( 2, TypeClass.PRIVATE ) ;
@@ -288,14 +141,14 @@
         assertEquals( TypeClass.PRIVATE, t.getTypeClass() ) ;
         assertEquals( false, t.isPrimitive() ) ;
         assertEquals( Length.INDEFINATE, t.getLength() ) ;
-        assertEquals( ArrayUtils.EMPTY_BYTE_ARRAY, t.getValue() ) ;
+        assertEquals( EMPTY_BUFFER, t.getLastValueChunk() ) ;
 
         t = new Tuple( 2, (TypeClass) null ) ;
         assertEquals( 2, t.getId() ) ;
         assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
         assertEquals( false, t.isPrimitive() ) ;
         assertEquals( Length.INDEFINATE, t.getLength() ) ;
-        assertEquals( ArrayUtils.EMPTY_BYTE_ARRAY, t.getValue() ) ;
+        assertEquals( EMPTY_BUFFER, t.getLastValueChunk() ) ;
     }
 
     public void testGetId()
@@ -387,14 +240,13 @@
     public void testGetValue()
     {
         Tuple t = new Tuple() ;
-        assertEquals( ArrayUtils.EMPTY_BYTE_ARRAY, t.getValue() ) ;
+        assertEquals( EMPTY_BUFFER, t.getLastValueChunk() ) ;
         byte[] bites = {1, 2, 3, 45} ;
-        t.value = bites ;
-        assertEquals( bites, t.getValue() ) ;
+        t.valueChunk = ByteBuffer.wrap( bites ) ;
+        assertEquals( ByteBuffer.wrap( bites ), t.getLastValueChunk() ) ;
         byte[] bites2 = {1, 2, 3, 45} ;
-        assertFalse( bites2 == t.getValue() ) ;
         t.clear() ;
-        assertEquals( ArrayUtils.EMPTY_BYTE_ARRAY, t.getValue() ) ;
+        assertEquals( EMPTY_BUFFER, t.getLastValueChunk() ) ;
     }
 
     public void testClear()
@@ -425,10 +277,10 @@
         t.clear() ;
         assertEquals( TypeClass.APPLICATION, t.typeClass ) ;
 
-        t.value = new byte[3] ;
-        assertNotNull( t.value ) ;
+        t.valueChunk = ByteBuffer.allocate( 3 ) ;
+        assertNotNull( t.valueChunk ) ;
         t.clear() ;
-        assertEquals( ArrayUtils.EMPTY_BYTE_ARRAY, t.value ) ;
+        assertEquals( EMPTY_BUFFER, t.valueChunk ) ;
 
         t.valueIndex = 12 ;
         assertEquals( 12, t.valueIndex ) ;
@@ -443,9 +295,9 @@
     public void testEqualsObject()
     {
         Tuple tnull0 = new Tuple() ;
-        tnull0.value = null ;
+        tnull0.valueChunk = null ;
         Tuple tnull1 = new Tuple() ;
-        tnull1.value = null ;
+        tnull1.valueChunk = null ;
         tnull0.equals( tnull1 ) ;
         
         tnull1.equals( tnull1 ) ;
@@ -491,9 +343,12 @@
         t1 = ( Tuple ) t0.clone() ;
         assertTrue( t0.equals( t1 ) ) ;
 
-        t0.value = new byte[4] ;
-        t1.value = null ;
-        assertFalse( t0.equals( t1 ) ) ;
+        t0.valueChunk = ByteBuffer.allocate( 4 ) ;
+        t1.valueChunk = null ;
+        
+        // The buffer does not factor into equality
+        assertTrue( t0.equals( t1 ) ) ;
+        
         t1 = ( Tuple ) t0.clone() ;
         assertTrue( t0.equals( t1 ) ) ;
 
@@ -509,229 +364,6 @@
         assertTrue( t.equals( t.clone() ) ) ;
     }
 
-    public void testToEncodedArrayConstructed()
-    {
-        Tuple t = null ;
-        byte[] encoded ;
-        String binary ;
-        
-        t = new Tuple( 0, 0 ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000000" +
-                "01100000"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        t = new Tuple( 2, 0 ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000000" +
-                "01100010"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        t = new Tuple( 30, 0 ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000000" +
-                "01111110"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        t = new Tuple( 31, 0 ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000000" +
-                "00011111" +
-                "01111111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        t = new Tuple( 128, 0 ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000000" +
-                "00000001" +
-                "10000000" +
-                "01111111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        t = new Tuple( 128, 127 ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "01111111" +
-                "00000001" +
-                "10000000" +
-                "01111111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        t = new Tuple( 128, 128 ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "10000000" +
-                "10000001" +
-                "00000001" +
-                "10000000" +
-                "01111111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        t = new Tuple( 128, 255 ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "11111111" +
-                "10000001" +
-                "00000001" +
-                "10000000" +
-                "01111111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        t = new Tuple( 128, 256 ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000001" +
-                "00000000" +
-                "10000010" +
-                "00000001" +
-                "10000000" +
-                "01111111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        t = new Tuple( Tuple.BIT_27-1, Integer.MAX_VALUE ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( Binary.toAsciiString( Integer.MAX_VALUE ) + 
-                "10000100" +
-                "01111111" +
-                "11111111" +
-                "11111111" +
-                "11111111" +
-                "01111111"
-                , Binary.toAsciiString( encoded ) ) ;
-    }
-
-    public void testToEncodedArrayPrimitive()
-    {
-        Tuple t = null ;
-        byte[] encoded ;
-        byte[] data ;
-        String binary ;
-        
-        data = new byte[0] ;
-        t = new Tuple( 0, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000000" +
-                "01000000"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        data = new byte[0] ;
-        t = new Tuple( 2, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000000" +
-                "01000010"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        data = new byte[0] ;
-        t = new Tuple( 30, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000000" +
-                "01011110"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        data = new byte[0] ;
-        t = new Tuple( 31, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000000" +
-                "00011111" +
-                "01011111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        data = new byte[0] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000000" +
-                "00000001" +
-                "10000000" +
-                "01011111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        data = new byte[1] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000000" +
-                "00000001" +
-                "00000001" +
-                "10000000" +
-                "01011111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        data = new byte[127] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( Binary.toAsciiString( data ) +
-                "01111111" +
-                "00000001" +
-                "10000000" +
-                "01011111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        data = new byte[128] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( Binary.toAsciiString( data ) +
-                "10000000" +
-                "10000001" +
-                "00000001" +
-                "10000000" +
-                "01011111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        data = new byte[255] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( Binary.toAsciiString( data ) +
-                "11111111" +
-                "10000001" +
-                "00000001" +
-                "10000000" +
-                "01011111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        data = new byte[256] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( Binary.toAsciiString( data ) + 
-                "00000001" +
-                "00000000" +
-                "10000010" +
-                "00000001" +
-                "10000000" +
-                "01011111"
-                , Binary.toAsciiString( encoded ) ) ;
-    }
-
-    
     public void testToEncodedBufferConstructed()
     {
         Tuple t = null ;
@@ -739,7 +371,7 @@
         String binary ;
         
         t = new Tuple( 0, 0 ) ;
-        encoded = t.toEncodedBuffer() ;
+        encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000000" +
@@ -747,7 +379,7 @@
                 , toAsciiString( encoded ) ) ;
 
         t = new Tuple( 2, 0 ) ;
-        encoded = t.toEncodedBuffer() ;
+        encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000000" +
@@ -755,7 +387,7 @@
                 , toAsciiString( encoded ) ) ;
 
         t = new Tuple( 30, 0 ) ;
-        encoded = t.toEncodedBuffer() ;
+        encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000000" +
@@ -763,7 +395,7 @@
                 , toAsciiString( encoded ) ) ;
 
         t = new Tuple( 31, 0 ) ;
-        encoded = t.toEncodedBuffer() ;
+        encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000000" +
@@ -772,7 +404,7 @@
                 , toAsciiString( encoded ) ) ;
 
         t = new Tuple( 128, 0 ) ;
-        encoded = t.toEncodedBuffer() ;
+        encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000000" +
@@ -782,7 +414,9 @@
                 , toAsciiString( encoded ) ) ;
 
         t = new Tuple( 128, 127 ) ;
-        encoded = t.toEncodedBuffer() ;
+        ArrayList list = new ArrayList() ;
+        list.add( ByteBuffer.allocate( 127 ) ) ;
+        encoded = t.toEncodedBuffer( list ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "01111111" +
@@ -792,7 +426,9 @@
                 , toAsciiString( encoded ) ) ;
 
         t = new Tuple( 128, 128 ) ;
-        encoded = t.toEncodedBuffer() ;
+        list.clear() ;
+        list.add( ByteBuffer.allocate( 128 ) ) ;
+        encoded = t.toEncodedBuffer( list ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "10000000" +
@@ -803,7 +439,9 @@
                 , toAsciiString( encoded ) ) ;
 
         t = new Tuple( 128, 255 ) ;
-        encoded = t.toEncodedBuffer() ;
+        list.clear() ;
+        list.add( ByteBuffer.allocate( 255 ) ) ;
+        encoded = t.toEncodedBuffer( list ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "11111111" +
@@ -814,7 +452,9 @@
                 , toAsciiString( encoded ) ) ;
 
         t = new Tuple( 128, 256 ) ;
-        encoded = t.toEncodedBuffer() ;
+        list.clear() ;
+        list.add( ByteBuffer.allocate( 256 ) ) ;
+        encoded = t.toEncodedBuffer( list ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000001" +
@@ -824,18 +464,6 @@
                 "10000000" +
                 "01111111"
                 , toAsciiString( encoded ) ) ;
-
-        t = new Tuple( Tuple.BIT_27-1, Integer.MAX_VALUE ) ;
-        encoded = t.toEncodedBuffer() ;
-        binary = toAsciiString( encoded ) ;
-        assertEquals( Binary.toAsciiString( Integer.MAX_VALUE ) + 
-                "10000100" +
-                "01111111" +
-                "11111111" +
-                "11111111" +
-                "11111111" +
-                "01111111"
-                , toAsciiString( encoded ) ) ;
     }
 
     public void testToEncodedBufferPrimitive()
@@ -845,36 +473,32 @@
         byte[] data ;
         String binary ;
         
-        data = new byte[0] ;
-        t = new Tuple( 0, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedBuffer() ;
+        t = new Tuple( 0, 0, true, TypeClass.APPLICATION ) ;
+        encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000000" +
                 "01000000"
                 , toAsciiString( encoded ) ) ;
 
-        data = new byte[0] ;
-        t = new Tuple( 2, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedBuffer() ;
+        t = new Tuple( 2, 0, true, TypeClass.APPLICATION ) ;
+        encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000000" +
                 "01000010"
                 , toAsciiString( encoded ) ) ;
 
-        data = new byte[0] ;
-        t = new Tuple( 30, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedBuffer() ;
+        t = new Tuple( 30, 0, true, TypeClass.APPLICATION ) ;
+        encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000000" +
                 "01011110"
                 , toAsciiString( encoded ) ) ;
 
-        data = new byte[0] ;
-        t = new Tuple( 31, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedBuffer() ;
+        t = new Tuple( 31, 0, true, TypeClass.APPLICATION ) ;
+        encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000000" +
@@ -882,9 +506,8 @@
                 "01011111"
                 , toAsciiString( encoded ) ) ;
 
-        data = new byte[0] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedBuffer() ;
+        t = new Tuple( 128, 0, true, TypeClass.APPLICATION ) ;
+        encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000000" +
@@ -894,8 +517,10 @@
                 , toAsciiString( encoded ) ) ;
 
         data = new byte[1] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedBuffer() ;
+        t = new Tuple( 128, 1, true, TypeClass.APPLICATION ) ;
+        ArrayList list = new ArrayList() ;
+        list.add( ByteBuffer.wrap( data ) ) ;
+        encoded = t.toEncodedBuffer( list ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000000" +
@@ -906,8 +531,10 @@
                 , toAsciiString( encoded ) ) ;
 
         data = new byte[127] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedBuffer() ;
+        t = new Tuple( 128, 127, true, TypeClass.APPLICATION ) ;
+        list.clear() ;
+        list.add( ByteBuffer.wrap( data ) ) ;
+        encoded = t.toEncodedBuffer( list ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( Binary.toAsciiString( data ) +
                 "01111111" +
@@ -917,8 +544,10 @@
                 , toAsciiString( encoded ) ) ;
 
         data = new byte[128] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedBuffer() ;
+        t = new Tuple( 128, 128, true, TypeClass.APPLICATION ) ;
+        list.clear() ;
+        list.add( ByteBuffer.wrap( data ) ) ;
+        encoded = t.toEncodedBuffer( list ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( Binary.toAsciiString( data ) +
                 "10000000" +
@@ -929,8 +558,10 @@
                 , toAsciiString( encoded ) ) ;
 
         data = new byte[255] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedBuffer() ;
+        t = new Tuple( 128, 255, true, TypeClass.APPLICATION ) ;
+        list.clear() ;
+        list.add( ByteBuffer.wrap( data ) ) ;
+        encoded = t.toEncodedBuffer( list ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( Binary.toAsciiString( data ) +
                 "11111111" +
@@ -941,8 +572,10 @@
                 , toAsciiString( encoded ) ) ;
 
         data = new byte[256] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedBuffer() ;
+        t = new Tuple( 128, 256, true, TypeClass.APPLICATION ) ;
+        list.clear() ;
+        list.add( ByteBuffer.wrap( data ) ) ;
+        encoded = t.toEncodedBuffer( list ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( Binary.toAsciiString( data ) + 
                 "00000001" +
@@ -1001,7 +634,7 @@
         assertEquals( "00000001" + "10000000" + "01111111", binary ) ;
 
         bites = ByteBuffer.allocate( 3 ) ;
-        t = new Tuple( Tuple.BIT_13 - 1, 0 ) ;
+        t = new Tuple( BIT_13 - 1, 0 ) ;
         t.setTag( bites, 3 ) ;
         binary = toAsciiString( bites ) ;
         assertEquals( "01111111" + 
@@ -1009,7 +642,7 @@
                       "01111111", binary ) ;
 
         bites = ByteBuffer.allocate( 4 ) ;
-        t = new Tuple( Tuple.BIT_13, 0 ) ;
+        t = new Tuple( BIT_13, 0 ) ;
         t.setTag( bites, 4 ) ;
         binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
@@ -1018,7 +651,7 @@
                       "01111111", binary ) ;
 
         bites = ByteBuffer.allocate( 4 ) ;
-        t = new Tuple( Tuple.BIT_13 + 1, 0 ) ;
+        t = new Tuple( BIT_13 + 1, 0 ) ;
         t.setTag( bites, 4 ) ;
         binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
@@ -1027,7 +660,7 @@
                       "01111111", binary ) ;
 
         bites = ByteBuffer.allocate( 4 ) ;
-        t = new Tuple( Tuple.BIT_20 - 1, 0 ) ;
+        t = new Tuple( BIT_20 - 1, 0 ) ;
         t.setTag( bites, 4 ) ;
         binary = toAsciiString( bites ) ;
         assertEquals( "01111111" + 
@@ -1036,7 +669,7 @@
                       "01111111", binary ) ;
 
         bites = ByteBuffer.allocate( 5 ) ;
-        t = new Tuple( Tuple.BIT_20, 0 ) ;
+        t = new Tuple( BIT_20, 0 ) ;
         t.setTag( bites, 5 ) ;
         binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
@@ -1046,7 +679,7 @@
                       "01111111", binary ) ;
 
         bites = ByteBuffer.allocate( 5 ) ;
-        t = new Tuple( Tuple.BIT_20 + 1, 0 ) ;
+        t = new Tuple( BIT_20 + 1, 0 ) ;
         t.setTag( bites, 5 ) ;
         binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
@@ -1056,7 +689,7 @@
                       "01111111", binary ) ;
 
         bites = ByteBuffer.allocate( 5 ) ;
-        t = new Tuple( Tuple.BIT_27 - 1, 0 ) ;
+        t = new Tuple( BIT_27 - 1, 0 ) ;
         t.setTag( bites, 5 ) ;
         binary = toAsciiString( bites ) ;
         assertEquals( "01111111" + 
@@ -1066,7 +699,7 @@
                       "01111111", binary ) ;
 
         bites = ByteBuffer.allocate( 6 ) ;
-        t = new Tuple( Tuple.BIT_27, 0 ) ;
+        t = new Tuple( BIT_27, 0 ) ;
         
         try
         {
@@ -1081,110 +714,110 @@
 
     public void testSetTagbyteArrayint()
     {
-        byte[] bites = new byte[1] ;
+        ByteBuffer bites = ByteBuffer.allocate( 1 ) ;
         Tuple t = new Tuple( 0, 0 ) ;
         t.setTag( bites, 1 ) ;
-        String binary = Binary.toAsciiString( bites ) ;
+        String binary = toAsciiString( bites ) ;
         assertEquals( "01100000", binary ) ;
         
-        bites = new byte[1] ;
+        bites = ByteBuffer.allocate( 1 ) ;
         t = new Tuple( 30, 0 ) ;
         t.setTag( bites, 1 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "01111110", binary ) ;
 
-        bites = new byte[1] ;
+        bites = ByteBuffer.allocate( 1 ) ;
         t = new Tuple( 30, 0 ) ;
         t.isPrimitive = true ;
         t.setTag( bites, 1 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "01011110", binary ) ;
 
-        bites = new byte[2] ;
+        bites = ByteBuffer.allocate( 2 ) ;
         t = new Tuple( 31, 0 ) ;
         t.setTag( bites, 2 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00011111" + "01111111", binary ) ;
 
-        bites = new byte[2] ;
+        bites = ByteBuffer.allocate( 2 ) ;
         t = new Tuple( 127, 0 ) ;
         t.setTag( bites, 2 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "01111111" + "01111111", binary ) ;
 
-        bites = new byte[3] ;
+        bites = ByteBuffer.allocate( 3 ) ;
         t = new Tuple( 128, 0 ) ;
         t.setTag( bites, 3 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00000001" + "10000000" + "01111111", binary ) ;
 
-        bites = new byte[3] ;
-        t = new Tuple( Tuple.BIT_13 - 1, 0 ) ;
+        bites = ByteBuffer.allocate( 3 ) ;
+        t = new Tuple( BIT_13 - 1, 0 ) ;
         t.setTag( bites, 3 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "01111111" + 
                       "11111111" + 
                       "01111111", binary ) ;
 
-        bites = new byte[4] ;
-        t = new Tuple( Tuple.BIT_13, 0 ) ;
+        bites = ByteBuffer.allocate( 4 ) ;
+        t = new Tuple( BIT_13, 0 ) ;
         t.setTag( bites, 4 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
                       "10000000" +
                       "10000000" + 
                       "01111111", binary ) ;
 
-        bites = new byte[4] ;
-        t = new Tuple( Tuple.BIT_13 + 1, 0 ) ;
+        bites = ByteBuffer.allocate( 4 ) ;
+        t = new Tuple( BIT_13 + 1, 0 ) ;
         t.setTag( bites, 4 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
                       "10000000" +
                       "10000001" + 
                       "01111111", binary ) ;
 
-        bites = new byte[4] ;
-        t = new Tuple( Tuple.BIT_20 - 1, 0 ) ;
+        bites = ByteBuffer.allocate( 4 ) ;
+        t = new Tuple( BIT_20 - 1, 0 ) ;
         t.setTag( bites, 4 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "01111111" + 
                       "11111111" + 
                       "11111111" + 
                       "01111111", binary ) ;
 
-        bites = new byte[5] ;
-        t = new Tuple( Tuple.BIT_20, 0 ) ;
+        bites = ByteBuffer.allocate( 5 ) ;
+        t = new Tuple( BIT_20, 0 ) ;
         t.setTag( bites, 5 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
                       "10000000" +
                       "10000000" +
                       "10000000" + 
                       "01111111", binary ) ;
 
-        bites = new byte[5] ;
-        t = new Tuple( Tuple.BIT_20 + 1, 0 ) ;
+        bites = ByteBuffer.allocate( 5 ) ;
+        t = new Tuple( BIT_20 + 1, 0 ) ;
         t.setTag( bites, 5 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
                       "10000000" +
                       "10000000" +
                       "10000001" + 
                       "01111111", binary ) ;
 
-        bites = new byte[5] ;
-        t = new Tuple( Tuple.BIT_27 - 1, 0 ) ;
+        bites = ByteBuffer.allocate( 5 ) ;
+        t = new Tuple( BIT_27 - 1, 0 ) ;
         t.setTag( bites, 5 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "01111111" + 
                       "11111111" + 
                       "11111111" + 
                       "11111111" + 
                       "01111111", binary ) ;
 
-        bites = new byte[6] ;
-        t = new Tuple( Tuple.BIT_27, 0 ) ;
+        bites = ByteBuffer.allocate( 6 ) ;
+        t = new Tuple( BIT_27, 0 ) ;
         
         try
         {
@@ -1196,6 +829,19 @@
             assertNotNull( e ) ;
         }
     }
+    
+    
+    String toAsciiString( int raw )
+    {
+        byte[] intBytes = new byte[4] ;
+        intBytes[0] = (byte) ( (int) 0x000000ff & raw ) ;
+        intBytes[1] = (byte) ( (int) ( 0x0000ff00 & raw ) >> 8 ) ;
+        intBytes[2] = (byte) ( (int) ( 0x00ff0000 & raw ) >> 16 ) ;
+        intBytes[3] = (byte) ( (int) ( 0xff000000 & raw ) >> 24 ) ;
+        
+        return Binary.toAsciiString( intBytes ) ;
+    }
+    
 
     public void testSetLengthBuffer()
     {
@@ -1240,7 +886,7 @@
                       "10000010", binary ) ;
         
         bites = ByteBuffer.allocate( 3 ) ;
-        t = new Tuple( 30, Tuple.BIT_15 - 1 ) ;
+        t = new Tuple( 30, BIT_15 - 1 ) ;
         t.setLength( bites, 3 ) ;
         binary = toAsciiString( bites ) ;
         assertEquals( "11111111" +
@@ -1248,7 +894,7 @@
                       "10000010", binary ) ;
         
         bites = ByteBuffer.allocate( 4 ) ;
-        t = new Tuple( 30, Tuple.BIT_15 ) ;
+        t = new Tuple( 30, BIT_15 ) ;
         t.setLength( bites, 4 ) ;
         binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
@@ -1257,7 +903,7 @@
                       "10000011", binary ) ;
         
         bites = ByteBuffer.allocate( 4 ) ;
-        t = new Tuple( 30, Tuple.BIT_15 + 1 ) ;
+        t = new Tuple( 30, BIT_15 + 1 ) ;
         t.setLength( bites, 4 ) ;
         binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
@@ -1266,7 +912,7 @@
                       "10000011", binary ) ;
         
         bites = ByteBuffer.allocate( 4 ) ;
-        t = new Tuple( 30, Tuple.BIT_23 - 1 ) ;
+        t = new Tuple( 30, BIT_23 - 1 ) ;
         t.setLength( bites, 4 ) ;
         binary = toAsciiString( bites ) ;
         assertEquals( "11111111" +
@@ -1275,7 +921,7 @@
                       "10000011", binary ) ;
         
         bites = ByteBuffer.allocate( 5 ) ;
-        t = new Tuple( 30, Tuple.BIT_23 ) ;
+        t = new Tuple( 30, BIT_23 ) ;
         t.setLength( bites, 5 ) ;
         binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
@@ -1285,7 +931,7 @@
                       "10000100", binary ) ;
         
         bites = ByteBuffer.allocate( 5 ) ;
-        t = new Tuple( 30, Tuple.BIT_23 + 1 ) ;
+        t = new Tuple( 30, BIT_23 + 1 ) ;
         t.setLength( bites, 5 ) ;
         binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
@@ -1298,7 +944,7 @@
         t = new Tuple( 30, Integer.MAX_VALUE ) ;
         t.setLength( bites, 5 ) ;
         binary = toAsciiString( bites ) ;
-        assertEquals( Binary.toAsciiString( Integer.MAX_VALUE ) +
+        assertEquals( toAsciiString( Integer.MAX_VALUE ) +
                       "10000100", binary ) ;
         
         
@@ -1318,116 +964,115 @@
 
     public void testSetLengthbyteArrayintint()
     {
-        byte[] bites = new byte[1] ;
+        ByteBuffer bites = ByteBuffer.allocate( 1 ) ;
         Tuple t = new Tuple( 0, 0 ) ;
-        t.setLength( bites, 0, 1 ) ;
-        String binary = Binary.toAsciiString( bites ) ;
+        t.setLength( bites, 1 ) ;
+        String binary = toAsciiString( bites ) ;
         assertEquals( "00000000", binary ) ;
 
-        bites = new byte[1] ;
+        bites = ByteBuffer.allocate( 1 ) ;
         t = new Tuple( 30, 15 ) ;
-        t.setLength( bites, 0, 1 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        t.setLength( bites, 1 ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00001111", binary ) ;
 
-        bites = new byte[1] ;
+        bites = ByteBuffer.allocate( 1 ) ;
         t = new Tuple( 30, 127 ) ;
-        t.setLength( bites, 0, 1 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        t.setLength( bites, 1 ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "01111111", binary ) ;
         
-        bites = new byte[2] ;
+        bites = ByteBuffer.allocate( 2 ) ;
         t = new Tuple( 30, 128 ) ;
-        t.setLength( bites, 0, 2 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        t.setLength( bites, 2 ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "10000000" +
                       "10000001", binary ) ;
         
-        bites = new byte[2] ;
+        bites = ByteBuffer.allocate( 2 ) ;
         t = new Tuple( 30, 255 ) ;
-        t.setLength( bites, 0, 2 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        t.setLength( bites, 2 ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "11111111" +
                       "10000001", binary ) ;
         
-        bites = new byte[3] ;
+        bites = ByteBuffer.allocate( 3 ) ;
         t = new Tuple( 30, 256 ) ;
-        t.setLength( bites, 0, 3 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        t.setLength( bites, 3 ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
                       "00000000" +
                       "10000010", binary ) ;
         
-        bites = new byte[3] ;
-        t = new Tuple( 30, Tuple.BIT_15 - 1 ) ;
-        t.setLength( bites, 0, 3 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        bites = ByteBuffer.allocate( 3 ) ;
+        t = new Tuple( 30, BIT_15 - 1 ) ;
+        t.setLength( bites, 3 ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "11111111" +
                       "11111111" +
                       "10000010", binary ) ;
         
-        bites = new byte[4] ;
-        t = new Tuple( 30, Tuple.BIT_15 ) ;
-        t.setLength( bites, 0, 4 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        bites = ByteBuffer.allocate( 4 ) ;
+        t = new Tuple( 30, BIT_15 ) ;
+        t.setLength( bites, 4 ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
                       "00000000" +
                       "00000000" +
                       "10000011", binary ) ;
         
-        bites = new byte[4] ;
-        t = new Tuple( 30, Tuple.BIT_15 + 1 ) ;
-        t.setLength( bites, 0, 4 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        bites = ByteBuffer.allocate( 4 ) ;
+        t = new Tuple( 30, BIT_15 + 1 ) ;
+        t.setLength( bites, 4 ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
                       "00000000" +
                       "00000001" +
                       "10000011", binary ) ;
         
-        bites = new byte[4] ;
-        t = new Tuple( 30, Tuple.BIT_23 - 1 ) ;
-        t.setLength( bites, 0, 4 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        bites = ByteBuffer.allocate( 4 ) ;
+        t = new Tuple( 30, BIT_23 - 1 ) ;
+        t.setLength( bites, 4 ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "11111111" +
                       "11111111" +
                       "11111111" +
                       "10000011", binary ) ;
         
-        bites = new byte[5] ;
-        t = new Tuple( 30, Tuple.BIT_23 ) ;
-        t.setLength( bites, 0, 5 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        bites = ByteBuffer.allocate( 5 ) ;
+        t = new Tuple( 30, BIT_23 ) ;
+        t.setLength( bites, 5 ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
                       "00000000" +
                       "00000000" +
                       "00000000" +
                       "10000100", binary ) ;
         
-        bites = new byte[5] ;
-        t = new Tuple( 30, Tuple.BIT_23 + 1 ) ;
-        t.setLength( bites, 0, 5 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        bites = ByteBuffer.allocate( 5 ) ;
+        t = new Tuple( 30, BIT_23 + 1 ) ;
+        t.setLength( bites, 5 ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
                       "00000000" +
                       "00000000" +
                       "00000001" +
                       "10000100", binary ) ;
         
-        bites = new byte[5] ;
+        bites = ByteBuffer.allocate( 5 ) ;
         t = new Tuple( 30, Integer.MAX_VALUE ) ;
-        t.setLength( bites, 0, 5 ) ;
-        t.setLength( bites, 0, 5 ) ;
-        binary = Binary.toAsciiString( bites ) ;
-        assertEquals( Binary.toAsciiString( Integer.MAX_VALUE ) +
+        t.setLength( bites, 5 ) ;
+        binary = toAsciiString( bites ) ;
+        assertEquals( toAsciiString( Integer.MAX_VALUE ) +
                       "10000100", binary ) ;
         
         
-        bites = new byte[6] ;
+        bites = ByteBuffer.allocate( 6 ) ;
         t = new Tuple( 30, Integer.MAX_VALUE + 1 ) ;
 
         try
         {
-            t.setLength( bites, 0, 6 ) ;
+            t.setLength( bites, 6 ) ;
             fail( "should never get here due to thrown exception" ) ;
         }
         catch( IllegalArgumentException e ) 
@@ -1453,24 +1098,24 @@
         t.id = 129 ;
         assertEquals( 3, t.getTagLength() ) ;
 
-        t.id = Tuple.BIT_13 - 1 ;
+        t.id = BIT_13 - 1 ;
         assertEquals( 3, t.getTagLength() ) ;
-        t.id = Tuple.BIT_13 ;
+        t.id = BIT_13 ;
         assertEquals( 4, t.getTagLength() ) ;
-        t.id = Tuple.BIT_13 + 100 ;
+        t.id = BIT_13 + 100 ;
         assertEquals( 4, t.getTagLength() ) ;
         
-        t.id = Tuple.BIT_20 - 1 ;
+        t.id = BIT_20 - 1 ;
         assertEquals( 4, t.getTagLength() ) ;
-        t.id = Tuple.BIT_20 ;
+        t.id = BIT_20 ;
         assertEquals( 5, t.getTagLength() ) ;
-        t.id = Tuple.BIT_20 + 100 ;
+        t.id = BIT_20 + 100 ;
         assertEquals( 5, t.getTagLength() ) ;
 
-        t.id = Tuple.BIT_27 - 1 ;
+        t.id = BIT_27 - 1 ;
         assertEquals( 5, t.getTagLength() ) ;
 
-        t.id = Tuple.BIT_27 ;
+        t.id = BIT_27 ;
         
         try
         {
@@ -1496,18 +1141,18 @@
         t.length = 256 ;
         assertEquals( 3, t.getLengthLength() ) ;
 
-        t.length = Tuple.BIT_15 - 1 ;
+        t.length = BIT_15 - 1 ;
         assertEquals( 3, t.getLengthLength() ) ;
-        t.length = Tuple.BIT_15 ;
+        t.length = BIT_15 ;
         assertEquals( 4, t.getLengthLength() ) ;
-        t.length = Tuple.BIT_15 + 100 ;
+        t.length = BIT_15 + 100 ;
         assertEquals( 4, t.getLengthLength() ) ;
         
-        t.length = Tuple.BIT_23 - 1 ;
+        t.length = BIT_23 - 1 ;
         assertEquals( 4, t.getLengthLength() ) ;
-        t.length = Tuple.BIT_23 ;
+        t.length = BIT_23 ;
         assertEquals( 5, t.getLengthLength() ) ;
-        t.length = Tuple.BIT_23 + 100 ;
+        t.length = BIT_23 + 100 ;
         assertEquals( 5, t.getLengthLength() ) ;
 
         t.length = Integer.MAX_VALUE ;

Modified: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/TupleTreeDecoderTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/TupleTreeDecoderTest.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/TupleTreeDecoderTest.java	Fri Mar 26 17:29:48 2004
@@ -20,6 +20,7 @@
 import java.io.ByteArrayOutputStream ;
 
 import java.nio.ByteBuffer ;
+import java.util.Collections ;
 
 import org.apache.commons.codec.stateful.DecoderCallback ;
 import org.apache.commons.codec.stateful.StatefulDecoder ;
@@ -59,24 +60,32 @@
         decoder.setDecoderMonitor( new DecoderMonitorAdapter() ) ;
     }
     
+
+    /** empty byte buffer used for convenience */
+    private static final ByteBuffer EMPTY_BUFFER = 
+        ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ;
     
     public void testTTD2() throws Exception
     {
         TupleTreeDecoder decoder = new TupleTreeDecoder() ;
-        decoder.decode(ByteBuffer.wrap( 
-                        new Tuple( 1, ArrayUtils.EMPTY_BYTE_ARRAY ).toEncodedArray())) ;
-        decoder.decode( ByteBuffer.wrap( new Tuple( 1, 
-                                ArrayUtils.EMPTY_BYTE_ARRAY ).toEncodedArray() ) ) ;
+        Tuple t = new Tuple( 1, 0, true, TypeClass.APPLICATION ) ;
+        ByteBuffer encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
+        decoder.decode( encoded ) ;
+        
+        t = new Tuple( 1, 0, true, TypeClass.APPLICATION ) ;
+        encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
+        decoder.decode( encoded ) ;
     }    
     
 
     public void testTTD4() throws Exception
     {
-        byte[] bites = new Tuple( 1, ArrayUtils.EMPTY_BYTE_ARRAY ).toEncodedArray() ;
-        byte[] shorter = new byte[bites.length-1] ;
-        System.arraycopy( bites, 0, shorter, 0, shorter.length ) ;
-        
-        assertNull( TupleTreeDecoder.treeDecode( ByteBuffer.wrap( shorter ) ) );
+        Tuple t = new Tuple( 1, 0, true, TypeClass.APPLICATION ) ;
+        ByteBuffer encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
+
+        ByteBuffer shorter = ByteBuffer.allocate( encoded.capacity() - 1 ) ;
+        shorter.put( ( ByteBuffer ) encoded.limit( shorter.limit() - 1 ) ) ;
+        assertNull( TupleTreeDecoder.treeDecode( shorter ) ) ;
     }    
     
 
@@ -106,8 +115,6 @@
         StringBuffer buf = new StringBuffer() ;
         root.printDepthFirst( buf, 0 ) ;
         System.out.println( "tuple tlv tree =\n" + buf.toString() ) ;
-        TupleTreeAnalyzer analyzer = new TupleTreeAnalyzer( root ) ;
-        analyzer.startup() ;
     }
     
     

Mime
View raw message