diff --git a/src/main/java/com/dostalgia/StaticResource.java b/src/main/java/com/dostalgia/StaticResource.java index 071b71d..b1935a8 100644 --- a/src/main/java/com/dostalgia/StaticResource.java +++ b/src/main/java/com/dostalgia/StaticResource.java @@ -171,7 +171,15 @@ public class StaticResource { } else { // Partial content (Range request) — transfer only the requested bytes try (FileChannel ch = FileChannel.open(file, StandardOpenOption.READ)) { - ch.transferTo(offset, length, java.nio.channels.Channels.newChannel(output)); + long remaining = length; + long pos = offset; + while (remaining > 0) { + long written = ch.transferTo(pos, remaining, + java.nio.channels.Channels.newChannel(output)); + if (written <= 0) break; + pos += written; + remaining -= written; + } } } }