diff --git a/src/main/java/de/hsel/spm/baudas/HelloWorld.java b/src/main/java/de/hsel/spm/baudas/HelloWorld.java
deleted file mode 100644
index 1cca1c8..0000000
--- a/src/main/java/de/hsel/spm/baudas/HelloWorld.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package de.hsel.spm.baudas;
-
-import javax.servlet.annotation.WebServlet;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.io.PrintWriter;
-
-/**
- * Hello World.
- *
- * @author Johannes Theiner
- * @version 0.1
- * @since 0.1
- */
-
-@WebServlet("/")
-public class HelloWorld extends HttpServlet {
-
- private static final long serialVersionUID = 156790693L;
-
- /**
- * doGet.
- *
- * @param req Request
- * @param resp Response
- * @throws IOException failed
- */
- @Override
- protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
- throws IOException {
-
- resp.setContentType("text/html");
- final PrintWriter out = resp.getWriter();
- out.println("");
- out.println("
");
- out.println("Hallo Welt!");
- out.println("");
- out.println("");
- out.println("Hallo Ostfriesland!
");
- out.println("");
- out.println("");
- }
-}
diff --git a/src/main/java/de/hsel/spm/baudas/web/Data.java b/src/main/java/de/hsel/spm/baudas/web/Data.java
index ed3581e..346e3ac 100644
--- a/src/main/java/de/hsel/spm/baudas/web/Data.java
+++ b/src/main/java/de/hsel/spm/baudas/web/Data.java
@@ -1,15 +1,18 @@
package de.hsel.spm.baudas.web;
import lombok.Getter;
+import org.jetbrains.annotations.Contract;
+import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
/**
+ *
+ *
* @author Johannes Theiner
* @version 0.1
* @since 0.1
@@ -17,23 +20,35 @@ import java.util.concurrent.ConcurrentMap;
public class Data {
@Getter
- private static ConcurrentMap files = new ConcurrentHashMap<>();
+ private static ConcurrentLinkedQueue files = new ConcurrentLinkedQueue<>();
- public static Path add(String name) {
+ @NotNull
+ static Path add(@NotNull String name) {
Path path;
+ UUID uuid = UUID.randomUUID();
if(files.size() >= 5) {
- path = null;
- files.put(UUID.randomUUID(), name);
+ SavedFile file = files.poll();
+ if(!get(file.getUuid()).delete()) {
+ System.out.println("failed");
+ }
+ path = Paths.get(getFileName(uuid));
+ files.offer(new SavedFile(uuid, name));
}else {
- UUID uuid = UUID.randomUUID();
- files.put(uuid, name);
- path = Paths.get("target/" + uuid + ".csv");
+ files.add(new SavedFile(uuid, name));
+ path = Paths.get(getFileName(uuid));
}
return path;
}
- public static File get(int index) {
- return new File("target/" + index + ".csv");
+ @Contract
+ @NotNull public static File get(@NotNull UUID uuid) {
+ return new File(getFileName(uuid));
+ }
+
+ @Contract(pure = true)
+ @NotNull
+ private static String getFileName(@NotNull UUID uuid) {
+ return "target/" + uuid + ".csv";
}
}
\ No newline at end of file
diff --git a/src/main/java/de/hsel/spm/baudas/web/Files.java b/src/main/java/de/hsel/spm/baudas/web/Files.java
index 56ff232..e586c08 100644
--- a/src/main/java/de/hsel/spm/baudas/web/Files.java
+++ b/src/main/java/de/hsel/spm/baudas/web/Files.java
@@ -9,8 +9,11 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
+import java.nio.charset.StandardCharsets;
/**
+ * list all currently available files.
+ *
* @author Johannes Theiner
* @version 0.1
* @since 0.1
@@ -22,6 +25,7 @@ public class Files extends HttpServlet {
@Override
protected void doGet(@NotNull HttpServletRequest req, @NotNull HttpServletResponse resp) throws IOException {
resp.setContentType("application/json");
+ resp.setCharacterEncoding(StandardCharsets.UTF_8.name());
PrintWriter out = resp.getWriter();
Gson gson = new Gson();
out.println(gson.toJson(Data.getFiles()));
diff --git a/src/main/java/de/hsel/spm/baudas/web/SavedFile.java b/src/main/java/de/hsel/spm/baudas/web/SavedFile.java
new file mode 100644
index 0000000..3ed9901
--- /dev/null
+++ b/src/main/java/de/hsel/spm/baudas/web/SavedFile.java
@@ -0,0 +1,14 @@
+package de.hsel.spm.baudas.web;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+import java.util.UUID;
+
+@Getter
+@AllArgsConstructor
+public class SavedFile {
+
+ private UUID uuid;
+ private String name;
+}
\ No newline at end of file
diff --git a/src/main/java/de/hsel/spm/baudas/web/Upload.java b/src/main/java/de/hsel/spm/baudas/web/Upload.java
index 5da00e2..92c992b 100644
--- a/src/main/java/de/hsel/spm/baudas/web/Upload.java
+++ b/src/main/java/de/hsel/spm/baudas/web/Upload.java
@@ -18,6 +18,8 @@ import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
/**
+ * saves uploaded files.
+ *
* @author Johannes Theiner
* @version 0.1
* @since 0.1
diff --git a/src/main/webapp/upload-test.html b/src/main/webapp/upload-test.html
new file mode 100644
index 0000000..b57a823
--- /dev/null
+++ b/src/main/webapp/upload-test.html
@@ -0,0 +1,11 @@
+
+
+
+
+
+
\ No newline at end of file