Return-Path: Delivered-To: apmail-incubator-directory-cvs-archive@www.apache.org Received: (qmail 13985 invoked from network); 27 Nov 2004 09:44:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 27 Nov 2004 09:44:04 -0000 Received: (qmail 46638 invoked by uid 500); 27 Nov 2004 09:44:04 -0000 Delivered-To: apmail-incubator-directory-cvs-archive@incubator.apache.org Received: (qmail 46595 invoked by uid 500); 27 Nov 2004 09:44:04 -0000 Mailing-List: contact directory-cvs-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: directory-dev@incubator.apache.org Delivered-To: mailing list directory-cvs@incubator.apache.org Received: (qmail 46581 invoked by uid 99); 27 Nov 2004 09:44:03 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Sat, 27 Nov 2004 01:44:03 -0800 Received: (qmail 13965 invoked by uid 65534); 27 Nov 2004 09:44:02 -0000 Date: 27 Nov 2004 09:44:02 -0000 Message-ID: <20041127094402.13958.qmail@minotaur.apache.org> From: akarasulu@apache.org To: directory-cvs@incubator.apache.org Subject: svn commit: r106701 - /incubator/directory/seda/trunk/src/java/org/apache/seda/HexDump.java /incubator/directory/seda/trunk/src/test/org/apache/seda/HexDumpTest.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: akarasulu Date: Sat Nov 27 01:44:01 2004 New Revision: 106701 URL: http://svn.apache.org/viewcvs?view=rev&rev=106701 Log: some tools that came in handy Added: incubator/directory/seda/trunk/src/java/org/apache/seda/HexDump.java incubator/directory/seda/trunk/src/test/org/apache/seda/HexDumpTest.java Added: incubator/directory/seda/trunk/src/java/org/apache/seda/HexDump.java Url: http://svn.apache.org/viewcvs/incubator/directory/seda/trunk/src/java/org/apache/seda/HexDump.java?view=auto&rev=106701 ============================================================================== --- (empty file) +++ incubator/directory/seda/trunk/src/java/org/apache/seda/HexDump.java Sat Nov 27 01:44:01 2004 @@ -0,0 +1,113 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.seda; + + +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.io.FileOutputStream; +import java.io.File; +import java.io.IOException; + + +/** + * Document this class. + * + * @author Apache Directory Project + * @version $Rev$ + */ +public class HexDump +{ + private final static char[] hexChars = { + '0', '1', '2', '3', + '4', '5', '6', '7', + '8', '9', 'a', 'b', + 'c', 'd', 'e', 'f' + }; + + + public static final StringBuffer dump( ByteBuffer[] buffers ) + { + StringBuffer buf = new StringBuffer(); + + int byteCount = 0; + for ( int ii = 0; ii < buffers.length; ii++ ) + { + ByteBuffer dup = buffers[ii].duplicate(); + while ( dup.hasRemaining() ) + { + if ( byteCount % 8 == 0 ) + { + buf.append( " " ); + } + + if ( byteCount % 16 == 0 ) + { + buf.append( '\n' ); + + int address = byteCount/16 + 10000000; + String addressStr = String.valueOf( address ).substring(1) + "0: "; + buf.append( addressStr ); + } + + byte bite = dup.get(); + buf.append( hexChars[ ( bite & 0xF0 ) >> 4 ] ); + buf.append( hexChars[ bite & 0x0F ]); + buf.append( ' ' ); + byteCount++; + } + } + + return buf; + } + + + public static void dump( String filename, ByteBuffer[] buffers ) throws IOException + { + File f = new File( filename ); + f.createNewFile(); + FileOutputStream outStream = new FileOutputStream( f ); + FileChannel out = outStream.getChannel(); + + ByteBuffer[] dups = new ByteBuffer[ buffers.length ]; + for ( int ii = 0; ii < buffers.length; ii++ ) + { + dups[ii] = buffers[ii].duplicate(); + } + + while ( hasRemaining( dups ) ) + { + out.write( dups ); + } + + outStream.close(); + } + + + public static boolean hasRemaining( ByteBuffer[] buffers ) + { + for ( int ii = 0; ii < buffers.length; ii++ ) + { + if ( buffers[ii].hasRemaining() ) + { + return true; + } + } + + return false; + } +} Added: incubator/directory/seda/trunk/src/test/org/apache/seda/HexDumpTest.java Url: http://svn.apache.org/viewcvs/incubator/directory/seda/trunk/src/test/org/apache/seda/HexDumpTest.java?view=auto&rev=106701 ============================================================================== --- (empty file) +++ incubator/directory/seda/trunk/src/test/org/apache/seda/HexDumpTest.java Sat Nov 27 01:44:01 2004 @@ -0,0 +1,41 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.seda; + + +import java.nio.ByteBuffer; + +import junit.framework.TestCase; + + +/** + * Document this class. + * + * @author Apache Directory Project + * @version $Rev$ + */ +public class HexDumpTest extends TestCase +{ + public void testDump() + { + ByteBuffer[] buffers = new ByteBuffer[] { + ByteBuffer.wrap( "Hello World this is the hex dump tool".getBytes() ) + }; + + System.err.println( HexDump.dump( buffers ) ); + } +}