• JAVA将byte数组(byte[])按照指定大小分割成多个byte数组


    /**
         * 将byte数组按照指定大小分割成多个数组
         * @param bytes   要分割的byte数组
         * @param subSize  分割的块大小  单位:字节
         * @return 指定大小的byte数组
         */
    
        public static Object[] splitByteArr(byte[] bytes, int subSize) {
            int count = bytes.length % subSize == 0 ? bytes.length / subSize : bytes.length / subSize + 1;
    
            List<List<Byte>> subAryList = new ArrayList<List<Byte>>();
    
            for (int i = 0; i < count; i++) {
                int index = i * subSize;
                List<Byte> list = new ArrayList<Byte>();
                int j = 0;
                while (j < subSize && index < bytes.length) {
                    list.add(bytes[index++]);
                    j++;
                }
                subAryList.add(list);
            }
    
            Object[] subAry = new Object[subAryList.size()];
    
            for (int i = 0; i < subAryList.size(); i++) {
                List<Byte> subList = subAryList.get(i);
                byte[] subAryItem = new byte[subList.size()];
                for (int j = 0; j < subList.size(); j++) {
                    subAryItem[j] = subList.get(j);
                }
                subAry[i] = subAryItem;
            }
            return subAry;
        }

    然后通过方法将object转成byte数组 参考 :https://www.cnblogs.com/pxblog/p/14919068.html

    -----------------------有任何问题可以在评论区评论,也可以私信我,我看到的话会进行回复,欢迎大家指教------------------------ (蓝奏云官网有些地址失效了,需要把请求地址lanzous改成lanzoux才可以)
  • 相关阅读:
    load custom class in drupal 8
    HEAD in Git
    composer version constraint 版本号前缀
    如何测试
    看待一段数据
    创建一个plugin
    eclipse的快捷方式
    .git文件夹的猜想
    本地可以但远程不行
    方法点不进去的原因
  • 原文地址:https://www.cnblogs.com/pxblog/p/14919061.html
Copyright © 2020-2023  润新知