[jboss-remoting-commits] JBoss Remoting SVN: r4013 - in remoting3/trunk: util/src/main/java/org/jboss/cx/remoting/util and 1 other directory.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Fri Apr 18 14:30:50 EDT 2008


Author: david.lloyd at jboss.com
Date: 2008-04-18 14:30:50 -0400 (Fri, 18 Apr 2008)
New Revision: 4013

Modified:
   remoting3/trunk/srp/src/main/java/org/jboss/cx/remoting/core/security/sasl/AbstractSrpSaslParticipant.java
   remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/IoUtil.java
Log:
Inline the one user of getSlice().  Add javadocs to the remaining IoUtil methods.

Modified: remoting3/trunk/srp/src/main/java/org/jboss/cx/remoting/core/security/sasl/AbstractSrpSaslParticipant.java
===================================================================
--- remoting3/trunk/srp/src/main/java/org/jboss/cx/remoting/core/security/sasl/AbstractSrpSaslParticipant.java	2008-04-18 18:13:33 UTC (rev 4012)
+++ remoting3/trunk/srp/src/main/java/org/jboss/cx/remoting/core/security/sasl/AbstractSrpSaslParticipant.java	2008-04-18 18:30:50 UTC (rev 4013)
@@ -18,7 +18,6 @@
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Random;
-import org.jboss.cx.remoting.util.IoUtil;
 
 import javax.crypto.BadPaddingException;
 import javax.crypto.Cipher;
@@ -470,8 +469,8 @@
         final ByteBuffer homeSlice;
         final ByteBuffer macSlice;
         if (integrityEnabled) {
-            homeSlice = IoUtil.getSlice(src, -macLength);
-            macSlice = IoUtil.getSlice(src, macLength);
+            homeSlice = getSlice(src, -macLength);
+            macSlice = getSlice(src, macLength);
             inboundMac.reset();
             inboundMac.update((ByteBuffer) homeSlice.mark());
             if (replayEnabled) {
@@ -501,6 +500,21 @@
         return;
     }
 
+    private static ByteBuffer getSlice(final ByteBuffer src, final int macLength) {
+        ByteBuffer slice = src.duplicate();
+        final int newLimit;
+        if (macLength < 0) {
+            // calculate from end
+            newLimit = src.limit() - macLength;
+        } else {
+            // calculate from start
+            newLimit = src.position() + macLength;
+        }
+        slice.limit(newLimit);
+        src.position(newLimit);
+        return slice;
+    }
+
     public boolean isWrappable() {
         return confidentialityEnabled || integrityEnabled;
     }

Modified: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/IoUtil.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/IoUtil.java	2008-04-18 18:13:33 UTC (rev 4012)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/IoUtil.java	2008-04-18 18:30:50 UTC (rev 4013)
@@ -11,21 +11,13 @@
 public final class IoUtil {
     private static final Logger log = Logger.getLogger(IoUtil.class);
 
-    public static ByteBuffer getSlice(ByteBuffer source, int length) {
-        ByteBuffer slice = source.duplicate();
-        final int newLimit;
-        if (length < 0) {
-            // calculate from end
-            newLimit = source.limit() - length;
-        } else {
-            // calculate from start
-            newLimit = source.position() + length;
-        }
-        slice.limit(newLimit);
-        source.position(newLimit);
-        return slice;
-    }
-
+    /**
+     * Base-64 decode a character buffer into a byte buffer.
+     *
+     * @param source the base-64 encoded source material
+     * @param target the target for the decoded data
+     * @throws Base64DecodingException if the source data is not in base-64 format
+     */
     public static void base64Decode(CharBuffer source, ByteBuffer target) throws Base64DecodingException {
         int triad;
         while (source.hasRemaining()) {
@@ -126,6 +118,12 @@
             '4', '5', '6', '7', '8', '9', '+', '/',
     };
 
+    /**
+     * Base-64 encode a byte buffer into a character buffer.
+     *
+     * @param source the binary data to encode
+     * @param target the target for the encoded material
+     */
     public static void base64Encode(ByteBuffer source, CharBuffer target) {
         int idx = 0;
         while (source.hasRemaining()) {
@@ -151,6 +149,12 @@
         }
     }
 
+    /**
+     * Close a resource without throwing an exception.  If the underlying {@code close} throws an exception, log
+     * it.  For use in {@code finally} blocks.
+     *
+     * @param c the resource to close
+     */
     public static void closeSafely(Closeable c) {
         try {
             c.close();




More information about the jboss-remoting-commits mailing list