mirror of
https://github.com/developersu/ns-usbloader.git
synced 2025-05-14 15:15:05 -04:00
Fix split-files validation. Add JUnit5 dependency on testing stage.
This commit is contained in:
parent
4cb3cbb491
commit
8771d551a4
7 changed files with 305 additions and 37 deletions
|
@ -77,12 +77,21 @@ public class NetworkSetupValidator {
|
|||
Arrays.sort(subFiles, Comparator.comparingInt(file -> Integer.parseInt(file.getName())));
|
||||
|
||||
for (int i = subFiles.length - 2; i > 0 ; i--){
|
||||
if (subFiles[i].length() < subFiles[i-1].length()) {
|
||||
if (subFiles[i].length() != subFiles[i-1].length()) {
|
||||
logPrinter.print("NET: Exclude split file: "+f.getName()+
|
||||
"\n Chunk sizes of the split file are not the same, but has to be.", EMsgType.WARNING);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
long firstFileLength = subFiles[0].length();
|
||||
long lastFileLength = subFiles[subFiles.length-1].length();
|
||||
|
||||
if (lastFileLength > firstFileLength){
|
||||
logPrinter.print("NET: Exclude split file: "+f.getName()+
|
||||
"\n Chunk sizes of the split file are not the same, but has to be.", EMsgType.WARNING);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -41,32 +41,40 @@ public abstract class TransferModule {
|
|||
this.task = task;
|
||||
this.logPrinter = printer;
|
||||
|
||||
// Validate split files to be sure that there is no crap
|
||||
//logPrinter.print("TransferModule: Validating split files ...", EMsgType.INFO); // NOTE: Used for debug
|
||||
Iterator<Map.Entry<String, File>> iterator = nspMap.entrySet().iterator();
|
||||
while (iterator.hasNext()){
|
||||
File f = iterator.next().getValue();
|
||||
if (f.isDirectory()){
|
||||
File[] subFiles = f.listFiles((file, name) -> name.matches("[0-9]{2}"));
|
||||
if (subFiles == null || subFiles.length == 0) {
|
||||
logPrinter.print("TransferModule: Removing empty folder: " + f.getName(), EMsgType.WARNING);
|
||||
iterator.remove();
|
||||
}
|
||||
else {
|
||||
Arrays.sort(subFiles, Comparator.comparingInt(file -> Integer.parseInt(file.getName())));
|
||||
|
||||
for (int i = subFiles.length - 2; i > 0 ; i--){
|
||||
if (subFiles[i].length() < subFiles[i-1].length()) {
|
||||
logPrinter.print("TransferModule: Removing strange split file: "+f.getName()+
|
||||
"\n (Chunk sizes of the split file are not the same, but has to be.)", EMsgType.WARNING);
|
||||
iterator.remove();
|
||||
} // what
|
||||
} // a
|
||||
} // nice
|
||||
} // stairway
|
||||
} // here =)
|
||||
//logPrinter.print("TransferModule: Validation complete.", EMsgType.INFO); // NOTE: Used for debug
|
||||
filterFiles();
|
||||
}
|
||||
void filterFiles(){
|
||||
nspMap.values().removeIf(f -> {
|
||||
if (f.isFile())
|
||||
return false;
|
||||
|
||||
File[] subFiles = f.listFiles((file, name) -> name.matches("[0-9]{2}"));
|
||||
|
||||
if (subFiles == null || subFiles.length == 0) {
|
||||
logPrinter.print("TransferModule: Exclude folder: " + f.getName(), EMsgType.WARNING);
|
||||
return true;
|
||||
}
|
||||
|
||||
Arrays.sort(subFiles, Comparator.comparingInt(file -> Integer.parseInt(file.getName())));
|
||||
|
||||
for (int i = subFiles.length - 2; i > 0 ; i--){
|
||||
if (subFiles[i].length() != subFiles[i-1].length()) {
|
||||
logPrinter.print("TransferModule: Exclude split file: "+f.getName()+
|
||||
"\n Chunk sizes of the split file are not the same, but has to be.", EMsgType.WARNING);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
long firstFileLength = subFiles[0].length();
|
||||
long lastFileLength = subFiles[subFiles.length-1].length();
|
||||
|
||||
if (lastFileLength > firstFileLength){
|
||||
logPrinter.print("TransferModule: Exclude split file: "+f.getName()+
|
||||
"\n Chunk sizes of the split file are not the same, but has to be.", EMsgType.WARNING);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
public EFileStatus getStatus(){ return status; }
|
||||
}
|
||||
|
|
|
@ -23,10 +23,10 @@ import java.nio.file.Path;
|
|||
import java.nio.file.Paths;
|
||||
|
||||
public class FilesHelper {
|
||||
public static String getRealFolder(String path){
|
||||
Path splitMergePath = Paths.get(path);
|
||||
if (Files.notExists(splitMergePath) || Files.isRegularFile(splitMergePath))
|
||||
public static String getRealFolder(String location){
|
||||
Path locationAsPath = Paths.get(location);
|
||||
if (Files.notExists(locationAsPath) || Files.isRegularFile(locationAsPath))
|
||||
return System.getProperty("user.home");
|
||||
return path;
|
||||
return location;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,10 +37,10 @@ public class RainbowHexDump {
|
|||
public static void hexDumpUTF8(byte[] byteArray){
|
||||
System.out.print(ANSI_BLUE);
|
||||
for (int i=0; i < byteArray.length; i++)
|
||||
System.out.print(String.format("%02d-", i%100));
|
||||
System.out.printf("%02d-", i%100);
|
||||
System.out.println(">"+ANSI_RED+byteArray.length+ANSI_RESET);
|
||||
for (byte b: byteArray)
|
||||
System.out.print(String.format("%02x ", b));
|
||||
System.out.printf("%02x ", b);
|
||||
System.out.println();
|
||||
System.out.print("\t\t\t"
|
||||
+ new String(byteArray, StandardCharsets.UTF_8)
|
||||
|
@ -49,10 +49,10 @@ public class RainbowHexDump {
|
|||
|
||||
public static void hexDumpUTF8ForWin(byte[] byteArray){
|
||||
for (int i=0; i < byteArray.length; i++)
|
||||
System.out.print(String.format("%02d-", i%100));
|
||||
System.out.printf("%02d-", i%100);
|
||||
System.out.println(">"+byteArray.length);
|
||||
for (byte b: byteArray)
|
||||
System.out.print(String.format("%02x ", b));
|
||||
System.out.printf("%02x ", b);
|
||||
System.out.println();
|
||||
System.out.print(new String(byteArray, StandardCharsets.UTF_8)
|
||||
+ "\n");
|
||||
|
@ -61,10 +61,10 @@ public class RainbowHexDump {
|
|||
public static void hexDumpUTF16LE(byte[] byteArray){
|
||||
System.out.print(ANSI_BLUE);
|
||||
for (int i=0; i < byteArray.length; i++)
|
||||
System.out.print(String.format("%02d-", i%100));
|
||||
System.out.printf("%02d-", i%100);
|
||||
System.out.println(">"+ANSI_RED+byteArray.length+ANSI_RESET);
|
||||
for (byte b: byteArray)
|
||||
System.out.print(String.format("%02x ", b));
|
||||
System.out.printf("%02x ", b);
|
||||
System.out.print(new String(byteArray, StandardCharsets.UTF_16LE)
|
||||
+ "\n");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue