featurre fertig
parent
a1c9d3bdda
commit
a61b239846
108
Main.java
108
Main.java
|
@ -2,6 +2,8 @@ import java.util.HashMap;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public class Main
|
public class Main
|
||||||
{
|
{
|
||||||
|
@ -66,6 +68,13 @@ public class Main
|
||||||
printBaum(byteString_to_baum(baum_to_byteString(wurzel)));
|
printBaum(byteString_to_baum(baum_to_byteString(wurzel)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void test3()
|
||||||
|
{
|
||||||
|
System.out.println(decodierungInlkBaum(codierungInklBaum("aaaabbc")));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static void printBaum(Node baum)
|
public static void printBaum(Node baum)
|
||||||
{
|
{
|
||||||
if(baum == null)return;
|
if(baum == null)return;
|
||||||
|
@ -131,6 +140,41 @@ public class Main
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String codierungInklBaum(String text)
|
||||||
|
{
|
||||||
|
//zahl wan angibt wan text kommt und baum aufhört
|
||||||
|
|
||||||
|
//decodiere baum, dcodierung text
|
||||||
|
|
||||||
|
|
||||||
|
Map<Character, Integer> zahlen = Zählen.countEachLetter(text);
|
||||||
|
Node baum = Node.erstellen(zahlen);
|
||||||
|
|
||||||
|
String codierterBaum = baum_to_byteString(baum);
|
||||||
|
String codierterText = codierung(text,baum);
|
||||||
|
|
||||||
|
int textErstIndex = codierterBaum.length() + 32;
|
||||||
|
String codiertertextErstIndex = Int_to_ByteString(textErstIndex);
|
||||||
|
|
||||||
|
System.out.println(codiertertextErstIndex + codierterBaum +" " + codierterText);
|
||||||
|
|
||||||
|
return codiertertextErstIndex + codierterBaum + codierterText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String decodierungInlkBaum(String code)
|
||||||
|
{
|
||||||
|
String codierterTextErstIndex = code.substring(0,32);
|
||||||
|
int textErstIndex = byteString_to_int(codierterTextErstIndex);
|
||||||
|
|
||||||
|
String codierterBaum = code.substring(32, textErstIndex);
|
||||||
|
Node decodierterBaum = byteString_to_baum(codierterBaum);
|
||||||
|
|
||||||
|
String codierterText = code.substring(textErstIndex, code.length());
|
||||||
|
String decodierterText = decodierungBaum(codierterText,decodierterBaum);
|
||||||
|
|
||||||
|
return decodierterText;
|
||||||
|
}
|
||||||
|
|
||||||
public static String decodierungBaum(String code,Node baum)
|
public static String decodierungBaum(String code,Node baum)
|
||||||
{
|
{
|
||||||
Node current = baum;
|
Node current = baum;
|
||||||
|
@ -168,6 +212,8 @@ public class Main
|
||||||
return decoded;
|
return decoded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static Byte ByteString_to_Byte (String byteString)
|
public static Byte ByteString_to_Byte (String byteString)
|
||||||
{
|
{
|
||||||
if(byteString.length() != 8)
|
if(byteString.length() != 8)
|
||||||
|
@ -314,5 +360,67 @@ public class Main
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void compressFile (String source, String target )
|
||||||
|
{
|
||||||
|
Path sourcePath = Path.of(source);
|
||||||
|
Path targetPath = Path.of(target);
|
||||||
|
|
||||||
|
if(Files.exists(sourcePath) == false)
|
||||||
|
{
|
||||||
|
System.out.println("Datei nicht gefunden");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String text;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
text = Files.readString(sourcePath);
|
||||||
|
}
|
||||||
|
catch(Exception error)
|
||||||
|
{
|
||||||
|
System.out.println(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String compressedText = codierungInklBaum(text);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Files.writeString(targetPath, compressedText);
|
||||||
|
}
|
||||||
|
catch(Exception error)
|
||||||
|
{
|
||||||
|
System.out.println(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void readFile(String file)
|
||||||
|
{
|
||||||
|
Path path = Path.of(file);
|
||||||
|
|
||||||
|
if(Files.exists(path) == false)
|
||||||
|
{
|
||||||
|
System.out.println("Datei nicht gefunden");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String compressedText;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
compressedText = Files.readString(path);
|
||||||
|
}
|
||||||
|
catch(Exception error)
|
||||||
|
{
|
||||||
|
System.out.println(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String text = decodierungInlkBaum(compressedText);
|
||||||
|
|
||||||
|
System.out.println(file+": " + text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
000000000000000000000000101100001111111111111111000000000110000111111111111111110000000001100010111111111111111100000000000010101111111111111111000000000110001100000000000011010000101011101111110
|
Loading…
Reference in New Issue