Update StreamUtils.drain to use InputStream.transferTo with a null OutputStream. This avoids allocating buffers for cases where the supplied InputStream has an optimized transferTo method (e.g., ByteArrayInputStream and FileInputStream).

Additionally, update StreamUtils.emptyInput to simply call InputStream.nullInputStream.

Comment From: j3graham

There are a few more similar opportunities in StreamUtils: - copyToByteArray could use in.readAllBytes() instead of going through a ByteArrayOutputStream - copy(InputStream in, OutputStream out) could also use transferTo

Comment From: kilink

There are a few more similar opportunities in StreamUtils:

  • copyToByteArray could use in.readAllBytes() instead of going through a ByteArrayOutputStream
  • copy(InputStream in, OutputStream out) could also use transferTo

There's already a PR for that here: #27702