diff --git a/src/main/java/sh/rhiobet/lalafin/file/FileInfoService.java b/src/main/java/sh/rhiobet/lalafin/file/FileInfoService.java index ef6d4e6..95b4cc4 100644 --- a/src/main/java/sh/rhiobet/lalafin/file/FileInfoService.java +++ b/src/main/java/sh/rhiobet/lalafin/file/FileInfoService.java @@ -8,6 +8,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; +import java.util.stream.Stream; import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; import javax.ws.rs.core.PathSegment; @@ -79,8 +80,8 @@ public class FileInfoService { Path path = null; try { path = rootFolderPath.resolve("file").resolve(requestedPath.replaceAll("^/*", "")); - } catch (Exception ignored) { - ignored.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); return null; } if (Files.exists(path)) { @@ -92,7 +93,8 @@ public class FileInfoService { requestedThumbUrl = Paths.get("/").resolve( rootFolderPath.relativize(requestedThumbPath)).toUri().getRawPath(); } - } catch (Exception ignored) { + } catch (Exception e) { + e.printStackTrace(); } if (Files.isDirectory(path)) { if (requestedFilename.isEmpty()) { @@ -107,7 +109,8 @@ public class FileInfoService { } StringBuilder playlistContent = new StringBuilder(); try { - Files.list(path).forEach(p -> { + Stream stream = Files.list(path); + stream.forEach(p -> { String fileName = p.getFileName().toString(); String fileUri = URLEncoder.encode(fileName, StandardCharsets.UTF_8) .replace("+", "%20"); @@ -124,7 +127,8 @@ public class FileInfoService { thumbPath = Paths.get("/lalafin/file" + requestedPath + "/.thumbnails/" + fileName + ".png"); } - } catch (Exception ignored) { + } catch (Exception e) { + e.printStackTrace(); } FileInfoBase contentInfo; @@ -177,12 +181,13 @@ public class FileInfoService { contentInfo.thumbnailUrl += ".png"; } } - } catch (Exception ignored) { - + } catch (Exception e) { + e.printStackTrace(); } } folderInfo.content.add(contentInfo); }); + stream.close(); if (playlistPath != null) { playlistPath.getParent().toFile().mkdirs(); Files.writeString(playlistPath, playlistContent.toString()); @@ -196,7 +201,8 @@ public class FileInfoService { + playlistFileUri) + "/" + playlistFileUri; folderInfo.playlist = playlistInfo; } - } catch (IOException ignored) { + } catch (IOException e) { + e.printStackTrace(); } return folderInfo; } else { diff --git a/src/main/java/sh/rhiobet/lalafin/file/ThumbnailService.java b/src/main/java/sh/rhiobet/lalafin/file/ThumbnailService.java index 3e2211c..f5d3e86 100644 --- a/src/main/java/sh/rhiobet/lalafin/file/ThumbnailService.java +++ b/src/main/java/sh/rhiobet/lalafin/file/ThumbnailService.java @@ -8,6 +8,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.NoSuchElementException; import java.util.Optional; +import java.util.stream.Stream; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import javax.enterprise.context.ApplicationScoped; @@ -87,11 +88,13 @@ public class ThumbnailService { + URLDecoder.decode(folderInfo.directUrl, StandardCharsets.UTF_8)); try { - Optional imgPath = Files.list(folderPath).sorted() + Stream stream = Files.list(folderPath); + Optional imgPath = stream.sorted() .filter(p -> !Files.isDirectory(p) && (p.toString().toLowerCase().endsWith(".png") || p.toString().toLowerCase().endsWith(".jpg"))) .findFirst(); + stream.close(); if (imgPath.isPresent()) { thumbPath.getParent().toFile().mkdirs(); diff --git a/src/main/java/sh/rhiobet/lalafin/upload/UploadService.java b/src/main/java/sh/rhiobet/lalafin/upload/UploadService.java index e3a2856..5e8fe3f 100644 --- a/src/main/java/sh/rhiobet/lalafin/upload/UploadService.java +++ b/src/main/java/sh/rhiobet/lalafin/upload/UploadService.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Optional; +import java.util.stream.Stream; import javax.crypto.Cipher; import javax.crypto.CipherInputStream; import javax.crypto.NoSuchPaddingException; @@ -92,7 +93,8 @@ public class UploadService { List uploadedFiles = new ArrayList<>(); try { - Files.list(folderPath).forEach(p -> { + Stream stream = Files.list(folderPath); + stream.forEach(p -> { final UploadedFile uploadedFile = new UploadedFile(); uploadedFile.iv = p.getFileName().toString(); uploadedFile.downloadUrl = "/api/public/upload/" + user + "/" + uploadedFile.iv; @@ -108,6 +110,7 @@ public class UploadService { e.printStackTrace(); } }); + stream.close(); return Response.ok(uploadedFiles).build(); } catch (IOException e) { e.printStackTrace(); @@ -185,8 +188,10 @@ public class UploadService { return Response.status(Response.Status.NOT_FOUND).build(); } try { - Files.walk(folderPath).sorted(Comparator.reverseOrder()).map(Path::toFile) - .forEach(File::delete); + Stream stream = Files.walk(folderPath).sorted( + Comparator.reverseOrder()).map(Path::toFile); + stream.forEach(File::delete); + stream.close(); return Response.ok().build(); } catch (IOException e) { e.printStackTrace();