RFR: 8353795: Add Writer.of(StringBuilder)

Chen Liang liach at openjdk.org
Sun May 4 14:57:51 UTC 2025


On Sat, 5 Apr 2025 17:36:29 GMT, Markus KARG <duke at openjdk.org> wrote:

> This Pull Requests proposes an implementation for [JDK-8353795](https://bugs.openjdk.org/browse/JDK-8353795): Adding the new method `public static Writer Writer.of(StringBuilder)`, providing a non-synchronized Writer implementation optimized for writing into `StringBuilder`.
> 
> A basic test is provided to proof that the new `Writer` behaves as expected. For comparison, the same test is also run against `StringWriter`.

src/java.base/share/classes/java/nio/X-Buffer.java.template line 2:

> 1: /*
> 2:  * Copyright (c) 2000, 2025, Oracle and/or its affiliates. All rights reserved.

Redundant change.

test/jdk/java/io/Writer/Of.java line 45:

> 43:         @Override
> 44:         public String toString() {
> 45:             return id; // allows to identify config when test case fails

I used the same strategy in junit tests; the default toString already includes id=..., so I usually don't provide an explicit override to make the code concise.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24469#discussion_r2072637744
PR Review Comment: https://git.openjdk.org/jdk/pull/24469#discussion_r2072638134


More information about the nio-dev mailing list