Close even more resources

This commit is contained in:
2022-10-30 15:37:04 +01:00
parent 39254c3c7d
commit 5b2ad781d2

View File

@@ -100,8 +100,10 @@ public class UploadService {
uploadedFile.downloadUrl = "/api/public/upload/" + user + "/" + uploadedFile.iv;
Optional<Path> filePathOptional;
try {
filePathOptional = Files.list(p)
.filter(p2 -> !p2.getFileName().toString().equals(".key")).findFirst();
Stream<Path> stream2 = Files.list(p)
.filter(p2 -> !p2.getFileName().toString().equals(".key"));
filePathOptional = stream.findFirst();
stream2.close();
if (filePathOptional.isPresent()) {
uploadedFile.name = filePathOptional.get().getFileName().toString();
uploadedFiles.add(uploadedFile);
@@ -136,8 +138,10 @@ public class UploadService {
}
try {
Optional<Path> filePathOptional = Files.list(folderPath)
.filter(p -> !p.getFileName().toString().equals(".key")).findFirst();
Stream<Path> stream = Files.list(folderPath)
.filter(p -> !p.getFileName().toString().equals(".key"));
Optional<Path> filePathOptional = stream.findFirst();
stream.close();
if (!filePathOptional.isPresent()) {
return Response.status(Response.Status.NOT_FOUND).build();
}