|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
27 | 27 |
|
28 | 28 | import java.net.URI;
|
29 | 29 | import java.io.BufferedInputStream;
|
30 |
| -import java.io.BufferedOutputStream; |
31 | 30 | import java.io.File;
|
32 |
| -import java.io.FileOutputStream; |
33 |
| -import java.io.InputStream; |
34 |
| -import java.io.OutputStream; |
35 | 31 | import java.io.InputStream;
|
36 | 32 | import java.io.IOException;
|
37 |
| -import java.io.FileNotFoundException; |
38 | 33 | import java.io.Reader;
|
39 | 34 | import java.net.URL;
|
| 35 | +import java.nio.file.Files; |
| 36 | +import java.nio.file.Path; |
| 37 | +import java.nio.file.StandardCopyOption; |
40 | 38 | import java.util.Vector;
|
41 | 39 |
|
42 | 40 | import javax.print.CancelablePrintJob;
|
43 | 41 | import javax.print.Doc;
|
44 | 42 | import javax.print.DocFlavor;
|
45 |
| -import javax.print.DocPrintJob; |
46 | 43 | import javax.print.PrintService;
|
47 | 44 | import javax.print.PrintException;
|
48 | 45 | import javax.print.event.PrintJobEvent;
|
49 | 46 | import javax.print.event.PrintJobListener;
|
50 | 47 | import javax.print.event.PrintJobAttributeListener;
|
51 | 48 |
|
52 | 49 | import javax.print.attribute.Attribute;
|
53 |
| -import javax.print.attribute.AttributeSet; |
54 | 50 | import javax.print.attribute.AttributeSetUtilities;
|
55 | 51 | import javax.print.attribute.DocAttributeSet;
|
56 | 52 | import javax.print.attribute.HashPrintJobAttributeSet;
|
@@ -437,18 +433,7 @@ public void print(Doc doc, PrintRequestAttributeSet attributes)
|
437 | 433 |
|
438 | 434 | if (mDestination != null) { // if destination attribute is set
|
439 | 435 | try {
|
440 |
| - FileOutputStream fos = new FileOutputStream(mDestination); |
441 |
| - byte []buffer = new byte[1024]; |
442 |
| - int cread; |
443 |
| - |
444 |
| - while ((cread = instream.read(buffer, 0, buffer.length)) >=0) { |
445 |
| - fos.write(buffer, 0, cread); |
446 |
| - } |
447 |
| - fos.flush(); |
448 |
| - fos.close(); |
449 |
| - } catch (FileNotFoundException fnfe) { |
450 |
| - notifyEvent(PrintJobEvent.JOB_FAILED); |
451 |
| - throw new PrintException(fnfe.toString()); |
| 436 | + Files.copy(instream, Path.of(mDestination), StandardCopyOption.REPLACE_EXISTING); |
452 | 437 | } catch (IOException ioe) {
|
453 | 438 | notifyEvent(PrintJobEvent.JOB_FAILED);
|
454 | 439 | throw new PrintException(ioe.toString());
|
|
0 commit comments