Transferring InputStream to OutputStream in JDK 9
One of the minor additions to JDK 9 that can make a sometimes routine task in Java even easier is the addition of the method InputStream.transferTo(OutputStream) . This method, as its name suggests, allows for the easy transfer (copy) of bytes from the input stream represented by the object the method is called upon to the output stream provided to that method. Or, as the method's Javadoc comment states, InputStream.transferTo(OutputStream) "reads all bytes from this input stream and writes the bytes to the given output stream in the order that they are read." There is more to the Javadoc comment on the InputStream.transferTo(OutputStream) method including these statements: "This method does not close either stream." " It is strongly recommended that both streams be promptly closed if an I/O error occurs." The easiest way to deal with the two concerns shown above that are expressed in the Javadoc comment for the InputStream.transferTo(OutputStream...