BytesUtils { public static byte[] remove(byte[] arr, int n) { int index = binarySearch(arr, n); byte[] arr2 = new byte[arr.length - 4]; System.arraycopy(arr, 0, arr2, 0, index); System.arraycopy(arr, index + 4, arr2, index, arr.length - index - 4); return arr2; }  static byte[] add(byte[] arr, int n); static byte[] remove(byte[] arr, int n); static int binarySearch(byte[] a, int key); static void write(DataOutput out, Object value); static Object read(DataInput in); static byte toByte(boolean value); static byte[] toBytes(long[] values); static byte[] toBytes(int[] values); static byte[] toBytes(short[] values); static byte[] toBytes(byte[] values); static byte[] toBytes(boolean[] values); static byte[] toBytes(float[] values); static byte[] toBytes(double[] values); static byte[] toBytes(String[] strings); static byte[] toBytes(Reference reference); static byte[] toBytes(ReferenceList reference); static Reference toReference(byte[] value, int offset); static ReferenceList toReferences(byte[] value, int offset); static ReferenceList toReferences(byte[] value, int offset, int length); static boolean[] toBooleans(byte[] value, int offset, int num); static boolean[] toBooleans(byte[] value, int offset); static List<Boolean> toBooleanList(byte[] value, int offset); static long[] toLongs(byte[] value, int offset, int num); static long[] toLongs(byte[] value, int offset); static List<Long> toLongList(byte[] value, int offset); static int[] toInts(byte[] value, int offset, int num); static int[] toInts(byte[] value, int offset); static List<Integer> toIntList(byte[] value, int offset); static short[] toShorts(byte[] value, int offset, int num); static short[] toShorts(byte[] value, int offset); static List<Short> toShortList(byte[] value, int offset); static byte[] toBytes(byte[] value, int offset, int num); static byte[] toBytes(byte[] value, int offset); static List<Byte> toByteList(byte[] value, int offset); static double[] toDoubles(byte[] value, int offset, int num); static double[] toDoubles(byte[] value, int offset); static List<Double> toDoubleList(byte[] value, int offset); static float[] toFloats(byte[] value, int offset, int num); static float[] toFloats(byte[] value, int offset); static List<Float> toFloatList(byte[] value, int offset); static String[] toStrings(byte[] value, int offset, int length); static String[] toStrings(byte[] value, int offset); static List<String> toStringList(byte[] value, int offset); static short getShort(final byte[] b, final int offset); static float getFloat(final byte[] b, final int offset); static double getDouble(final byte[] b, final int offset); static String getString(final byte[] b, final int offset); static ByteBuffer allocate(int length); static int compareTo(byte[] buffer1, int offset1, int length1,
                         byte[] buffer2, int offset2, int length2);  }
@Test public void remove() { int max = 10; byte[] bytes = createBytes(max); List<Integer> shuffle = new ArrayList<>(); for (int i = 0; i < max; i++) { shuffle.add(i); } Collections.shuffle(shuffle); int length = bytes.length; for (int i = 0; i < max; i++) { bytes = BytesUtils.remove(bytes, shuffle.get(i)); assertThat(bytes.length, CoreMatchers.is(length - (i * 4) - 4)); } }