initial commit
This commit is contained in:
commit
2d70878d6b
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_20" project-jdk-name="21" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/SatReceiverUmbenenner.iml" filepath="$PROJECT_DIR$/SatReceiverUmbenenner.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
|
|
@ -0,0 +1,187 @@
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`,
|
||||||
|
// then press Enter. You can now see whitespace characters in your code.
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// /media/ubuntu/BACKUP/toRename"
|
||||||
|
File f = new File(args[0]);
|
||||||
|
if (f.isDirectory()) {
|
||||||
|
File[] list = f.listFiles();
|
||||||
|
for (File file : list) {
|
||||||
|
//System.out.println(file);
|
||||||
|
benenneUm(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
System.out.println("Angegebener Pfad ist nicht vorhanden oder kein Verzeichnis!\n"+args[0]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getCharFromByte(byte b)
|
||||||
|
{ String preview = String.valueOf((char)b);
|
||||||
|
if(b > 32 && b < 48 || b > 57 && b < 65 || b > 90 && b < 97 || b > 122)
|
||||||
|
return " ";
|
||||||
|
return switch (Byte.toUnsignedInt(b)) {
|
||||||
|
case 246 -> "ö";
|
||||||
|
case 228 -> "ä";
|
||||||
|
case 223 -> "ß";
|
||||||
|
case 252 -> "ü";
|
||||||
|
case 196 -> "Ä";
|
||||||
|
default -> String.valueOf((char)b);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public static void benenneUm(File f) {
|
||||||
|
String[] l = f.list();
|
||||||
|
for (File content : f.listFiles()) {
|
||||||
|
String name = content.getName();
|
||||||
|
if (name.equals("REC.TS")) {
|
||||||
|
File newFile = new File(content.getParentFile().getPath()+"/REC.00");
|
||||||
|
boolean success = content.renameTo(newFile);
|
||||||
|
if(!success)
|
||||||
|
System.out.println("konnte datei nicht umbenennen");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (content.getName().equals("META.DAT")) {
|
||||||
|
try {
|
||||||
|
byte[] fileContent = Files.readAllBytes(content.toPath());
|
||||||
|
ArrayList<byte[]> parts = splitByteArray(fileContent);
|
||||||
|
StringBuilder sender = new StringBuilder();
|
||||||
|
StringBuilder programm = new StringBuilder();
|
||||||
|
for (byte b : parts.get(0)) {
|
||||||
|
sender.append(getCharFromByte(b));
|
||||||
|
}
|
||||||
|
for (byte b : parts.get(1)) {
|
||||||
|
programm.append(getCharFromByte(b));
|
||||||
|
}
|
||||||
|
String pattern = "yyyy-MM-dd";
|
||||||
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
|
||||||
|
if(programm.toString().length() < 2)
|
||||||
|
programm = new StringBuilder();
|
||||||
|
else
|
||||||
|
programm.insert(0,"_");
|
||||||
|
String date = simpleDateFormat.format(new Date(content.lastModified()));
|
||||||
|
System.out.println(f.getName() + ": " + date +"_"+sender+programm );
|
||||||
|
File oldFile = content.getParentFile();
|
||||||
|
String newFileName = oldFile.getParentFile().getPath()+"/"+date +"_"+sender+programm;
|
||||||
|
newFileName = newFileName.replace(" {2}", " ").trim();
|
||||||
|
File newFile = new File(newFileName);
|
||||||
|
|
||||||
|
boolean success = oldFile.renameTo(newFile);
|
||||||
|
if(!success)
|
||||||
|
System.out.println("konnte datei nicht umbenennen");
|
||||||
|
|
||||||
|
/*
|
||||||
|
BufferedReader reader = new BufferedReader(new FileReader(content));
|
||||||
|
String currentLine = "";
|
||||||
|
String output = "";
|
||||||
|
currentLine = reader.readLine();
|
||||||
|
while (currentLine != null) {
|
||||||
|
output += currentLine;
|
||||||
|
currentLine = reader.readLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
reader.close();
|
||||||
|
*/
|
||||||
|
//System.out.println(f.getName() + ": " + f.lastModified() + ": " + output.replaceAll("\\p{C}", ""));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArrayList<byte[]> splitByteArray(byte[] input)
|
||||||
|
{
|
||||||
|
input = getPartOfArray(input, 13, input.length);
|
||||||
|
int start = 0;
|
||||||
|
int end = 0;
|
||||||
|
byte[] sender = new byte[0];
|
||||||
|
byte[] programm = new byte[0];
|
||||||
|
boolean hasFoundProgramm = false;
|
||||||
|
StringBuilder textOutput = new StringBuilder();
|
||||||
|
byte lastByte = Byte.MIN_VALUE;
|
||||||
|
for (byte b : input) {
|
||||||
|
|
||||||
|
|
||||||
|
if(b==0)
|
||||||
|
{
|
||||||
|
//System.out.print(Byte.toUnsignedLong(b));
|
||||||
|
if(sender.length == 0) {
|
||||||
|
sender = getPartOfArray(input, start, end);
|
||||||
|
start = end;
|
||||||
|
}
|
||||||
|
else if(hasFoundProgramm)
|
||||||
|
{
|
||||||
|
programm = getPartOfArray(input, start, end);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
textOutput.append(" ");
|
||||||
|
}else if(sender.length > 0 && b == 10)//Zeilenumbruch
|
||||||
|
{
|
||||||
|
start = end+1;
|
||||||
|
hasFoundProgramm = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(lastByte == 0) {
|
||||||
|
//System.out.print(" ");
|
||||||
|
textOutput.append(" ");
|
||||||
|
}
|
||||||
|
//System.out.printf("%02x", b);
|
||||||
|
//System.out.print(" ");
|
||||||
|
if(Byte.toUnsignedInt(b) == 246)
|
||||||
|
textOutput.append(" ö ");//148
|
||||||
|
else if(Byte.toUnsignedInt(b) == 228)
|
||||||
|
textOutput.append(" ä ");//132
|
||||||
|
else if(Byte.toUnsignedInt(b) == 223)
|
||||||
|
textOutput.append(" ß ");//225
|
||||||
|
else if(Byte.toUnsignedInt(b) == 252)
|
||||||
|
textOutput.append(" ü ");//129
|
||||||
|
else if(Byte.toUnsignedInt(b) == 196)
|
||||||
|
textOutput.append(" Ä ");
|
||||||
|
else if(Byte.toUnsignedInt(b) == 32)
|
||||||
|
textOutput.append(" _ ");
|
||||||
|
else if(b != 10)
|
||||||
|
textOutput.append(" ").append((char) b).append(" ");
|
||||||
|
else
|
||||||
|
textOutput.append(" ");
|
||||||
|
}
|
||||||
|
end++;
|
||||||
|
lastByte = b;
|
||||||
|
|
||||||
|
}
|
||||||
|
//System.out.println();
|
||||||
|
//System.out.println(textOutput);
|
||||||
|
String humanText = textOutput.toString().replaceAll("\\p{C}", "");
|
||||||
|
humanText = humanText.replaceAll("\\s+", "");
|
||||||
|
humanText = humanText.replaceAll("_", " ");
|
||||||
|
|
||||||
|
//System.out.println(humanText);
|
||||||
|
|
||||||
|
//System.out.println();
|
||||||
|
ArrayList<byte[]> result = new ArrayList<>();
|
||||||
|
result.add(sender);
|
||||||
|
result.add(programm);
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] getPartOfArray(byte[] array, int start, int end)
|
||||||
|
{
|
||||||
|
byte[] result = new byte[end-start];
|
||||||
|
int index = 0;
|
||||||
|
for (int i = start; i < end; i++) {
|
||||||
|
result[index] = array[i];
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue