public static byte[][] fragmentBuffer(byte[] buf, int frag_size) { return fragmentBuffer(buf, frag_size, buf.length);
public static byte[][] fragmentBuffer(byte[] buf, int frag_size, int length) { byte[] retval[]; long total_size=length; int accumulated_size=0; byte[] fragment; int tmp_size=0; int num_frags; int index=0;  num_frags=length % frag_size == 0 ? length / frag_size : length / frag_size + 1; retval=new byte[num_frags][];  while(accumulated_size < total_size) { if(accumulated_size + frag_size <= total_size) tmp_size=frag_size; else tmp_size=(int)(total_size - accumulated_size); fragment=new byte[tmp_size]; System.arraycopy(buf, accumulated_size, fragment, 0, tmp_size); retval[index++]=fragment; accumulated_size+=tmp_size; } return retval;
    public static byte[][] fragmentBuffer(byte[] buf, int frag_size) {        return fragmentBuffer(buf, frag_size, buf.length);    }