diff --git a/src/main/java/sh/rhiobet/lalafin/path/PathFactory.java b/src/main/java/sh/rhiobet/lalafin/path/PathFactory.java index 424de13..1c5e0a3 100644 --- a/src/main/java/sh/rhiobet/lalafin/path/PathFactory.java +++ b/src/main/java/sh/rhiobet/lalafin/path/PathFactory.java @@ -8,7 +8,6 @@ import java.net.URLDecoder; import java.nio.charset.StandardCharsets; import java.nio.file.Paths; import java.util.List; -import java.util.stream.Collectors; import sh.rhiobet.lalafin.api.configuration.FileApiConfiguration; @@ -34,11 +33,7 @@ public class PathFactory { if (zipIndex >= 0 && zipIndex < names.size() - 1) { FileSystemPath zipFilePath = new FileSystemPath(names.subList(0, zipIndex + 1), rootFolderPath); - String zipEntryName = names.stream() - .skip(zipIndex + 1) - .map(PathSegment::getPath) - .collect(Collectors.joining("/")); - return new ZipEntryPath(zipFilePath, zipEntryName); + return new ZipEntryPath(zipFilePath, names.subList(zipIndex + 1, names.size())); } else { return new FileSystemPath(names, rootFolderPath); } diff --git a/src/main/java/sh/rhiobet/lalafin/path/ZipEntryPath.java b/src/main/java/sh/rhiobet/lalafin/path/ZipEntryPath.java index a708d2c..521421c 100644 --- a/src/main/java/sh/rhiobet/lalafin/path/ZipEntryPath.java +++ b/src/main/java/sh/rhiobet/lalafin/path/ZipEntryPath.java @@ -4,8 +4,9 @@ import jakarta.ws.rs.core.PathSegment; import java.io.IOException; import java.io.InputStream; +import java.util.Arrays; import java.util.List; -import java.util.stream.Stream; +import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -17,20 +18,23 @@ public final class ZipEntryPath implements Path { FileSystemPath zipFilePath; List segments; + String entryName; - ZipEntryPath(List names, java.nio.file.Path rootFolderPath) { - this(new FileSystemPath(names.subList(0, names.size() - 1), rootFolderPath), - names.getLast().getPath()); + ZipEntryPath(FileSystemPath parent, List entryName) { + this.zipFilePath = parent; + this.segments = entryName.stream().map(PathSegment::getPath).toList(); + this.entryName = this.segments.stream().collect(Collectors.joining("/")); } ZipEntryPath(FileSystemPath parent, String entryName) { - this.segments = Stream.concat(parent.segments.stream(), Stream.of(entryName)).toList(); this.zipFilePath = parent; + this.segments = Arrays.asList(entryName.split("/")); + this.entryName = entryName; } @Override public String getURI() { - return this.segments.stream() + return this.zipFilePath.getURI() + this.segments.stream() .map(s -> "/" + Encode.encodePathSegment(s)) .reduce("", String::concat); } @@ -70,12 +74,12 @@ public final class ZipEntryPath implements Path { public InputStream getInputStream() throws IOException { ZipFile zipFile = new ZipFile(this.zipFilePath.absolutePath.toFile()); return new ZipEntryInputStream(zipFile, - zipFile.getInputStream(zipFile.getEntry(this.segments.getLast()))); + zipFile.getInputStream(zipFile.getEntry(this.entryName))); } private void fetchEntryData() { try (ZipFile zipFile = new ZipFile(this.zipFilePath.absolutePath.toFile())) { - ZipEntry zipEntry = zipFile.getEntry(this.segments.getLast()); + ZipEntry zipEntry = zipFile.getEntry(this.entryName); this.exists = zipEntry != null; if (this.exists) {