Here you can find the source of splitArray(byte[] array, int len)
private static List<byte[]> splitArray(byte[] array, int len)
//package com.java2s; /*/*from w w w . j a va2 s . co m*/ * Copyright 2015-2017 GenerallyCloud.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.ArrayList; import java.util.List; public class Main { private static List<byte[]> splitArray(byte[] array, int len) { int length = array.length; List<byte[]> list = new ArrayList<byte[]>(); if (length <= len) { list.add(array); return list; } int size = length / len; for (int i = 0; i < size; i++) { byte[] a = new byte[len]; System.arraycopy(array, i * len, a, 0, len); list.add(a); } int yu = array.length % len; if (yu > 0) { byte[] a = new byte[yu]; System.arraycopy(array, length - yu, a, 0, yu); list.add(a); } return list; } }