Skip to content

Commit

Permalink
check file existence before upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobasco99 committed Aug 13, 2024
1 parent aa69bc3 commit a5f14d1
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Base64;
import java.util.Base64.Decoder;
Expand Down Expand Up @@ -403,7 +404,6 @@ public boolean storeFileLocally(String name, String text, String type) {
System.out.println(decodedBytes);
FileUtils.writeByteArrayToFile(f, decodedBytes);
textContent = readTxtFile("tmitocar/texts/" + name + "/" + fileName);
System.out.println("Text content: " + textContent);
} else if (type.toLowerCase().equals("application/pdf") || type.toLowerCase().equals("pdf")) {
byte[] decodedBytes = d.decode(text);
System.out.println(decodedBytes);
Expand Down Expand Up @@ -455,6 +455,17 @@ public void deleteFileLocally(String name) {

private void uploadToTmitocar(String label1, String fileName, String wordspec)
throws InterruptedException, IOException {

Path filePath = Paths.get("tmitocar/texts/" + label1 + "/" + fileName);

if (!Files.exists(filePath)) {
throw new IOException("File not found: " + filePath);
}
byte[] fileContent = Files.readAllBytes(filePath);
String fileTextContent = new String(fileContent);

System.out.println("File content: " + fileTextContent);

ProcessBuilder pb;
if (wordspec != null && wordspec.length() > 2) {
System.out.println("Using wordspec: " + wordspec);
Expand Down

0 comments on commit a5f14d1

Please sign in to comment.