Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 2609 invoked from network); 21 Aug 2005 23:19:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 21 Aug 2005 23:19:51 -0000 Received: (qmail 57447 invoked by uid 500); 21 Aug 2005 23:19:50 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 57422 invoked by uid 500); 21 Aug 2005 23:19:50 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 57405 invoked by uid 99); 21 Aug 2005 23:19:50 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 21 Aug 2005 16:19:50 -0700 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 21 Aug 2005 16:20:08 -0700 Received: (qmail 2560 invoked by uid 65534); 21 Aug 2005 23:19:49 -0000 Message-ID: <20050821231949.2559.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r234389 - /directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/TwixDecoder.java Date: Sun, 21 Aug 2005 23:19:48 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.3 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: elecharny Date: Sun Aug 21 16:19:45 2005 New Revision: 234389 URL: http://svn.apache.org/viewcvs?rev=234389&view=rev Log: - Created the class - implemented the decoding of a Stream Modified: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/TwixDecoder.java Modified: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/TwixDecoder.java URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/TwixDecoder.java?rev=234389&r1=234388&r2=234389&view=diff ============================================================================== --- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/TwixDecoder.java (original) +++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/TwixDecoder.java Sun Aug 21 16:19:45 2005 @@ -3,15 +3,27 @@ import java.io.InputStream; import java.nio.ByteBuffer; +import org.apache.asn1.ber.digester.BERDigester; import org.apache.asn1.codec.DecoderException; import org.apache.asn1.codec.stateful.DecoderCallback; import org.apache.asn1.codec.stateful.DecoderMonitor; +import org.apache.asn1.codec.stateful.StatefulDecoder; +import org.apache.asn1new.ber.Asn1Decoder; +import org.apache.asn1new.ber.containers.IAsn1Container; +import org.apache.asn1new.ber.tlv.TLVStateEnum; +import org.apache.asn1new.ldap.codec.LdapDecoder; +import org.apache.asn1new.ldap.codec.LdapMessageContainer; +import org.apache.ldap.common.berlib.asn1.decoder.LdapDigesterFactory; +import org.apache.ldap.common.message.Message; import org.apache.ldap.common.message.spi.Provider; import org.apache.ldap.common.message.spi.ProviderDecoder; import org.apache.ldap.common.message.spi.ProviderException; public class TwixDecoder implements ProviderDecoder { private final Provider provider; + + private final LdapMessageContainer ldapMessageContainer; + private final Asn1Decoder ldapDecoder; /** * Creates an instance of a Twix Decoder implementation. @@ -21,6 +33,8 @@ public TwixDecoder( Provider provider ) { this.provider = provider; + ldapMessageContainer = new LdapMessageContainer(); + ldapDecoder = new LdapDecoder(); } public void decode( Object encoded ) throws DecoderException @@ -41,10 +55,53 @@ "ByteBuffer argument but got a " + encoded.getClass() ); } - LdapDecoder.decode( buf ); + ldapDecoder.decode( buf, ldapMessageContainer ); + + if ( ldapMessageContainer.getState() == TLVStateEnum.PDU_DECODED ) + { + // Send the result to the callback. + // TO BE DONE + } } /** + * Feeds the bytes within the input stream to the digester to generate the + * resultant decoded Message. + * + * @param in + * @throws ProviderException + */ + private void digest( InputStream in ) + throws ProviderException + { + byte[] buf = null; + + try + { + int amount = -1; + + while( in.available() > 0 ) + { + buf = new byte[in.available()]; + + if ( ( amount = in.read( buf ) ) == -1 ) + { + break; + } + + ldapDecoder.decode( ByteBuffer.wrap( buf, 0, amount ), ldapMessageContainer ); + } + } + catch( Exception e ) + { + ProviderException pe = new ProviderException( provider, + "Twix decoder failure!" ) ; + pe.addThrowable( e ) ; + throw pe ; + } + } + + /** * Decodes a PDU from an input stream into a Snickers compiler generated * stub envelope. * @@ -54,7 +111,53 @@ */ public Object decode( Object lock, InputStream in ) throws ProviderException { - return null; + if( lock == null ) + { + digest( in ); + + if ( ldapMessageContainer.getState() == TLVStateEnum.PDU_DECODED ) + { + return ldapMessageContainer.getLdapMessage(); + } + else + { + ProviderException pe = new ProviderException( provider, "Twix decoder failure!" ) ; + pe.addThrowable( new DecoderException( "The input stream does not contain a full PDU" ) ) ; + throw pe ; + } + } + else + { + try + { + // Synchronize on the input lock object to prevent concurrent reads + synchronized ( lock ) + { + digest( in ); + + // Notify/awaken threads waiting to read from input stream + lock.notifyAll() ; + } + } + catch( Exception e ) + { + ProviderException pe = new ProviderException( provider, + "Twix decoder failure!" ) ; + pe.addThrowable( e ) ; + throw pe ; + } + + if ( ldapMessageContainer.getState() == TLVStateEnum.PDU_DECODED ) + { + return ldapMessageContainer.getLdapMessage(); + } + else + { + ProviderException pe = new ProviderException( provider, "Twix decoder failure!" ) ; + pe.addThrowable( new DecoderException( "The input stream does not contain a full PDU" ) ) ; + throw pe ; + } + } } /**