I know about IOUtils and I know about FileChannel transferTo.
But I would really like to know if there is a stream copy method somewhere hidden in the normal Java runtime.
Something like public long copy( InputStream is, OutputStream os){…}
I know I can write it myself but I am curious.
AFAIK, there is no “secret” method / facility for doing this in the Java runtime libraries. If there was, you shouldn’t use it.
Secret methods … aka private APIs … are typically implemented that way for a good reason. For example, they may have behaviour that is not what is wanted in a general purpose API. This is often a good reason to avoid them.
Furthermore, Sun/Oracle has always taken the position that these APIs and/or their behaviors are liable to be changed or removed without notice. And indeed, this happens.
Finally, many IDEs, bug / style checkers and dependency management frameworks will get stroppy with you* if your code depends directly on the private APIs.
* Look it up 🙂