From 369841ab90f72445097d918dcb5d6c385d4524b8 Mon Sep 17 00:00:00 2001 From: Sergey Vladimirov Date: Mon, 25 Jul 2011 10:12:34 +0000 Subject: [PATCH] restore JDK 1.5 compatibility 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 | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/java/org/apache/poi/util/ArrayUtil.java b/src/java/org/apache/poi/util/ArrayUtil.java index be2b49999d..e5c6744764 100644 --- a/src/java/org/apache/poi/util/ArrayUtil.java +++ b/src/java/org/apache/poi/util/ArrayUtil.java @@ -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 newLength is negative + * @throws NullPointerException + * if original 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; + } } -- 2.39.5