Browse Source

1.去除 OSS中 源文件大小的路径,改为 依据不同的文件名称 去固定返回不同的源文件大小

xuzip 2 months ago
parent
commit
4046cfb142

+ 11 - 11
src/main/java/com/yeechart/dotMatrix/signage/SignageFileUtil.java

@@ -130,18 +130,13 @@ public class SignageFileUtil {
                 String name = entry.getKey();
                 sortedMap.put(name, entry.getValue());
 
-                //获取文件路径中的图的原始数据大小
-                if (!sizeMap.containsKey(name)) {
-                    String sum = name.substring(0, name.lastIndexOf('/'));
-                    sizeMap.put(name, Integer.parseInt(sum));
-                }
             }
 
             //整图的原始数据的大小 sizeMap 的value 总和
             String fileName = null;
             Integer ogSize = null;
 
-            byte[] data = new byte[sizeMap.values().stream().mapToInt(Integer::intValue).sum()];
+            byte[] data1 = new byte[ SignageDrawUtil.height * SignageDrawUtil.width ] ;//默认使用完整图
 
             int length = 0;
 
@@ -150,7 +145,7 @@ public class SignageFileUtil {
             for (Map.Entry<String, byte[]> entry : sortedMap.entrySet()) {
                 fileName = entry.getKey();
 
-                ogSize = Integer.parseInt(fileName.substring(0, fileName.lastIndexOf('/')));
+                ogSize = TypeCodeUtil.fileNameToLastFileSize(fileName);
 
                 byte[] dataBytes = entry.getValue();
 
@@ -160,7 +155,7 @@ public class SignageFileUtil {
                 MiniLZO.lzo1x_decompress(dataBytes, ogSize, dataBytes2, outL2);
 
 //                logger.info("解压缩后的长度 outLen  len:" +outL2.v);
-                System.arraycopy(dataBytes2, 0, data, length, outL2.v);
+                System.arraycopy(dataBytes2, 0, data1, length, outL2.v);
 
                 MiniLZOVo miniLZOVo = new MiniLZOVo();
                 miniLZOVo.setOgSize(ogSize);
@@ -171,9 +166,14 @@ public class SignageFileUtil {
                 length = length + ogSize;
 
             }
+            byte[] data  ;
+            if(length == SignageDrawUtil.height * SignageDrawUtil.width){
+                data = data1;
+            }else{
+                data = new byte[length ] ;
+                System.arraycopy(data1, 0, data, 0, data.length);
+            }
 
-//            byte[] dataBytes33 = new byte[4];
-//            System.arraycopy(data,data.length-4,dataBytes33,0,4);
 
             byte[] dataBytes3 = new byte[data.length - 4];
             System.arraycopy(data, 0, dataBytes3, 0, data.length - 4);
@@ -267,7 +267,7 @@ public class SignageFileUtil {
 
             MiniLZOVo miniLZOVo = miniLZOVoList.get(i);
 
-            sizeMap.put(miniLZOVo.getOgSize() + "/" + fileName, miniLZOVo);
+            sizeMap.put(fileName, miniLZOVo);
         }
 
         return sizeMap;

+ 32 - 0
src/main/java/com/yeechart/dotMatrix/signage/TypeCodeUtil.java

@@ -223,4 +223,36 @@ public class TypeCodeUtil {
 
     }
 
+
+    /**
+     * 由于不使用数据库以及,OSS中不能存在原字节大小的问题
+     * 根据type 得到最后一个文件的大小
+     * @param fileName
+     * @return
+     */
+    public static int fileNameToLastFileSize(String fileName){
+
+        /**
+         *  03 8884
+         * 000000 01010100 01010101 00010000 00010001
+         * 010001FF00 010001FF01 010001FF02 010001FF03 010001FF04   010001FF05 010001FFFE
+         * 02 3764
+         * 0100010000 0100010001 0100010002 0100010003 0100010004 0100010005
+         * 01000100FE 01000101FF 01000102FF 01000103FF
+         */
+
+        String typeCode = fileName.substring(0,fileName.length()-2);
+        int fileNumber = Integer.parseInt(fileName.substring(fileName.length()-2));
+        if(fileNumber <=1){
+            return 10000;
+        }
+        if( typeCode.startsWith("00") // 关机画面
+                ||  "01".equals(typeCode.substring(2,4)) //右屏相关
+                ||  "FF".equals(typeCode.substring(typeCode.length() - 4,typeCode.length() - 24))//倒数第二个为FF
+            ){
+            return 8884;
+        }else{
+            return 3764;
+        }
+    }
 }