On Tue, 13 May 2025 15:33:39 GMT, Brian Burkhalter <[email protected]> wrote:
>> Implement the requested methods and add a test thereof.
>
> Brian Burkhalter has updated the pull request incrementally with one
> additional commit since the last revision:
>
> 8354724: "stream" -> "reader"
src/java.base/share/classes/java/io/Reader.java line 205:
> 203: public String readAllAsString() throws IOException {
> 204: ensureOpen();
> 205: String result = cs.toString().substring(next);
For sake of efficiency can we please *first* limit and copy *last*? If `cs`
refers to a huge object and `next` is just few bytes before `length()`, it
makes no sense to copy the huge memory block just to return one or two
characters finally. 🤔
`result = cs.subSequence(next, cs.length()).toString()`?
src/java.base/share/classes/java/io/Reader.java line 500:
> 498: * @since 25
> 499: */
> 500: public String readAllAsString() throws IOException {
Still thinking that declaring `CharSequence` instead of `String` would be
beneficial. In case a `Reader` implementation reads from I/O, the
implementation could so return a block of native memory without turning it into
a Java `String` just for sake of fulfilling the API. In case of servers for
example, the information often is passed-through from one I/O source to another
I/O sink *unmodified*, which means, the `String` then is turned into *a new*
native memory block again; double native memory used *plus* on-heap memory
used, without any benefit. Can we please provide I/O APIs which do *not*
enforce duplicate copying to and from `String` in such scenarios? 😃
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24728#discussion_r2089421861
PR Review Comment: https://git.openjdk.org/jdk/pull/24728#discussion_r2089436642