Files
Testate/WS2526/Testat 3a/Main.java
T

71 lines
3.3 KiB
Java

import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
public class Main {
public static void main(String[] args) {
System.out.println();
System.out.println("=========================================");
System.out.println("Aufgabe 2 - I/O-Serialisierung von Listen");
System.out.println("=========================================");
System.out.println();
// Create a StringListSerializer to test our implementation
StringListSerializer serializer = new StringListSerializer();
Path erlkingPath = InMemoryPathFactory.createPath("/test/erlking.txt");
List<String> erlkingData = Arrays.asList(
"Who rides so late through night and wind?",
"It is the father with his child.",
"He holds the boy tightly in his arms,",
"He holds him safely, he keeps him warm.",
"My son, why do you hide your face so anxiously?",
"Father, do you not see the Erlking?",
"The Erlking with crown and tail?",
"My son, it is a streak of fog.",
"Come, go with me! Many pretty games I play with you;",
"Many colorful flowers are at the shore;",
"My mother has many golden garments.",
"Father, father, do you not hear what the Erlking promises me?",
"Be calm, stay calm, my child;",
"The wind rustles through the dry leaves.",
"Do you not want to come with me?",
"Father, father, do you not see the Erlking's daughter?",
"The Erlking's daughter with her golden garments?",
"My son, my son, I see it clearly:",
"The old willows look so gray and twisted.",
"I love you, I want to play with you,",
"And if you are not willing, I will use force.",
"Father, father, now he has seized me!",
"The Erlking has hurt me!",
"The father shudders, he rides swiftly,",
"He holds in his arms the moaning child,",
"He reaches the farmhouse with great effort;",
"In his arms, the child was dead.",
"- Johann Wolfgang von Goethe, 1782");
System.out.println("Writing 'Erlking' data to memory path: " + erlkingPath);
serializer.write(erlkingPath, erlkingData);
System.out.println("Wrote 'Erlking' data to memory path.");
System.out.println("");
System.out.println("Reading 'Erlking' data from memory path:");
List<String> erlkingReadData = serializer.read(erlkingPath);
for (String line : erlkingReadData) {
System.out.println(" " + line);
}
System.out.println("");
if (erlkingData.equals(erlkingReadData)) {
System.out.println("Read content matches original content.");
} else {
System.out.println("Read content does NOT match original content.");
}
System.out.println();
System.out.println("=========================================");
System.out.println("Aufgabe 3 - Exceptions");
System.out.println("=========================================");
System.out.println();
}
}