Proposal for new public class: java.io.CharSequenceReader
Alan Bateman
alan.bateman at oracle.com
Mon Sep 30 07:07:10 UTC 2024
On 28/09/2024 17:15, Markus Karg wrote:
> :
>
> Alternatives:
>
> - Applications could use Apache Commons IO's CharSequenceReader. As it
> is an open-source third-party dependency, some authors might not be
> allowed to use it, or may not want to carry this additional burden
> just for the sake of this single performance improvement. In addition,
> this library is not very actively maintained; its Java baseline still
> is Java 8. There is no commercial support.
>
> - Applications could write their own Reader implementation. Given the
> assumption that this is a rather common use case, this imposes
> unjustified additional work for the authors of thousands of
> applications. It is hard to justify why there is a StringReader but
> not a CharSequenceReader.
>
> - Instead of writing a new CharSequenceReader class we could slightly
> modify StringReader, so it accepts CharSequences (not only Strings).
> This does not remove the synchronization overhead unless we decide to
> remove the synchronization from StringReader's implementation, and it
> would be confusing / surprising (in the negative sense) that a class
> named "StringReader" actually is a "CharSequenceReader".
>
>
Add to your list to explore is a static factory method on Reader, look
at Reader.nullReader. That would avoid exposing yet another very
specific implementation class in the API. The specification of that
method could say that is isn't safe for use by concurrent threads. That
doesn't excuse you completely from thinking about concurrent use as
Readers have a close method so you'll need to think about how close is
specified for when it is called while another thread is reading chars
from a custom CS.
-Alan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20240930/eaffd6c5/attachment.htm>
More information about the core-libs-dev
mailing list