< prev index next >

src/java.base/share/classes/sun/security/util/ArrayUtil.java

Print this page
rev 52526 : Moving some code around

*** 30,40 **** import java.security.*; import jdk.internal.util.Preconditions; /** ! * This class holds the various utility methods for array range checks. */ public final class ArrayUtil { private static final BiFunction<String, List<Integer>, --- 30,40 ---- import java.security.*; import jdk.internal.util.Preconditions; /** ! * This class holds the various utility methods for arrays. */ public final class ArrayUtil { private static final BiFunction<String, List<Integer>,
*** 50,55 **** --- 50,73 ---- public static void nullAndBoundsCheck(byte[] array, int offset, int len) { // NPE is thrown when array is null Preconditions.checkFromIndexSize(offset, len, array.length, AIOOBE_SUPPLIER); } + + + private static void swap(byte[] arr, int i, int j) { + byte tmp = arr[i]; + arr[i] = arr[j]; + arr[j] = tmp; + } + + public static void reverse(byte [] arr) { + int i = 0; + int j = arr.length - 1; + + while (i < j) { + swap(arr, i, j); + i++; + j--; + } + } }
< prev index next >