commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject Re: [IO] Missing Reader / Writer implementations
Date Thu, 01 Aug 2019 12:16:32 GMT
On Thu, Aug 1, 2019 at 6:39 AM Rob Spoor <apache@icemanx.nl> wrote:

> Hi,
>
> I noticed that a lot of InputStream / OutputStream implementations do
> not have a matching Reader / Writer implementation. Some would really be
> useful.
>
> I've made an overview of classes that could be added:
> * AutoCloseReader
> * BrokenReader
> * CloseShieldReader
> * ClosedReader
> * CountingReader
> * DemuxReader
> * InfiniteCircularReader
> * ObservableReader
> * TaggedReader
> * TeeReader
> * UnixLineEndingReader
> * WindowsLineEndingReader
>
> * AppendableWriter
> * BrokenWriter
> * CloseShieldWriter
> * ClosedWriter
> * CountingWriter
> * DeferredFileWriter
> * DemuxWriter
> * TaggedWriter
> * TeeWriter
> * ThresholdingWriter
>
>
> I am willing to write the following (based on the InputStream
> implementations), if needed. I have signed the ICLA, have a JIRA account
> (username Spoor) and a GitHub account (username robtimus):
>
> * AutoCloseReader
> * BrokenReader
> * CloseShieldReader
> * ClosedReader
> * CountingReader
> * TaggedReader
> * TeeReader
>
> * AppendableWriter
> * BrokenWriter
> * CloseShieldWriter
> * ClosedWriter
> * CountingWriter
> * TaggedWriter
> * TeeWriter
>
>
> In addition, if AppendableWriter is added, I think there should be a
> method added to IOUtils, to prevent having to create an AppendableWriter
> for an object that's already a Writer:
>
>      public static Writer writer(final Appendable appendable) {
>          if (appendable == null) {
>              throw new NullPointerException();
>          }
>          return appendable instanceof Writer ?
>                  (Writer) appendable : new AppendableWriter(appendable);
>      }
>

That is too broad a test IMO, keep it simple at first.

Also, in general the kind of NPE test you show is best written
using java.util.Objects.requireNonNull(T, String), for example, in this
case:

Objects.requireNonNull(appendable, "appendable");

That said you should also consider if a null input should simply return a
null output. But in the case of new readers and writers, it might be
simplest to follow what the JRE does with such inputs, for consistency's
sake ;-)

Gary


>
>
> Kind regards,
>
> Rob
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message