directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r123511 - in incubator/directory/network/trunk/mina/src/java/org/apache/mina: common protocol util
Date Tue, 28 Dec 2004 14:01:35 GMT
Author: trustin
Date: Tue Dec 28 06:01:34 2004
New Revision: 123511

URL: http://svn.apache.org/viewcvs?view=rev&rev=123511
Log:
 * Moved util.ByteBuffers to common package
Added:
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBufferHexDumper.java
  (contents, props changed)
Removed:
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ByteBuffers.java
Modified:
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolViolationException.java

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java?view=diff&rev=123511&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java&r1=123510&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java&r2=123511
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java
Tue Dec 28 06:01:34 2004
@@ -491,4 +491,12 @@
     {
         return buf.asDoubleBuffer();
     }
+    
+    /**
+     * Returns hexdump of this buffer.
+     */
+    public String getHexDump()
+    {
+        return ByteBufferHexDumper.getHexdump(this);
+    }
 }

Added: incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBufferHexDumper.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBufferHexDumper.java?view=auto&rev=123511
==============================================================================
--- (empty file)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBufferHexDumper.java
Tue Dec 28 06:01:34 2004
@@ -0,0 +1,87 @@
+/*
+ *   @(#) $Id$
+ *
+ *   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.mina.common;
+
+import org.apache.mina.common.ByteBuffer;
+
+/**
+ * Provides utility methods for ByteBuffers.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+class ByteBufferHexDumper
+{
+    private static final byte[] highDigits;
+
+    private static final byte[] lowDigits;
+
+    // initialize lookup tables
+    static
+    {
+        final byte[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
+                               '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+
+        int i;
+        byte[] high = new byte[ 256 ];
+        byte[] low = new byte[ 256 ];
+
+        for( i = 0; i < 256; i++ )
+        {
+            high[ i ] = digits[ i >>> 4 ];
+            low[ i ] = digits[ i & 0x0F ];
+        }
+
+        highDigits = high;
+        lowDigits = low;
+    }
+
+    static String getHexdump( ByteBuffer in )
+    {
+        int size = in.remaining();
+
+        if( size == 0 )
+        {
+            return "empty";
+        }
+
+        StringBuffer out = new StringBuffer( ( in.remaining() * 3 ) - 1 );
+
+        int mark = in.position();
+
+        // fill the first
+        int byteValue = in.get() & 0xFF;
+        out.append( ( char ) highDigits[ byteValue ] );
+        out.append( ( char ) lowDigits[ byteValue ] );
+        size--;
+
+        // and the others, too
+        for( ; size > 0; size-- )
+        {
+            out.append( ' ' );
+            byteValue = in.get() & 0xFF;
+            out.append( ( char ) highDigits[ byteValue ] );
+            out.append( ( char ) lowDigits[ byteValue ] );
+        }
+
+        in.position( mark );
+
+        return out.toString();
+    }
+}
\ No newline at end of file

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolViolationException.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolViolationException.java?view=diff&rev=123511&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolViolationException.java&r1=123510&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolViolationException.java&r2=123511
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolViolationException.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolViolationException.java
Tue Dec 28 06:01:34 2004
@@ -19,7 +19,6 @@
 package org.apache.mina.protocol;
 
 import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.util.ByteBuffers;
 
 /**
  * An exception that is thrown when {@link ProtocolEncoder} cannot understand or
@@ -81,7 +80,7 @@
         if( buffer != null )
         {
             return message + ( ( message.length() > 0 ) ? " " : "" )
-                   + "(Hexdump: " + ByteBuffers.getHexdump( buffer ) + ')';
+                   + "(Hexdump: " + buffer.getHexDump() + ')';
         }
         else
         {

Deleted: /incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ByteBuffers.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ByteBuffers.java?view=auto&rev=123510
==============================================================================

Mime
View raw message