<Swing Dev> RFR: 8262161 Refactor manual I/O stream copying to new convinient methods in java.desktop

Andrey Turbanov github.com+741251+turbanoff at openjdk.java.net
Tue Feb 23 16:46:48 UTC 2021


On Tue, 23 Feb 2021 15:47:20 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

>> Cleanup code to use new handy methods in `java.io.InputStream`/`java.nio.file.Files` instead of manual stream copy:
>> 1. java.io.InputStream#readAllBytes
>> 2. java.io.InputStream#transferTo
>> 3. java.nio.file.Files#copy
>> 
>> Similar issue - https://bugs.openjdk.java.net/browse/JDK-8080272
>
> src/java.desktop/windows/classes/sun/print/Win32PrintJob.java line 436:
> 
>> 434:             if (mDestination != null) { // if destination attribute is set
>> 435:                 try {
>> 436:                     Files.copy(instream, Path.of(mDestination), StandardCopyOption.REPLACE_EXISTING);
> 
> Don't we need to close the instream in finally block?

It will be closed in `notifyEvent(PrintJobEvent.JOB_FAILED);` -> `closeDataStreams` in case of IOException.
And there shouldn't be any other kinds of exceptions.

-------------

PR: https://git.openjdk.java.net/jdk/pull/1856


More information about the swing-dev mailing list