]> source.dussan.org Git - poi.git/commitdiff
restore JDK 1.5 compatibility
authorSergey Vladimirov <sergey@apache.org>
Mon, 25 Jul 2011 10:12:34 +0000 (10:12 +0000)
committerSergey Vladimirov <sergey@apache.org>
Mon, 25 Jul 2011 10:12:34 +0000 (10:12 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1150617 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/util/ArrayUtil.java

index be2b49999dfd6c2d4de096178aec37874f8cb035..e5c6744764a5bf4cee3b116a07ac7d955ce2fb39 100644 (file)
@@ -104,4 +104,28 @@ public class ArrayUtil
        
        // We're done - array will now have everything moved as required
     }
+
+    /**
+     * Copies the specified array, truncating or padding with zeros (if
+     * necessary) so the copy has the specified length. This method is temporary
+     * replace for Arrays.copyOf() until we start to require JDK 1.6.
+     * 
+     * @param source
+     *            the array to be copied
+     * @param newLength
+     *            the length of the copy to be returned
+     * @return a copy of the original array, truncated or padded with zeros to
+     *         obtain the specified length
+     * @throws NegativeArraySizeException
+     *             if <tt>newLength</tt> is negative
+     * @throws NullPointerException
+     *             if <tt>original</tt> is null
+     */
+    public static byte[] copyOf( byte[] source, int newLength )
+    {
+        byte[] result = new byte[newLength];
+        System.arraycopy( source, 0, result, 0,
+                Math.min( source.length, newLength ) );
+        return result;
+    }
 }