RFR: 8354724: Methods in java.io.Reader to read all characters and all lines [v19]
Markus KARG
duke at openjdk.org
Thu May 15 10:25:58 UTC 2025
On Thu, 15 May 2025 10:21:26 GMT, Markus KARG <duke at openjdk.org> wrote:
>>> > Maybe a good idea at this point if @mkarg could provide an example of server code benefitting from returning a CharSequence...
>>>
>>> The most simple example is a file server. Incidential fact, just today I wrote a function that simply passes JSON documents received in a REST call forward to another server using another REST call (without parsing it). The document is not changed. It is _inefficient_ to force it into a `String` temporarily. This is not untypical, such use cases exists often in server computing.
>>
>> Seems to me that in your example `Reader.transferTo(Writer)` would be the better choice instead of reading everything into a String or CharSequence and writing it to the next sink.
>
> If the source is a `Reader` **and** target is a `Writer`, yes. But what if it is a native piece of hardware, like an IoT device, which produces / consumes `CharSequence`?
Also, in JAX-RS for example, you cannot make use of `transferTo` as what you get is a heap object, and what you must forward also is a heap object.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24728#discussion_r2090844002
More information about the core-libs-dev
mailing list