Library enhancement proposal for copying data from/to Reader/Writer InputStream/OutputStream

Patrick Reinhart patrick at reini.net
Mon Nov 24 16:34:23 UTC 2014


Hi Paul,

> Am 24.11.2014 um 15:32 schrieb Paul Sandoz <paul.sandoz at oracle.com>:
> 
> Hi Patrick,
> 
> To speed things along for now i recommend creating a new class say IOUtils or preferably ByteStreams. 

Hmm, in the case of Reader/Writer ByteStreams seams to be a bit confusing for me, should then the reader copy stuff go to also a separate class like „CharStreams“. Locally I created an implementation named „IOUtils“ containing a copy method for InputStream to OutputStream.

> You should keep things simple for an initial iteration and just add one static method :-) which is essentially a refined copy of the private method that Pavel pointed out. Then write some tests for that method [1]. Then consider any nio related classes for an equivalent copy method. Some other candidates to consider are on Guava's ByteStreams class:
> 
>  http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/io/ByteStreams.html

I will also take a look at this

> It's very easy to get carried away and over-engineer such utility methods thinking they need to be all things to all people so we need to consider them carefully and i think the ones you included with size and reporting are not required. Simply just one static method copying input to output will go a long way (i have lost count of how many times i have reimplemented that!).

For now a single copy(from, to) for Input-/OutputStream and Readable/Appendable would be perfect for now.

> Hth,
> Paul.
> 
> [1] You can download jtreg from here:
> 
>  https://adopt-openjdk.ci.cloudbees.com/view/OpenJDK/job/jtreg/
> 
> for executing JDK tests. Depending on how you want to write your tests you can also make ‚em run standalone too, but sometimes it is easier convenient to use testng and execute via jtreg.

The environment I will update in the next.

Patrick


More information about the core-libs-dev mailing list