RFR: 8329829: HttpClient: Add a BodyPublishers.ofFileChannel method [v5]

Volkan Yazici vyazici at openjdk.org
Wed Jul 30 09:32:17 UTC 2025


> 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.

Volkan Yazici has updated the pull request incrementally with one additional commit since the last revision:

  Apply review feedback for `FileChannelPublisherTest`

-------------

Changes:
  - all: https://git.openjdk.org/jdk/pull/26155/files
  - new: https://git.openjdk.org/jdk/pull/26155/files/da698406..99503c0b

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=26155&range=04
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=26155&range=03-04

  Stats: 78 lines in 1 file changed: 37 ins; 20 del; 21 mod
  Patch: https://git.openjdk.org/jdk/pull/26155.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/26155/head:pull/26155

PR: https://git.openjdk.org/jdk/pull/26155


More information about the net-dev mailing list