On Mon, 7 Jul 2025 07:33:58 GMT, Volkan Yazici <vyaz...@openjdk.org> wrote:
> Adds a new `ofFileChannel(FileChannel channel, long offset, long length)` > method to `java.net.HttpRequest.BodyPublishers` to provide an `HttpClient` > publisher to upload a certain region of a file. The new publisher does not > modify the state of the passed `FileChannel`, streams the file channel bytes > as it publishes (i.e., avoids reading the entire file into the memory), and > can be leveraged to implement sliced uploads. As noted in the Javadoc: > >> The file channel will not be closed upon completion. The caller is >> expected to manage the life cycle of the channel, and close it >> appropriately when not needed anymore. > > ### Implementation notes > > - `FileChannel` is preferred over `{Readable,Seekable}ByteChannel`, since the > latter does not provide a positional read without modifying the state of the > `FileChannel`, which is necessary to use a single `FileChannel` instance to > implement sliced uploads. > - `ofFileChannel(FileChannel,long,long)` is preferred over > `ofPath(Path,long,long)` to avoid overloading the maximum file descriptor > limit of the platform. This pull request has now been integrated. Changeset: dacd9af9 Author: Volkan Yazici <vyaz...@openjdk.org> URL: https://git.openjdk.org/jdk/commit/dacd9af9a02464d2d6144e29d851216641e836c9 Stats: 851 lines in 4 files changed: 846 ins; 2 del; 3 mod 8329829: HttpClient: Add a BodyPublishers.ofFileChannel method Reviewed-by: dfuchs, jpai, michaelm ------------- PR: https://git.openjdk.org/jdk/pull/26155