|
@@ -19,10 +19,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.io.ByteArrayInputStream;
|
|
|
+import java.io.BufferedInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -67,55 +68,43 @@ public class DmpSoftwareUpgradeServiceImpl extends AbstractCrudService<DmpSoftwa
|
|
|
InputStream inputStream = null;
|
|
|
List<DmpSoftwareSubpackage> list = new ArrayList<>();
|
|
|
try {
|
|
|
- byte [] byteArr=multipartFile.getBytes();
|
|
|
- inputStream = new ByteArrayInputStream(byteArr);
|
|
|
+// byte [] byteArr=multipartFile.getBytes();
|
|
|
+ inputStream = new BufferedInputStream(multipartFile.getInputStream());
|
|
|
//创建规定大小的byte数组
|
|
|
byte[] b = new byte[num];
|
|
|
//name为以后的小文件命名做准备
|
|
|
int name = 0;
|
|
|
//遍历将大文件读入byte数组中,当byte数组读满后写入对应的小文件中
|
|
|
-
|
|
|
int len,crc,cur = 0;
|
|
|
- while((len = inputStream.read(b))!=-1) {
|
|
|
- crc = 0;
|
|
|
- for(int i=0;i<len;i++) {
|
|
|
- String str = Integer.toHexString(b[i]&0x00ff);
|
|
|
- if(str.length()==1)
|
|
|
- str = "0"+str;
|
|
|
- System.out.print(str+" ");
|
|
|
- crc = (crc + (b[i]&0x00ff))&0xffff;
|
|
|
+// while((len = inputStream.read(b))!=-1) {
|
|
|
+// crc = 0;
|
|
|
+// for(int i=0;i<len;i++) {
|
|
|
+// crc = (crc + (b[i]&0x00ff))&0xffff;
|
|
|
+// }
|
|
|
+// DmpSoftwareSubpackage dmpSoftwareSubpackage = new DmpSoftwareSubpackage();
|
|
|
+// dmpSoftwareSubpackage.setUpgradeId(dmpSoftwareUpgrade.getId());
|
|
|
+// dmpSoftwareSubpackage.setSubpackageNumber(cur);
|
|
|
+// byte[] bytes = Arrays.copyOf(b, len);
|
|
|
+// dmpSoftwareSubpackage.setApplyPackage(bytes);
|
|
|
+// dmpSoftwareSubpackage.setSubpackageLength(String.valueOf(len));
|
|
|
+// dmpSoftwareSubpackage.setCheckCode(Integer.toHexString(crc));
|
|
|
+// list.add(dmpSoftwareSubpackage);
|
|
|
+// cur++;
|
|
|
+// }
|
|
|
+ while ((len = inputStream.read(b)) != -1) {
|
|
|
+ int chk = 0x0000;
|
|
|
+ for(int i=0;i<len;i++){
|
|
|
+ chk += b[i]&0x00ff;
|
|
|
}
|
|
|
-
|
|
|
DmpSoftwareSubpackage dmpSoftwareSubpackage = new DmpSoftwareSubpackage();
|
|
|
dmpSoftwareSubpackage.setUpgradeId(dmpSoftwareUpgrade.getId());
|
|
|
dmpSoftwareSubpackage.setSubpackageNumber(name);
|
|
|
- dmpSoftwareSubpackage.setApplyPackage(b);
|
|
|
- if (len < 1024){
|
|
|
- dmpSoftwareSubpackage.setApplyPackage(subBytes(b,0,len));
|
|
|
- }
|
|
|
+ dmpSoftwareSubpackage.setApplyPackage(Arrays.copyOf(b, len));
|
|
|
dmpSoftwareSubpackage.setSubpackageLength(String.valueOf(len));
|
|
|
- dmpSoftwareSubpackage.setCheckCode(Integer.toHexString(crc));
|
|
|
+ dmpSoftwareSubpackage.setCheckCode(String.format("%04x", chk& 0x0000ffff));
|
|
|
list.add(dmpSoftwareSubpackage);
|
|
|
- System.out.println("\n"+cur+") len:"+len+"\tcrc:"+Integer.toHexString(crc));
|
|
|
- cur++;
|
|
|
+ name++;
|
|
|
}
|
|
|
-// while ((len = inputStream.read(b)) != -1) {
|
|
|
-// int chk = 0x0000;
|
|
|
-// for(int i=0;i<len;i++){
|
|
|
-// chk += b[i]&0x00ff;
|
|
|
-// }
|
|
|
-// DmpSoftwareSubpackage dmpSoftwareSubpackage = new DmpSoftwareSubpackage();
|
|
|
-// dmpSoftwareSubpackage.setUpgradeId(dmpSoftwareUpgrade.getId());
|
|
|
-// dmpSoftwareSubpackage.setSubpackageNumber(name);
|
|
|
-// dmpSoftwareSubpackage.setApplyPackage(b);
|
|
|
-// if (len < 1024){
|
|
|
-// dmpSoftwareSubpackage.setApplyPackage(subBytes(b,0,len));
|
|
|
-// }
|
|
|
-// dmpSoftwareSubpackage.setSubpackageLength(String.valueOf(len));
|
|
|
-// dmpSoftwareSubpackage.setCheckCode(String.format("%04x", chk& 0x0000ffff));
|
|
|
-// list.add(dmpSoftwareSubpackage);
|
|
|
-// name++;
|
|
|
-// }
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|