jakartaee / servlet

Jakarta Servlet
https://eclipse.org/ee4j/servlet
Other
253 stars 81 forks source link

Expose zero-copy file transfer in Servlet API #539

Open poutsma opened 11 months ago

poutsma commented 11 months ago

It would be nice if the Servlet spec would expose zero-copy file transfer operations, so that files can be written to the network socket without involving the CPU. In Java, zero-copy is exposed through the FileChannel::transferTo methods, but combing this channel-based API with the Servlet spec seems impossible.

For instance, this could take the form of a long transfer(Path file, long pos, long count) method on either ServletResponse or ServletOutputStream, that takes the file path, position and byte count, and returns the bytes written.