You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ad...@apache.org on 2005/02/16 19:57:33 UTC
svn commit: r154063 [2/3] - in
incubator/directory/asn1/branches/ber-decoder/modules: ber/ ber/xdocs/
codec/ codec/src/docbook/ codec/src/images/ compiler/ der/ runtime/
runtime/src/java/org/apache/snickers/encoding/
runtime/src/java/org/apache/snickers/encoding/ber/
runtime/src/java/org/apache/snickers/runtime/
runtime/src/test/com/acme/spnego/ runtime/src/test/com/acme/spnego/ber/
runtime/src/test/org/apache/snickers/encoding/ber/
Modified: incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/ContextFlagsEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/ContextFlagsEncoder.java?view=diff&r1=154062&r2=154063
==============================================================================
--- incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/ContextFlagsEncoder.java (original)
+++ incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/ContextFlagsEncoder.java Wed Feb 16 10:57:26 2005
@@ -16,31 +16,29 @@
*/
package com.acme.spnego.ber;
-import java.io.OutputStream;
-
-import org.apache.snickers.encoding.EncoderException;
-import org.apache.snickers.encoding.ber.BEREncoder;
-import org.apache.snickers.encoding.ber.BEROutputStream;
-import org.apache.snickers.runtime.ASN1Type;
+import com.acme.spnego.ContextFlags;
+import com.acme.spnego.type.ContextFlagsType;
/**
* @version $Revision$ $Date: $
*/
-public class ContextFlagsEncoder implements BEREncoder
+public class ContextFlagsEncoder extends org.apache.snickers.encoding.ber.ASN1BitStringEncoder
{
- public void encode( BEROutputStream stream, ASN1Type object ) throws EncoderException
+ public void encode( java.io.OutputStream stream, org.apache.snickers.runtime.ASN1Type object ) throws org.apache.snickers.encoding.EncoderException
{
- //todo: consider this autogenerated code
- }
+ if ( !( object instanceof ContextFlagsType ) )
+ {
+ throw new org.apache.snickers.encoding.EncoderException( "Object not instance of ContextFlagsType" );
+ }
- public void encode( OutputStream stream, ASN1Type object ) throws EncoderException
- {
- //todo: consider this autogenerated code
- }
+ ContextFlags contextFlags = (ContextFlags) object;
- public int length( int tagNumber, ASN1Type object ) throws EncoderException
- {
- return 0; //todo: consider this autogenerated code
+ if ( !contextFlags.isConsistent() )
+ {
+ throw new org.apache.snickers.encoding.EncoderException( "ContextFlagsType is not consistent." );
+ }
+
+ super.encode( new org.apache.snickers.encoding.ber.BEROutputStream( stream ), object );
}
}
Modified: incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/MechTypeDecoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/MechTypeDecoder.java?view=diff&r1=154062&r2=154063
==============================================================================
--- incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/MechTypeDecoder.java (original)
+++ incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/MechTypeDecoder.java Wed Feb 16 10:57:26 2005
@@ -19,16 +19,24 @@
import java.io.InputStream;
import org.apache.snickers.encoding.Decoder;
+import org.apache.snickers.encoding.DecoderException;
+import org.apache.snickers.encoding.ber.BERDecoder;
+import org.apache.snickers.encoding.ber.BERInputStream;
import org.apache.snickers.runtime.ASN1Type;
/**
* @version $Revision$ $Date: $
*/
-public class MechTypeDecoder implements Decoder
+public class MechTypeDecoder implements BERDecoder
{
- public ASN1Type decode( InputStream stream )
+ public ASN1Type decode( BERInputStream stream ) throws DecoderException
{
- return null; //todo: consider this autogenerated code
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public ASN1Type decode( InputStream stream ) throws DecoderException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
}
}
Modified: incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/MechTypeEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/MechTypeEncoder.java?view=diff&r1=154062&r2=154063
==============================================================================
--- incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/MechTypeEncoder.java (original)
+++ incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/MechTypeEncoder.java Wed Feb 16 10:57:26 2005
@@ -16,51 +16,19 @@
*/
package com.acme.spnego.ber;
-import java.io.OutputStream;
-
-import org.apache.snickers.encoding.ber.BEREncoder;
-import org.apache.snickers.encoding.ber.BEROutputStream;
-import org.apache.snickers.runtime.ASN1Type;
-
/**
* @version $Revision$ $Date: $
*/
-public class MechTypeEncoder implements BEREncoder
+public class MechTypeEncoder extends org.apache.snickers.encoding.ber.ASN1ObjectIdentifierEncoder
{
- protected org.apache.snickers.encoding.ber.BEREncoder encoder;
-
- public MechTypeEncoder()
- {
- encoder = new org.apache.snickers.encoding.ber.ASN1ObjectIdentifierEncoder();
- }
-
- public void encode( OutputStream stream, ASN1Type object ) throws org.apache.snickers.encoding.EncoderException
+ public void encode( java.io.OutputStream stream, org.apache.snickers.runtime.ASN1Type object ) throws org.apache.snickers.encoding.EncoderException
{
if ( !( object instanceof org.apache.snickers.runtime.ASN1ObjectIdentifier ) )
{
throw new org.apache.snickers.encoding.EncoderException( "Object not instance of org.apache.snickers.runtime.ASN1ObjectIdentifier" );
}
- org.apache.snickers.runtime.ASN1ObjectIdentifier oid = (org.apache.snickers.runtime.ASN1ObjectIdentifier) object;
-
- if ( !oid.isConsistent() )
- {
- throw new org.apache.snickers.encoding.EncoderException( "org.apache.snickers.runtime.ASN1ObjectIdentifier is not consistent." );
- }
-
- encode( new org.apache.snickers.encoding.ber.BEROutputStream( stream ), object );
- }
-
- public int length( int tagNumber, ASN1Type object ) throws org.apache.snickers.encoding.EncoderException
- {
- return encoder.length( tagNumber, object );
- }
-
- public void encode( BEROutputStream out, ASN1Type object ) throws org.apache.snickers.encoding.EncoderException
- {
- org.apache.snickers.runtime.ASN1ObjectIdentifier oid = (org.apache.snickers.runtime.ASN1ObjectIdentifier) object;
-
- encoder.encode( out, oid );
+ super.encode( stream, object );
}
}
Modified: incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/MechTypeListDecoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/MechTypeListDecoder.java?view=diff&r1=154062&r2=154063
==============================================================================
--- incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/MechTypeListDecoder.java (original)
+++ incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/MechTypeListDecoder.java Wed Feb 16 10:57:26 2005
@@ -19,16 +19,24 @@
import java.io.InputStream;
import org.apache.snickers.encoding.Decoder;
+import org.apache.snickers.encoding.DecoderException;
+import org.apache.snickers.encoding.ber.BERDecoder;
+import org.apache.snickers.encoding.ber.BERInputStream;
import org.apache.snickers.runtime.ASN1Type;
/**
* @version $Revision$ $Date: $
*/
-public class MechTypeListDecoder implements Decoder
+public class MechTypeListDecoder implements BERDecoder
{
- public ASN1Type decode( InputStream stream )
+ public ASN1Type decode( BERInputStream stream ) throws DecoderException
{
- return null; //todo: consider this autogenerated code
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public ASN1Type decode( InputStream stream ) throws DecoderException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
}
}
Modified: incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/NegTokenInitDecoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/NegTokenInitDecoder.java?view=diff&r1=154062&r2=154063
==============================================================================
--- incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/NegTokenInitDecoder.java (original)
+++ incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/NegTokenInitDecoder.java Wed Feb 16 10:57:26 2005
@@ -22,13 +22,46 @@
*/
public class NegTokenInitDecoder implements org.apache.snickers.encoding.ber.BERDecoder
{
+ protected org.apache.snickers.encoding.ber.BERDecoder mechTypesDecoder;
+ protected org.apache.snickers.encoding.ber.BERDecoder reqFlagsDecoder;
+ protected org.apache.snickers.encoding.ber.BERDecoder mechTokenDecoder;
+ protected org.apache.snickers.encoding.ber.BERDecoder mechListMICDecoder;
+
+ public NegTokenInitDecoder()
+ {
+ mechTypesDecoder = new MechTypeListDecoder();
+ reqFlagsDecoder = new ContextFlagsDecoder();
+ mechTokenDecoder = new org.apache.snickers.encoding.ber.ASN1OctetStringDecoder();
+ mechListMICDecoder = new org.apache.snickers.encoding.ber.ASN1OctetStringDecoder();
+ }
+
public org.apache.snickers.runtime.ASN1Type decode( java.io.InputStream stream ) throws org.apache.snickers.encoding.DecoderException
{
- return null; //todo: consider this autogenerated code
+ return decode( new org.apache.snickers.encoding.ber.BERInputStream( stream ) );
}
public org.apache.snickers.runtime.ASN1Type decode( org.apache.snickers.encoding.ber.BERInputStream stream ) throws org.apache.snickers.encoding.DecoderException
{
- return null; //todo: consider this autogenerated code
+ com.acme.spnego.NegTokenInit negTokenInit = new com.acme.spnego.NegTokenInit();
+
+ try
+ {
+ int tag;
+
+ stream.loadImplicitIdentificaiton();
+ if ( stream.getTypeClass() != org.apache.snickers.encoding.ber.TypeClass.CONTEXT_SPECIFIC ) throw new org.apache.snickers.encoding.DecoderException( "Invalid type class" );
+ if ( !stream.isConstructed() ) throw new org.apache.snickers.encoding.DecoderException( "Identifier not constructed" );
+
+ tag = stream.getTag();
+ if (tag == 0) {
+ negTokenInit.setMechTypes( (com.acme.spnego.MechTypeList) mechTypesDecoder.decode( stream ) );
+ }
+ }
+ catch ( java.io.IOException ioe )
+ {
+ throw new org.apache.snickers.encoding.DecoderException( ioe );
+ }
+
+ return negTokenInit;
}
}
Modified: incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/NegotiationTokenDecoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/NegotiationTokenDecoder.java?view=diff&r1=154062&r2=154063
==============================================================================
--- incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/NegotiationTokenDecoder.java (original)
+++ incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/NegotiationTokenDecoder.java Wed Feb 16 10:57:26 2005
@@ -47,11 +47,12 @@
try
{
- if ( stream.readTypeClass() != org.apache.snickers.encoding.ber.TypeClass.CONTEXT_SPECIFIC ) throw new org.apache.snickers.encoding.DecoderException( "Invalid type class" );
- if ( !stream.readConstructed() ) throw new org.apache.snickers.encoding.DecoderException( "Identifier not constructed" );
+ stream.loadImplicitIdentificaiton();
+ if ( stream.getTypeClass() != org.apache.snickers.encoding.ber.TypeClass.CONTEXT_SPECIFIC ) throw new org.apache.snickers.encoding.DecoderException( "Invalid type class" );
+ if ( !stream.isConstructed() ) throw new org.apache.snickers.encoding.DecoderException( "Identifier not constructed" );
- int tag = stream.readTag();
- switch ( stream.readTag() )
+ int tag = stream.getTag();
+ switch ( stream.getTag() )
{
case 0:
{
Modified: incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/NegotiationTokenEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/NegotiationTokenEncoder.java?view=diff&r1=154062&r2=154063
==============================================================================
--- incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/NegotiationTokenEncoder.java (original)
+++ incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/com/acme/spnego/ber/NegotiationTokenEncoder.java Wed Feb 16 10:57:26 2005
@@ -16,8 +16,6 @@
*/
package com.acme.spnego.ber;
-import com.acme.spnego.NegotiationToken;
-
/**
* @version $Revision$ $Date: $
@@ -35,12 +33,12 @@
public void encode( java.io.OutputStream stream, org.apache.snickers.runtime.ASN1Type object ) throws org.apache.snickers.encoding.EncoderException
{
- if ( !( object instanceof NegotiationToken ) )
+ if ( !( object instanceof com.acme.spnego.NegotiationToken ) )
{
throw new org.apache.snickers.encoding.EncoderException( "Object not instance of NegotiationTokenType" );
}
- NegotiationToken negotiationToken = (NegotiationToken) object;
+ com.acme.spnego.NegotiationToken negotiationToken = (com.acme.spnego.NegotiationToken) object;
if ( !negotiationToken.isConsistent() )
{
@@ -52,7 +50,7 @@
public int length( int tagNumber, org.apache.snickers.runtime.ASN1Type object ) throws org.apache.snickers.encoding.EncoderException
{
- NegotiationToken negotiationToken = (NegotiationToken) object;
+ com.acme.spnego.NegotiationToken negotiationToken = (com.acme.spnego.NegotiationToken) object;
int length = 0;
@@ -63,7 +61,7 @@
public void encode( org.apache.snickers.encoding.ber.BEROutputStream out, org.apache.snickers.runtime.ASN1Type object ) throws org.apache.snickers.encoding.EncoderException
{
- NegotiationToken negotiationToken = (NegotiationToken) object;
+ com.acme.spnego.NegotiationToken negotiationToken = (com.acme.spnego.NegotiationToken) object;
try
{
@@ -89,7 +87,7 @@
}
- protected int contentLength( int tagNumber, NegotiationToken negotiationToken ) throws org.apache.snickers.encoding.EncoderException
+ protected int contentLength( int tagNumber, com.acme.spnego.NegotiationToken negotiationToken ) throws org.apache.snickers.encoding.EncoderException
{
int length = 0;
Modified: incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/org/apache/snickers/encoding/ber/AbstractDecoderTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/org/apache/snickers/encoding/ber/AbstractDecoderTestCase.java?view=diff&r1=154062&r2=154063
==============================================================================
--- incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/org/apache/snickers/encoding/ber/AbstractDecoderTestCase.java (original)
+++ incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/org/apache/snickers/encoding/ber/AbstractDecoderTestCase.java Wed Feb 16 10:57:26 2005
@@ -19,11 +19,10 @@
import java.nio.ByteBuffer;
import java.util.ArrayList;
-import junit.framework.TestCase;
-import org.apache.snickers.codec.binary.Binary;
+import junit.framework.TestCase;
+import org.apache.commons.codec.binary.BinaryCodec;
import org.apache.commons.lang.exception.ExceptionUtils;
-
import org.apache.snickers.encoding.DecoderException;
@@ -35,8 +34,7 @@
* @version $Rev$
*/
public abstract class AbstractDecoderTestCase extends TestCase
- implements DecoderCallback, DecoderMonitor
-{
+ implements DecoderCallback, DecoderMonitor {
/**
* list of encountered TLV's as we recieve completed decode callbacks
*/
@@ -48,7 +46,7 @@
/**
* value accumulator
*/
- ByteBuffer buffer = ByteBuffer.allocate( 11111 );
+ ByteBuffer buffer = ByteBuffer.allocate(11111);
/**
* stack counter
*/
@@ -61,12 +59,11 @@
/*
* @see TestCase#setUp()
*/
- protected void setUp() throws Exception
- {
+ protected void setUp() throws Exception {
super.setUp();
decoder = new org.apache.snickers.encoding.ber.AOKTestDecoder();
- decoder.setCallback( this );
- decoder.setDecoderMonitor( this );
+ decoder.setCallback(this);
+ decoder.setDecoderMonitor(this);
level = 0;
buffer.clear();
}
@@ -75,8 +72,7 @@
/*
* @see TestCase#tearDown()
*/
- protected void tearDown() throws Exception
- {
+ protected void tearDown() throws Exception {
super.tearDown();
tlvList.clear();
decoder = null;
@@ -88,9 +84,8 @@
*
* @param arg0
*/
- public AbstractDecoderTestCase( String arg0 )
- {
- super( arg0 );
+ public AbstractDecoderTestCase(String arg0) {
+ super(arg0);
}
/**
@@ -98,8 +93,7 @@
*
* @param expectedState the xpected state when tuple is decoded
*/
- public void setExpectedState( AOKDecoder.State expectedState )
- {
+ public void setExpectedState(AOKDecoder.State expectedState) {
this.expectedState = expectedState;
}
@@ -114,13 +108,11 @@
* @param size the maximum size of a fragment
* @return the array of byte[] fragments
*/
- public byte[][] fragment( byte[] bites, int size )
- {
+ public byte[][] fragment(byte[] bites, int size) {
byte[][] fragments = null;
- if ( size <= 0 )
- {
- throw new IllegalArgumentException( "fragment size should be 1 or more but was " + size );
+ if (size <= 0) {
+ throw new IllegalArgumentException("fragment size should be 1 or more but was " + size);
}
int wholeFrags = bites.length / size;
@@ -129,27 +121,22 @@
/*
* Allocate what we need depending on the size of our remainder
*/
- if ( partialFragSize == 0 )
- {
+ if (partialFragSize == 0) {
fragments = new byte[wholeFrags][];
- }
- else
- {
+ } else {
fragments = new byte[wholeFrags + 1][];
fragments[wholeFrags] = new byte[partialFragSize];
}
- for ( int ii = 0; ii < wholeFrags; ii++ )
- {
+ for (int ii = 0; ii < wholeFrags; ii++) {
fragments[ii] = new byte[size];
- System.arraycopy( bites, ii * size, fragments[ii], 0, size );
+ System.arraycopy(bites, ii * size, fragments[ii], 0, size);
}
- if ( partialFragSize != 0 )
- {
+ if (partialFragSize != 0) {
int srcPos = wholeFrags * size;
byte[] src = fragments[wholeFrags];
- System.arraycopy( bites, srcPos, src, 0, partialFragSize );
+ System.arraycopy(bites, srcPos, src, 0, partialFragSize);
}
return fragments;
@@ -167,14 +154,12 @@
* @param size the maximum size of a fragment
* @return the buffer fragment
*/
- public ByteBuffer[] fragment( ByteBuffer bites, int size )
- {
+ 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 );
+ if (size <= 0) {
+ throw new IllegalArgumentException("fragment size should be 1 or more but was " + size);
}
int wholeFrags = bites.remaining() / size;
@@ -183,25 +168,20 @@
/*
* Allocate what we need depending on the size of our remainder
*/
- if ( partialFragSize == 0 )
- {
+ if (partialFragSize == 0) {
fragments = new ByteBuffer[wholeFrags];
- }
- else
- {
+ } else {
fragments = new ByteBuffer[wholeFrags + 1];
- fragments[wholeFrags] = ByteBuffer.allocate( partialFragSize );
+ fragments[wholeFrags] = ByteBuffer.allocate(partialFragSize);
}
- for ( int ii = 0; ii < wholeFrags; ii++ )
- {
- fragments[ii] = (ByteBuffer) bites.slice().limit( size );
- bites.position( bites.position() + size );
+ 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 );
+ if (partialFragSize != 0) {
+ fragments[wholeFrags].put(bites);
fragments[wholeFrags].flip();
}
@@ -216,19 +196,17 @@
* @return a copy of the decoded tuple or the partially decoded current tlv
* @throws DecoderException if there are errors while decoding.
*/
- public Tuple decode( String bitString ) throws DecoderException
- {
- byte[] bites = Binary.fromAscii( bitString.getBytes() );
- ByteBuffer buf = ByteBuffer.wrap( bites );
+ public Tuple decode(String bitString) throws DecoderException {
+ byte[] bites = BinaryCodec.fromAscii(bitString.getBytes());
+ ByteBuffer buf = ByteBuffer.wrap(bites);
int lastSize = tlvList.size();
- decoder.decode( buf );
+ decoder.decode(buf);
- if ( tlvList.isEmpty() || tlvList.size() == lastSize )
- {
+ if (tlvList.isEmpty() || tlvList.size() == lastSize) {
return decoder.getCurrentTuple();
}
- return (Tuple) tlvList.get( tlvList.size() - 1 );
+ return (Tuple) tlvList.get(tlvList.size() - 1);
}
@@ -239,19 +217,17 @@
* @return a copy of the decoded tuple or the partially decoded current tlv
* @throws DecoderException if there are errors while decoding.
*/
- public Tuple decode( byte bite ) throws DecoderException
- {
+ public Tuple decode(byte bite) throws DecoderException {
byte[] bites = {bite};
- ByteBuffer buf = ByteBuffer.wrap( bites );
+ ByteBuffer buf = ByteBuffer.wrap(bites);
int lastSize = tlvList.size();
- decoder.decode( buf );
+ decoder.decode(buf);
- if ( tlvList.isEmpty() || tlvList.size() == lastSize )
- {
+ if (tlvList.isEmpty() || tlvList.size() == lastSize) {
return decoder.getCurrentTuple();
}
- return (Tuple) tlvList.get( tlvList.size() - 1 );
+ return (Tuple) tlvList.get(tlvList.size() - 1);
}
@@ -262,18 +238,16 @@
* @return a copy of the decoded tuple or the partially decoded current tlv
* @throws DecoderException if there are errors while decoding.
*/
- public Tuple decode( byte[] bites ) throws DecoderException
- {
- ByteBuffer buf = ByteBuffer.wrap( bites );
+ public Tuple decode(byte[] bites) throws DecoderException {
+ ByteBuffer buf = ByteBuffer.wrap(bites);
int lastSize = tlvList.size();
- decoder.decode( buf );
+ decoder.decode(buf);
- if ( tlvList.isEmpty() || tlvList.size() == lastSize )
- {
+ if (tlvList.isEmpty() || tlvList.size() == lastSize) {
return decoder.getCurrentTuple();
}
- return (Tuple) tlvList.get( tlvList.size() - 1 );
+ return (Tuple) tlvList.get(tlvList.size() - 1);
}
@@ -284,17 +258,15 @@
* @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
- {
+ public Tuple decode(ByteBuffer bites) throws DecoderException {
int lastSize = tlvList.size();
- decoder.decode( bites );
+ decoder.decode(bites);
- if ( tlvList.isEmpty() || tlvList.size() == lastSize )
- {
+ if (tlvList.isEmpty() || tlvList.size() == lastSize) {
return decoder.getCurrentTuple();
}
- return (Tuple) tlvList.get( tlvList.size() - 1 );
+ return (Tuple) tlvList.get(tlvList.size() - 1);
}
@@ -305,20 +277,18 @@
* @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, ByteBuffer value ) throws DecoderException
- {
+ public Tuple decode(Tuple tlv, ByteBuffer value) throws DecoderException {
ArrayList list = new ArrayList();
- list.add( value );
- ByteBuffer buf = tlv.toEncodedBuffer( list );
+ list.add(value);
+ ByteBuffer buf = tlv.toEncodedBuffer(list);
int lastSize = tlvList.size();
- decoder.decode( buf );
+ decoder.decode(buf);
- if ( tlvList.isEmpty() || tlvList.size() == lastSize )
- {
+ if (tlvList.isEmpty() || tlvList.size() == lastSize) {
return decoder.getCurrentTuple();
}
- return (Tuple) tlvList.get( tlvList.size() - 1 );
+ return (Tuple) tlvList.get(tlvList.size() - 1);
}
@@ -329,32 +299,28 @@
* @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, ByteBuffer[] values )
- 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], values[ii] );
+ for (int ii = 0; ii < tlvs.length; ii++) {
+ decode(tlvs[ii], values[ii]);
}
- if ( tlvList.isEmpty() || tlvList.size() == lastSize )
- {
+ if (tlvList.isEmpty() || tlvList.size() == lastSize) {
return decoder.getCurrentTuple();
}
- return (Tuple) tlvList.get( tlvList.size() - 1 );
+ return (Tuple) tlvList.get(tlvList.size() - 1);
}
/* (non-Javadoc)
* @see org.apache.snickers.codec.stateful.DecoderCallback#decodeOccurred(
* org.apache.snickers.codec.stateful.Decoder, java.lang.Object)
*/
- public void decodeOccurred( Decoder decoder, Tuple decoded )
- {
- tlvList.add( decoded );
- assertEquals( expectedState, this.decoder.getState() );
+ public void decodeOccurred(Decoder decoder, Tuple decoded) {
+ tlvList.add(decoded);
+ assertEquals(expectedState, this.decoder.getState());
buffer.flip();
}
@@ -364,16 +330,14 @@
* org.apache.snickers.codec.stateful.Decoder,
* org.apache.snickers.codec.stateful.DecoderCallback, java.lang.Object)
*/
- public void callbackOccured( Decoder decoder, DecoderCallback cb,
- Object decoded )
- {
- assertEquals( this, cb );
- assertEquals( this.decoder, decoder );
+ public void callbackOccured(Decoder decoder, DecoderCallback cb,
+ Object decoded) {
+ assertEquals(this, cb);
+ assertEquals(this.decoder, decoder);
Tuple t = (Tuple) decoded;
- assertNotNull( t );
- if ( t.isPrimitive() )
- {
- assertTrue( this.decoder.getCurrentTuple().equals( decoded ) );
+ assertNotNull(t);
+ if (t.isPrimitive()) {
+ assertTrue(this.decoder.getCurrentTuple().equals(decoded));
}
}
@@ -384,10 +348,9 @@
* org.apache.snickers.codec.stateful.DecoderCallback,
* org.apache.snickers.codec.stateful.DecoderCallback)
*/
- public void callbackSet( Decoder decoder, DecoderCallback oldcb,
- DecoderCallback newcb )
- {
- assertEquals( this, newcb );
+ public void callbackSet(Decoder decoder, DecoderCallback oldcb,
+ DecoderCallback newcb) {
+ assertEquals(this, newcb);
}
@@ -395,9 +358,8 @@
* @see org.apache.snickers.codec.stateful.DecoderMonitor#error(
* org.apache.snickers.codec.stateful.Decoder, java.lang.Exception)
*/
- public void error( Decoder decoder, Exception exception )
- {
- fail( ExceptionUtils.getFullStackTrace( exception ) );
+ public void error(Decoder decoder, Exception exception) {
+ fail(ExceptionUtils.getFullStackTrace(exception));
}
@@ -405,9 +367,8 @@
* @see org.apache.snickers.codec.stateful.DecoderMonitor#fatalError(
* org.apache.snickers.codec.stateful.Decoder, java.lang.Exception)
*/
- public void fatalError( Decoder decoder, Exception exception )
- {
- fail( ExceptionUtils.getFullStackTrace( exception ) );
+ public void fatalError(Decoder decoder, Exception exception) {
+ fail(ExceptionUtils.getFullStackTrace(exception));
}
@@ -416,9 +377,8 @@
* org.apache.snickers.codec.stateful.Decoder,
* org.apache.snickers.codec.stateful.DecoderMonitor)
*/
- public void monitorSet( Decoder decoder, DecoderMonitor oldmon )
- {
- assertEquals( this, oldmon );
+ public void monitorSet(Decoder decoder, DecoderMonitor oldmon) {
+ assertEquals(this, oldmon);
}
@@ -426,9 +386,8 @@
* @see org.apache.snickers.codec.stateful.DecoderMonitor#warning(
* org.apache.snickers.codec.stateful.Decoder, java.lang.Exception)
*/
- public void warning( Decoder decoder, Exception exception )
- {
- assertNotNull( exception );
+ public void warning(Decoder decoder, Exception exception) {
+ assertNotNull(exception);
}
/**
@@ -444,9 +403,8 @@
*
* @param tlv the TLV tuple
*/
- public void start( Tuple tlv )
- {
- assertNotNull( tlv );
+ public void start(Tuple tlv) {
+ assertNotNull(tlv);
level++;
buffer.clear();
}
@@ -456,19 +414,17 @@
*
* @param buf the possibly partial contents of a TLV value
*/
- public void contents( ByteBuffer buf )
- {
- assertNotNull( buf );
- assertTrue( level > 0 );
- buffer.put( buf );
+ public void contents(ByteBuffer buf) {
+ assertNotNull(buf);
+ assertTrue(level > 0);
+ buffer.put(buf);
}
/**
* Method used to provide notification that a TLV tuple has been read.
*/
- public void end()
- {
- assertTrue( level > 0 );
+ public void end() {
+ assertTrue(level > 0);
level--;
}
}
Modified: incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/org/apache/snickers/encoding/ber/BenchmarkTest.java
URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/org/apache/snickers/encoding/ber/BenchmarkTest.java?view=diff&r1=154062&r2=154063
==============================================================================
--- incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/org/apache/snickers/encoding/ber/BenchmarkTest.java (original)
+++ incubator/directory/asn1/branches/ber-decoder/modules/runtime/src/test/org/apache/snickers/encoding/ber/BenchmarkTest.java Wed Feb 16 10:57:26 2005
@@ -16,14 +16,15 @@
*/
package org.apache.snickers.encoding.ber;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Map;
+
import com.acme.spnego.MechType;
import com.acme.spnego.MechTypeList;
import com.acme.spnego.NegTokenInit;
import com.acme.spnego.NegotiationToken;
import junit.framework.TestCase;
-
import org.apache.snickers.encoding.Encoder;
import org.apache.snickers.encoding.EncodingFactory;
import org.apache.snickers.encoding.EncodingFactoryDefault;
@@ -59,18 +60,11 @@
public void testSpeed() throws Exception
{
- long COUNT = 100000L;
+ long COUNT = 1000000L;
Encoder encoder = EncodingFactory.getEncoder( "ber", NegotiationToken.class );
- NegotiationToken negotiationToken = new NegotiationToken();
- NegTokenInit negTokenInit = new NegTokenInit();
- negotiationToken.setNegTokenInit( negTokenInit );
-
- negTokenInit.setMechTypes( new MechTypeList() );
- negTokenInit.getMechTypes().add( new MechType( EncodingFactoryTest.KERBEROS_V5_LEGACY ) );
- negTokenInit.getMechTypes().add( new MechType( new int[]{1, 2, 840, 113554, 1, 2, 2} ) );
- negTokenInit.setMechToken( new ASN1OctetString( new byte[1458] ) );
+ NegotiationToken negotiationToken = generateNegotiationToken();
ByteArrayOutputStream out = new ByteArrayOutputStream( 2048 );
long start = System.currentTimeMillis();
@@ -78,6 +72,7 @@
{
out.reset();
encoder.encode( out, negotiationToken );
+ ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
}
long end = System.currentTimeMillis();
@@ -91,7 +86,7 @@
start = System.currentTimeMillis();
for ( long i = 0; i < COUNT; i++ )
{
- ( (BEREncoder) encoder ).length( 5, negTokenInit );
+ ( (BEREncoder) encoder ).length( 5, negotiationToken.getNegTokenInit() );
}
end = System.currentTimeMillis();
@@ -114,17 +109,7 @@
// negotiationToken.negTokenInit.mechToken = new byte[1458];
//
// com.ibm.asn1.BEREncoder out = new com.ibm.asn1.BEREncoder( 2048, 64 );
-// long start = System.currentTimeMillis();
-// for ( long i = 0; i < COUNT; i++ )
-// {
-// out.init();
-// negotiationToken.encode( out );
-// }
-// long end = System.currentTimeMillis();
-//
-// System.out.println( "negotiationToken.encode: " + ( ( end - start ) / 1000.0 ) + "s duration" );
-// System.out.println( "negotiationToken.encode: " + ( ( end - start ) * 1000000.0 / COUNT ) + "ns" );
-// System.out.println( "negotiationToken.encode: " + ( ( end - start ) / ( COUNT * 1.0 ) ) + "ms\n" );
+// negotiationToken.encode( out );
//
// byte[] target = new byte[]{(byte) 0xa0, (byte) 0x82, (byte) 0x05, (byte) 0xd8,
// (byte) 0x30, (byte) 0x82, (byte) 0x05, (byte) 0xd4,
@@ -137,21 +122,45 @@
//
// byte[] result = out.toByteArray();
//
-// assertEquals( 1500, result.length );
+// assertEquals(1494, result.length);
//
-// for ( int i = 0; i < target.length; i++ )
-// {
-// assertEquals( target[i], result[i] );
+// for (int i = 0; i < target.length; i++) {
+// assertEquals("result[" + i + "]", target[i], result[i]);
// }
//
-// for ( int i = target.length; i < result.length; i++ )
+// for (int i = target.length; i < result.length; i++) {
+// assertEquals("result[" + i + "]", 0x00, result[i]);
+// }
+//
+// long start = System.currentTimeMillis();
+// for ( long i = 0; i < COUNT; i++ )
// {
-// assertEquals( 0x00, result[i] );
+// out = new com.ibm.asn1.BEREncoder( 2048, 64 );
+// negotiationToken.encode( out );
// }
+// long end = System.currentTimeMillis();
+//
+// System.out.println( "negotiationToken.encode: " + ( ( end - start ) / 1000.0 ) + "s duration" );
+// System.out.println( "negotiationToken.encode: " + ( ( end - start ) * 1000000.0 / COUNT ) + "ns" );
+// System.out.println( "negotiationToken.encode: " + ( ( end - start ) / ( COUNT * 1.0 ) ) + "ms\n" );
// }
public void setUp()
{
EncodingFactory.register( new EncodingFactoryDefault( "ber" ) );
+ }
+
+ public NegotiationToken generateNegotiationToken()
+ {
+ NegotiationToken negotiationToken = new NegotiationToken();
+ NegTokenInit negTokenInit = new NegTokenInit();
+ negotiationToken.setNegTokenInit( negTokenInit );
+
+ negTokenInit.setMechTypes( new MechTypeList() );
+ negTokenInit.getMechTypes().add( new MechType( EncodingFactoryTest.KERBEROS_V5_LEGACY ) );
+ negTokenInit.getMechTypes().add( new MechType( new int[]{1, 2, 840, 113554, 1, 2, 2} ) );
+ negTokenInit.setMechToken( new ASN1OctetString( new byte[1458] ) );
+
+ return negotiationToken;
}
}