Replaced functionality with method if FileReaderWriter.

This commit is contained in:
WickedJack99
2024-04-07 12:01:05 +02:00
parent b603f297f7
commit 83c1858f65

View File

@@ -43,22 +43,9 @@ public record PullFileRequestRequest(Peer sender, Peer receiver, String fileName
if (!Files.exists(path)) {
System.err.println("File path doesn't exist.");
} else {
try {
//Write content to String and send data via sendingqueue to requesting peer
StringBuilder stringBuilder = new StringBuilder();
BufferedReader reader = new BufferedReader(new FileReader(new File(filePath)));
String line;
while ((line = reader.readLine()) != null) {
stringBuilder.append(line).append("\n");
}
reader.close();
String fileContent = stringBuilder.toString();
sendingQueue.add(new SendFileReply(thisPeer, sender, fileContent, fileName));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//Write content to String and send data via sendingqueue to requesting peer
String fileContent = FileReaderWriter.readFile(filePath);
sendingQueue.add(new SendFileReply(thisPeer, sender, fileContent, fileName));
}
}
}