commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r759501 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioUtil.java
Date Sat, 28 Mar 2009 16:25:27 GMT
Author: sebb
Date: Sat Mar 28 16:25:26 2009
New Revision: 759501

URL: http://svn.apache.org/viewvc?rev=759501&view=rev
Log:
Correct Javadoc
Detect error earlier

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioUtil.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioUtil.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioUtil.java?rev=759501&r1=759500&r2=759501&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioUtil.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioUtil.java
Sat Mar 28 16:25:26 2009
@@ -25,7 +25,7 @@
  */
 class CpioUtil {
     /**
-     * Converts a byte array to a long. Halfwords can be swaped with setting
+     * Converts a byte array to a long. Halfwords can be swapped by setting
      * swapHalfWord=true.
      * 
      * @param number
@@ -33,17 +33,18 @@
      * @param swapHalfWord
      *            Swap halfwords ([0][1][2][3]->[1][0][3][2])
      * @return The long value
+     * @throws UnsupportedOperationException if number length is not a multiple of 2
      */
     static long byteArray2long(final byte[] number, final boolean swapHalfWord) {
+        if (number.length % 2 != 0) {
+            throw new UnsupportedOperationException();
+        }
+
         long ret = 0;
         int pos = 0;
         byte tmp_number[] = new byte[number.length];
         System.arraycopy(number, 0, tmp_number, 0, number.length);
 
-        if (tmp_number.length % 2 != 0) {
-            throw new UnsupportedOperationException();
-        }
-
         if (!swapHalfWord) {
             byte tmp = 0;
             for (pos = 0; pos < tmp_number.length; pos++) {
@@ -62,16 +63,18 @@
     }
 
     /**
-     * Converts a byte array to a long. Halfwords can be swaped with setting
-     * swapHalfWord=true.
+     * Converts a long number to a byte array 
+     * Halfwords can be swapped by setting swapHalfWord=true.
      * 
-     * @param number
-     *            An array of bytes containing a number
+     * @param number 
+     *            the input long number to be converted
+     *            
      * @param length
      *            The length of the returned array
      * @param swapHalfWord
      *            Swap halfwords ([0][1][2][3]->[1][0][3][2])
      * @return The long value
+     * @throws UnsupportedOperationException if the length is not a positive multiple of
two
      */
     static byte[] long2byteArray(final long number, final int length,
             final boolean swapHalfWord) {



Mime
View raw message