You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2004/11/27 10:35:39 UTC
svn commit: r106700 - in incubator/directory/snickers/trunk/ber-codec/src: java/org/apache/snickers/ber test/org/apache/snickers/ber
Author: akarasulu
Date: Sat Nov 27 01:35:38 2004
New Revision: 106700
URL: http://svn.apache.org/viewcvs?view=rev&rev=106700
Log:
Changes ...
o fixes for major bug http://nagoya.apache.org/jira/browse/DIREVE-87
o fixed Length to now put MSB of long format Length field bytes first in decode
o fixed Tuple to encode MSB of long formmat length field bytes first
o fixed test cases to comply with changes
Modified:
incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/AbstractDecoderTestCase.java
incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Length.java
incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Tuple.java
incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/LengthTest.java
incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/MultiByteLengthTests.java
incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/TupleTest.java
Modified: incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/AbstractDecoderTestCase.java
Url: http://svn.apache.org/viewcvs/incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/AbstractDecoderTestCase.java?view=diff&rev=106700&p1=incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/AbstractDecoderTestCase.java&r1=106699&p2=incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/AbstractDecoderTestCase.java&r2=106700
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/AbstractDecoderTestCase.java (original)
+++ incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/AbstractDecoderTestCase.java Sat Nov 27 01:35:38 2004
@@ -24,7 +24,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
-import org.apache.commons.codec.binary.Binary ;
+import org.apache.commons.codec.binary.BinaryCodec ;
import org.apache.commons.codec.DecoderException ;
import org.apache.commons.codec.stateful.DecoderMonitor ;
import org.apache.commons.codec.stateful.DecoderCallback ;
@@ -207,7 +207,7 @@
*/
public Tuple decode( String bitString ) throws DecoderException
{
- byte [] bites = Binary.fromAscii( bitString.getBytes() ) ;
+ byte [] bites = BinaryCodec.fromAscii( bitString.getBytes() ) ;
ByteBuffer buf = ByteBuffer.wrap( bites ) ;
int lastSize = tlvList.size() ;
decoder.decode( buf ) ;
Modified: incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Length.java
Url: http://svn.apache.org/viewcvs/incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Length.java?view=diff&rev=106700&p1=incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Length.java&r1=106699&p2=incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Length.java&r2=106700
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Length.java (original)
+++ incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Length.java Sat Nov 27 01:35:38 2004
@@ -183,15 +183,19 @@
// using the long form so we calculate the length from all octets
int length = 0 ;
-
- // calculate tag value w/ long tag format
- int shift = 0 ;
- do
+ for ( int ii = octets.remaining(), shift = (ii-1)<<3; ii > 0; ii--, shift -= 8 )
{
length |= ( 0xFF & ( int ) octets.get() ) << shift ;
- shift += 8 ;
}
- while ( octets.hasRemaining() ) ;
+
+ // calculate tag value w/ long tag format
+// int shift = 0 ;
+// do
+// {
+// length |= ( 0xFF & ( int ) octets.get() ) << shift ;
+// shift += 8 ;
+// }
+// while ( octets.hasRemaining() ) ;
return length ;
}
Modified: incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Tuple.java
Url: http://svn.apache.org/viewcvs/incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Tuple.java?view=diff&rev=106700&p1=incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Tuple.java&r1=106699&p2=incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Tuple.java&r2=106700
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Tuple.java (original)
+++ incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Tuple.java Sat Nov 27 01:35:38 2004
@@ -363,7 +363,7 @@
/**
* Gets the total size of this TLV tuple in bytes. This includes the
* length of the tag field, the length of the length field and the length
- * of the value filed.
+ * of the value feild.
*
* @return the total TLV size in bytes
*/
@@ -668,6 +668,14 @@
*/
public void setLength( ByteBuffer octets, int lengthBytes )
{
+ if ( lengthBytes >= 6 )
+ {
+ throw new IllegalArgumentException( "cannot support lengths larger "
+ + "than a max integer using " + lengthBytes
+ + " bytes unless we start using longs or BigIntegers for "
+ + "the length" ) ;
+ }
+
if ( length == Length.INDEFINATE )
{
octets.put( ( byte ) BIT_7 ) ;
@@ -681,59 +689,71 @@
else
{
/*
+ * Here we basically set the first byte of the length field which
+ * is in the long form. In this case the first byte's 7 least
+ * significant bits hold the length of the length field or the
+ * number of bytes used to hold the size of the value. BTW the
+ * first most significant bit is set to 1 to mark the long form and
+ * hence why we bitwise or it with 0x80 which is BIT_7.
+ */
+
+ /*
* 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
+ * 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.
+ * field.
*/
octets.put( ( byte ) ( BIT_7 | ( lengthBytes - 1 ) ) ) ;
}
-
- if ( lengthBytes >= 2 )
- {
- octets.put( ( byte ) ( 0xff & length ) ) ;
- }
- else
- {
- return ;
- }
-
- if ( lengthBytes >= 3 )
- {
- octets.put( ( byte ) ( ( 0xff00 & length ) >> 8 ) ) ;
- }
- else
- {
- return ;
- }
-
- if ( lengthBytes >= 4 )
- {
- octets.put( ( byte ) ( ( 0xff0000 & length ) >> 16 ) ) ;
- }
- else
- {
- return ;
- }
-
- if ( lengthBytes >= 5 )
- {
- octets.put( ( byte ) ( ( 0xff000000 & length ) >> 24 ) ) ;
- }
- else
+
+
+ // using the long form so we calculate the length from all octets
+ for ( int ii = 0, shift = (lengthBytes-2)<<3; ii <= lengthBytes-2; ii++, shift -= 8 )
{
- return ;
+ octets.put( octets.position() + ii, ( byte ) ( ( ( 0xff << shift ) & length ) >> shift ) );
}
+
+ octets.position( octets.position() + lengthBytes - 1 );
+
+// if ( lengthBytes >= 2 )
+// {
+// octets.put( ( byte ) ( 0xff & length ) ) ;
+// }
+// else
+// {
+// return ;
+// }
+//
+// if ( lengthBytes >= 3 )
+// {
+// octets.put( ( byte ) ( ( 0xff00 & length ) >> 8 ) ) ;
+// }
+// else
+// {
+// return ;
+// }
+//
+// if ( lengthBytes >= 4 )
+// {
+// octets.put( ( byte ) ( ( 0xff0000 & length ) >> 16 ) ) ;
+// }
+// else
+// {
+// return ;
+// }
+//
+// 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" ) ;
- }
}
Modified: incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/LengthTest.java
Url: http://svn.apache.org/viewcvs/incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/LengthTest.java?view=diff&rev=106700&p1=incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/LengthTest.java&r1=106699&p2=incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/LengthTest.java&r2=106700
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/LengthTest.java (original)
+++ incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/LengthTest.java Sat Nov 27 01:35:38 2004
@@ -34,15 +34,160 @@
public class LengthTest extends TestCase
{
/**
+ * Tests the long form when a byte is used for the length's length and
+ * another is used for the value length for a total of two bytes for the
+ * length field itself.
+ */
+ public void testLongTwoBytes() throws DecoderException
+ {
+ ByteBuffer list = ByteBuffer.allocate( 2 ) ;
+ list.put( (byte) 0x81 ) ;
+ list.put( (byte) 0x01 ) ;
+ list.flip();
+ assertEquals( 0x01, Length.getLength( list ) );
+
+ list = ByteBuffer.allocate( 2 ) ;
+ list.put( (byte) 0x81 ) ;
+ list.put( (byte) 0x05 ) ;
+ list.flip();
+ assertEquals( 0x05, Length.getLength( list ) );
+
+ list = ByteBuffer.allocate( 2 ) ;
+ list.put( (byte) 0x81 ) ;
+ list.put( (byte) 0xFF ) ;
+ list.flip();
+ assertEquals( 0xFF, Length.getLength( list ) );
+ }
+
+
+ /**
+ * Tests the long form when a byte is used for the length's length and
+ * two more are used for the value length for a total of three bytes for the
+ * length field itself.
+ */
+ public void testLongThreeBytes() throws DecoderException
+ {
+ ByteBuffer list = ByteBuffer.allocate( 3 ) ;
+ list.put( (byte) 0x82 ) ;
+ list.put( (byte) 0x00 ) ;
+ list.put( (byte) 0x01 ) ;
+ list.flip();
+ assertEquals( 0x01, Length.getLength( list ) );
+
+ list = ByteBuffer.allocate( 3 ) ;
+ list.put( (byte) 0x82 ) ;
+ list.put( (byte) 0x00 ) ;
+ list.put( (byte) 0x05 ) ;
+ list.flip();
+ assertEquals( 0x05, Length.getLength( list ) );
+
+ list = ByteBuffer.allocate( 3 ) ;
+ list.put( (byte) 0x82 ) ;
+ list.put( (byte) 0x00 ) ;
+ list.put( (byte) 0xFF ) ;
+ list.flip();
+ assertEquals( 0xFF, Length.getLength( list ) );
+
+ list = ByteBuffer.allocate( 3 ) ;
+ list.put( (byte) 0x82 ) ;
+ list.put( (byte) 0x01 ) ;
+ list.put( (byte) 0x05 ) ;
+ list.flip();
+ assertEquals( 0x0105, Length.getLength( list ) );
+
+ list = ByteBuffer.allocate( 3 ) ;
+ list.put( (byte) 0x82 ) ;
+ list.put( (byte) 0x01 ) ;
+ list.put( (byte) 0xFF ) ;
+ list.flip();
+ assertEquals( 0x01FF, Length.getLength( list ) );
+
+ list = ByteBuffer.allocate( 3 ) ;
+ list.put( (byte) 0x82 ) ;
+ list.put( (byte) 0x80 ) ;
+ list.put( (byte) 0x00 ) ;
+ list.flip();
+ assertEquals( 32768, Length.getLength( list ) );
+ }
+
+
+ /**
+ * Tests the long form when a byte is used for the length's length and
+ * three more are used for the value length for a total of four bytes for
+ * the length field itself.
+ */
+ public void testLongFourBytes() throws DecoderException
+ {
+ ByteBuffer list = ByteBuffer.allocate( 4 ) ;
+ list.put( (byte) 0x83 ) ;
+ list.put( (byte) 0x00 ) ;
+ list.put( (byte) 0x00 ) ;
+ list.put( (byte) 0x01 ) ;
+ list.flip();
+ assertEquals( 0x01, Length.getLength( list ) );
+
+ list = ByteBuffer.allocate( 4 ) ;
+ list.put( (byte) 0x83 ) ;
+ list.put( (byte) 0x00 ) ;
+ list.put( (byte) 0x00 ) ;
+ list.put( (byte) 0x05 ) ;
+ list.flip();
+ assertEquals( 0x05, Length.getLength( list ) );
+
+ list = ByteBuffer.allocate( 4 ) ;
+ list.put( (byte) 0x83 ) ;
+ list.put( (byte) 0x00 ) ;
+ list.put( (byte) 0x00 ) ;
+ list.put( (byte) 0xFF ) ;
+ list.flip();
+ assertEquals( 0xFF, Length.getLength( list ) );
+ }
+
+
+ /**
+ * Tests the long form when a byte is used for the length's length and
+ * four more are used for the value length for a total of five bytes for
+ * the length field itself.
+ */
+ public void testLongFiveBytes() throws DecoderException
+ {
+ ByteBuffer list = ByteBuffer.allocate( 5 ) ;
+ list.put( (byte) 0x84 ) ;
+ list.put( (byte) 0x00 ) ;
+ list.put( (byte) 0x00 ) ;
+ list.put( (byte) 0x00 ) ;
+ list.put( (byte) 0x01 ) ;
+ list.flip();
+ assertEquals( 0x01, Length.getLength( list ) );
+
+ list = ByteBuffer.allocate( 5 ) ;
+ list.put( (byte) 0x84 ) ;
+ list.put( (byte) 0x00 ) ;
+ list.put( (byte) 0x00 ) ;
+ list.put( (byte) 0x00 ) ;
+ list.put( (byte) 0x05 ) ;
+ list.flip();
+ assertEquals( 0x05, Length.getLength( list ) );
+
+ list = ByteBuffer.allocate( 5 ) ;
+ list.put( (byte) 0x84 ) ;
+ list.put( (byte) 0x00 ) ;
+ list.put( (byte) 0x00 ) ;
+ list.put( (byte) 0x00 ) ;
+ list.put( (byte) 0xFF ) ;
+ list.flip();
+ assertEquals( 0xFF, Length.getLength( list ) );
+ }
+
+
+ /**
* Tests to make sure certain length sizes are not allowed. Basically we
* are capping off the length at 2^32-1 which corresponds to 5 total length
* bytes in the long form or the indeterminate form.
*/
public void testMaxLength() throws Exception
{
- ByteBuffer list = ByteBuffer.allocate( 8 ) ;
- list.put( (byte) 0x1 ) ;
- list.put( (byte) 0x1 ) ;
+ ByteBuffer list = ByteBuffer.allocate( 6 ) ;
list.put( (byte) 0x1 ) ;
list.put( (byte) 0x1 ) ;
list.put( (byte) 0x1 ) ;
Modified: incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/MultiByteLengthTests.java
Url: http://svn.apache.org/viewcvs/incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/MultiByteLengthTests.java?view=diff&rev=106700&p1=incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/MultiByteLengthTests.java&r1=106699&p2=incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/MultiByteLengthTests.java&r2=106700
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/MultiByteLengthTests.java (original)
+++ incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/MultiByteLengthTests.java Sat Nov 27 01:35:38 2004
@@ -107,15 +107,15 @@
assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
assertEquals( 0, tlv.length ) ;
- tlv = decode( "10000010" ) ;
+ tlv = decode( (byte)0x82 ) ;
assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
assertEquals( 0, tlv.length ) ;
- tlv = decode( "00000000" ) ;
+ tlv = decode( (byte) 0x80 ) ;
assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
assertEquals( 0, tlv.length ) ;
- tlv = decode( "10000000" ) ;
+ tlv = decode( (byte) 0x00 ) ;
assertEquals( BERDecoderState.VALUE, decoder.getState() ) ;
assertEquals( 32768, tlv.length ) ;
}
Modified: incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/TupleTest.java
Url: http://svn.apache.org/viewcvs/incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/TupleTest.java?view=diff&rev=106700&p1=incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/TupleTest.java&r1=106699&p2=incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/TupleTest.java&r2=106700
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/TupleTest.java (original)
+++ incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/TupleTest.java Sat Nov 27 01:35:38 2004
@@ -22,7 +22,7 @@
import java.util.Collections;
import org.apache.commons.lang.ArrayUtils ;
-import org.apache.commons.codec.binary.Binary ;
+import org.apache.commons.codec.binary.BinaryCodec;
import junit.framework.TestCase ;
@@ -244,7 +244,6 @@
byte[] bites = {1, 2, 3, 45} ;
t.valueChunk = ByteBuffer.wrap( bites ) ;
assertEquals( ByteBuffer.wrap( bites ), t.getLastValueChunk() ) ;
- byte[] bites2 = {1, 2, 3, 45} ;
t.clear() ;
assertEquals( EMPTY_BUFFER, t.getLastValueChunk() ) ;
}
@@ -368,36 +367,31 @@
{
Tuple t = null ;
ByteBuffer encoded ;
- String binary ;
-
+
t = new Tuple( 0, 0 ) ;
encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
- binary = toAsciiString( encoded ) ;
- assertEquals(
+ assertEquals(
"00000000" +
"01100000"
, toAsciiString( encoded ) ) ;
t = new Tuple( 2, 0 ) ;
encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
- binary = toAsciiString( encoded ) ;
- assertEquals(
+ assertEquals(
"00000000" +
"01100010"
, toAsciiString( encoded ) ) ;
t = new Tuple( 30, 0 ) ;
encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
- binary = toAsciiString( encoded ) ;
- assertEquals(
+ assertEquals(
"00000000" +
"01111110"
, toAsciiString( encoded ) ) ;
t = new Tuple( 31, 0 ) ;
encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
- binary = toAsciiString( encoded ) ;
- assertEquals(
+ assertEquals(
"00000000" +
"00011111" +
"01111111"
@@ -405,8 +399,7 @@
t = new Tuple( 128, 0 ) ;
encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
- binary = toAsciiString( encoded ) ;
- assertEquals(
+ assertEquals(
"00000000" +
"00000001" +
"10000000" +
@@ -417,8 +410,7 @@
ArrayList list = new ArrayList() ;
list.add( ByteBuffer.allocate( 127 ) ) ;
encoded = t.toEncodedBuffer( list ) ;
- binary = toAsciiString( encoded ) ;
- assertEquals(
+ assertEquals(
"01111111" +
"00000001" +
"10000000" +
@@ -429,8 +421,7 @@
list.clear() ;
list.add( ByteBuffer.allocate( 128 ) ) ;
encoded = t.toEncodedBuffer( list ) ;
- binary = toAsciiString( encoded ) ;
- assertEquals(
+ assertEquals(
"10000000" +
"10000001" +
"00000001" +
@@ -442,8 +433,7 @@
list.clear() ;
list.add( ByteBuffer.allocate( 255 ) ) ;
encoded = t.toEncodedBuffer( list ) ;
- binary = toAsciiString( encoded ) ;
- assertEquals(
+ assertEquals(
"11111111" +
"10000001" +
"00000001" +
@@ -455,10 +445,9 @@
list.clear() ;
list.add( ByteBuffer.allocate( 256 ) ) ;
encoded = t.toEncodedBuffer( list ) ;
- binary = toAsciiString( encoded ) ;
- assertEquals(
- "00000001" +
+ assertEquals(
"00000000" +
+ "00000001" +
"10000010" +
"00000001" +
"10000000" +
@@ -471,36 +460,31 @@
Tuple t = null ;
ByteBuffer encoded ;
byte[] data ;
- String binary ;
-
+
t = new Tuple( 0, 0, true, TypeClass.APPLICATION ) ;
encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
- binary = toAsciiString( encoded ) ;
- assertEquals(
+ assertEquals(
"00000000" +
"01000000"
, toAsciiString( encoded ) ) ;
t = new Tuple( 2, 0, true, TypeClass.APPLICATION ) ;
encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
- binary = toAsciiString( encoded ) ;
- assertEquals(
+ assertEquals(
"00000000" +
"01000010"
, toAsciiString( encoded ) ) ;
t = new Tuple( 30, 0, true, TypeClass.APPLICATION ) ;
encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
- binary = toAsciiString( encoded ) ;
- assertEquals(
+ assertEquals(
"00000000" +
"01011110"
, toAsciiString( encoded ) ) ;
t = new Tuple( 31, 0, true, TypeClass.APPLICATION ) ;
encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
- binary = toAsciiString( encoded ) ;
- assertEquals(
+ assertEquals(
"00000000" +
"00011111" +
"01011111"
@@ -508,8 +492,7 @@
t = new Tuple( 128, 0, true, TypeClass.APPLICATION ) ;
encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
- binary = toAsciiString( encoded ) ;
- assertEquals(
+ assertEquals(
"00000000" +
"00000001" +
"10000000" +
@@ -521,8 +504,7 @@
ArrayList list = new ArrayList() ;
list.add( ByteBuffer.wrap( data ) ) ;
encoded = t.toEncodedBuffer( list ) ;
- binary = toAsciiString( encoded ) ;
- assertEquals(
+ assertEquals(
"00000000" +
"00000001" +
"00000001" +
@@ -535,8 +517,7 @@
list.clear() ;
list.add( ByteBuffer.wrap( data ) ) ;
encoded = t.toEncodedBuffer( list ) ;
- binary = toAsciiString( encoded ) ;
- assertEquals( Binary.toAsciiString( data ) +
+ assertEquals( BinaryCodec.toAsciiString( data ) +
"01111111" +
"00000001" +
"10000000" +
@@ -548,8 +529,7 @@
list.clear() ;
list.add( ByteBuffer.wrap( data ) ) ;
encoded = t.toEncodedBuffer( list ) ;
- binary = toAsciiString( encoded ) ;
- assertEquals( Binary.toAsciiString( data ) +
+ assertEquals( BinaryCodec.toAsciiString( data ) +
"10000000" +
"10000001" +
"00000001" +
@@ -562,8 +542,7 @@
list.clear() ;
list.add( ByteBuffer.wrap( data ) ) ;
encoded = t.toEncodedBuffer( list ) ;
- binary = toAsciiString( encoded ) ;
- assertEquals( Binary.toAsciiString( data ) +
+ assertEquals( BinaryCodec.toAsciiString( data ) +
"11111111" +
"10000001" +
"00000001" +
@@ -576,10 +555,9 @@
list.clear() ;
list.add( ByteBuffer.wrap( data ) ) ;
encoded = t.toEncodedBuffer( list ) ;
- binary = toAsciiString( encoded ) ;
- assertEquals( Binary.toAsciiString( data ) +
- "00000001" +
+ assertEquals( BinaryCodec.toAsciiString( data ) +
"00000000" +
+ "00000001" +
"10000010" +
"00000001" +
"10000000" +
@@ -590,7 +568,7 @@
public String toAsciiString( ByteBuffer buf )
{
- return Binary.toAsciiString( buf.array() ) ;
+ return BinaryCodec.toAsciiString( buf.array() ) ;
}
@@ -839,7 +817,7 @@
intBytes[2] = (byte) ( (int) ( 0x00ff0000 & raw ) >> 16 ) ;
intBytes[3] = (byte) ( (int) ( 0xff000000 & raw ) >> 24 ) ;
- return Binary.toAsciiString( intBytes ) ;
+ return BinaryCodec.toAsciiString( intBytes ) ;
}
@@ -862,74 +840,64 @@
t.setLength( bites, 1 ) ;
binary = toAsciiString( bites ) ;
assertEquals( "01111111", binary ) ;
-
+
bites = ByteBuffer.allocate( 2 ) ;
t = new Tuple( 30, 128 ) ;
t.setLength( bites, 2 ) ;
binary = toAsciiString( bites ) ;
- assertEquals( "10000000" +
- "10000001", binary ) ;
-
+ assertEquals( "10000000" + "10000001", binary ) ;
+
bites = ByteBuffer.allocate( 2 ) ;
t = new Tuple( 30, 255 ) ;
t.setLength( bites, 2 ) ;
binary = toAsciiString( bites ) ;
- assertEquals( "11111111" +
- "10000001", binary ) ;
-
+ assertEquals( "11111111" + "10000001", binary ) ;
+
bites = ByteBuffer.allocate( 3 ) ;
t = new Tuple( 30, 256 ) ;
t.setLength( bites, 3 ) ;
binary = toAsciiString( bites ) ;
- assertEquals( "00000001" +
- "00000000" +
- "10000010", binary ) ;
-
+ assertEquals( "00000000" + "00000001" + "10000010", binary ) ;
+
bites = ByteBuffer.allocate( 3 ) ;
t = new Tuple( 30, BIT_15 - 1 ) ;
t.setLength( bites, 3 ) ;
binary = toAsciiString( bites ) ;
assertEquals( "11111111" +
- "11111111" +
- "10000010", binary ) ;
-
+ "11111111" + "10000010", binary ) ;
+
bites = ByteBuffer.allocate( 4 ) ;
t = new Tuple( 30, BIT_15 ) ;
t.setLength( bites, 4 ) ;
binary = toAsciiString( bites ) ;
- assertEquals( "00000001" +
- "00000000" +
- "00000000" +
- "10000011", binary ) ;
-
+ assertEquals( "00000000" + "00000000" + "00000001" + "10000011", binary ) ;
+
bites = ByteBuffer.allocate( 4 ) ;
t = new Tuple( 30, BIT_15 + 1 ) ;
t.setLength( bites, 4 ) ;
binary = toAsciiString( bites ) ;
assertEquals( "00000001" +
"00000000" +
- "00000001" +
- "10000011", binary ) ;
-
+ "00000001" + "10000011", binary ) ;
+
bites = ByteBuffer.allocate( 4 ) ;
t = new Tuple( 30, BIT_23 - 1 ) ;
t.setLength( bites, 4 ) ;
binary = toAsciiString( bites ) ;
assertEquals( "11111111" +
"11111111" +
- "11111111" +
- "10000011", binary ) ;
-
+ "11111111" + "10000011", binary ) ;
+
bites = ByteBuffer.allocate( 5 ) ;
t = new Tuple( 30, BIT_23 ) ;
t.setLength( bites, 5 ) ;
binary = toAsciiString( bites ) ;
- assertEquals( "00000001" +
- "00000000" +
+ assertEquals( "00000000" +
"00000000" +
"00000000" +
+ "00000001" +
"10000100", binary ) ;
-
+
bites = ByteBuffer.allocate( 5 ) ;
t = new Tuple( 30, BIT_23 + 1 ) ;
t.setLength( bites, 5 ) ;
@@ -937,17 +905,18 @@
assertEquals( "00000001" +
"00000000" +
"00000000" +
- "00000001" +
- "10000100", binary ) ;
-
+ "00000001" + "10000100", binary ) ;
+
bites = ByteBuffer.allocate( 5 ) ;
t = new Tuple( 30, Integer.MAX_VALUE ) ;
t.setLength( bites, 5 ) ;
binary = toAsciiString( bites ) ;
- assertEquals( toAsciiString( Integer.MAX_VALUE ) +
- "10000100", binary ) ;
-
-
+ assertEquals( "11111111" +
+ "11111111" +
+ "11111111" +
+ "01111111" + "10000100", binary ) ;
+
+
bites = ByteBuffer.allocate( 6 ) ;
t = new Tuple( 30, Integer.MAX_VALUE + 1 ) ;
@@ -956,7 +925,7 @@
t.setLength( bites, 6 ) ;
fail( "should never get here due to thrown exception" ) ;
}
- catch( IllegalArgumentException e )
+ catch( IllegalArgumentException e )
{
assertNotNull( e ) ;
}
@@ -981,74 +950,62 @@
t.setLength( bites, 1 ) ;
binary = toAsciiString( bites ) ;
assertEquals( "01111111", binary ) ;
-
+
bites = ByteBuffer.allocate( 2 ) ;
t = new Tuple( 30, 128 ) ;
t.setLength( bites, 2 ) ;
binary = toAsciiString( bites ) ;
- assertEquals( "10000000" +
- "10000001", binary ) ;
-
+ assertEquals( "10000000" + "10000001", binary ) ;
+
bites = ByteBuffer.allocate( 2 ) ;
t = new Tuple( 30, 255 ) ;
t.setLength( bites, 2 ) ;
binary = toAsciiString( bites ) ;
- assertEquals( "11111111" +
- "10000001", binary ) ;
-
+ assertEquals( "11111111" + "10000001", binary ) ;
+
bites = ByteBuffer.allocate( 3 ) ;
t = new Tuple( 30, 256 ) ;
t.setLength( bites, 3 ) ;
binary = toAsciiString( bites ) ;
- assertEquals( "00000001" +
- "00000000" +
- "10000010", binary ) ;
-
+ assertEquals( "00000000" +
+ "00000001" + "10000010", binary ) ;
+
bites = ByteBuffer.allocate( 3 ) ;
t = new Tuple( 30, BIT_15 - 1 ) ;
t.setLength( bites, 3 ) ;
binary = toAsciiString( bites ) ;
- assertEquals( "11111111" +
- "11111111" +
- "10000010", binary ) ;
-
+ assertEquals( "11111111" + "11111111" + "10000010", binary ) ;
+
bites = ByteBuffer.allocate( 4 ) ;
t = new Tuple( 30, BIT_15 ) ;
t.setLength( bites, 4 ) ;
binary = toAsciiString( bites ) ;
- assertEquals( "00000001" +
- "00000000" +
- "00000000" +
- "10000011", binary ) ;
-
+ assertEquals( "00000000" + "00000000" +
+ "00000001" + "10000011", binary ) ;
+
bites = ByteBuffer.allocate( 4 ) ;
t = new Tuple( 30, BIT_15 + 1 ) ;
t.setLength( bites, 4 ) ;
binary = toAsciiString( bites ) ;
- assertEquals( "00000001" +
- "00000000" +
- "00000001" +
- "10000011", binary ) ;
-
+ assertEquals( "00000001" + "00000000" +
+ "00000001" + "10000011", binary ) ;
+
bites = ByteBuffer.allocate( 4 ) ;
t = new Tuple( 30, BIT_23 - 1 ) ;
t.setLength( bites, 4 ) ;
binary = toAsciiString( bites ) ;
- assertEquals( "11111111" +
- "11111111" +
- "11111111" +
- "10000011", binary ) ;
-
+ assertEquals( "11111111" + "11111111" +
+ "11111111" + "10000011", binary ) ;
+
bites = ByteBuffer.allocate( 5 ) ;
t = new Tuple( 30, BIT_23 ) ;
t.setLength( bites, 5 ) ;
binary = toAsciiString( bites ) ;
- assertEquals( "00000001" +
- "00000000" +
+ assertEquals( "00000000" +
"00000000" +
"00000000" +
- "10000100", binary ) ;
-
+ "00000001" + "10000100", binary ) ;
+
bites = ByteBuffer.allocate( 5 ) ;
t = new Tuple( 30, BIT_23 + 1 ) ;
t.setLength( bites, 5 ) ;
@@ -1056,17 +1013,18 @@
assertEquals( "00000001" +
"00000000" +
"00000000" +
- "00000001" +
- "10000100", binary ) ;
-
+ "00000001" + "10000100", binary ) ;
+
bites = ByteBuffer.allocate( 5 ) ;
t = new Tuple( 30, Integer.MAX_VALUE ) ;
t.setLength( bites, 5 ) ;
binary = toAsciiString( bites ) ;
- assertEquals( toAsciiString( Integer.MAX_VALUE ) +
- "10000100", binary ) ;
-
-
+ assertEquals( "11111111" +
+ "11111111" +
+ "11111111" +
+ "01111111" + "10000100", binary ) ;
+
+
bites = ByteBuffer.allocate( 6 ) ;
t = new Tuple( 30, Integer.MAX_VALUE + 1 ) ;
@@ -1075,7 +1033,7 @@
t.setLength( bites, 6 ) ;
fail( "should never get here due to thrown exception" ) ;
}
- catch( IllegalArgumentException e )
+ catch( IllegalArgumentException e )
{
assertNotNull( e ) ;
}