src/share/classes/sun/print/PSPrinterJob.java

Print this page




 670                     /* Write to a temporary file which will be spooled to
 671                      * the printer then deleted. In the case that the file
 672                      * is not removed for some reason, request that it is
 673                      * removed when the VM exits.
 674                      */
 675                     spoolFile = Files.createTempFile("javaprint", ".ps").toFile();
 676                     spoolFile.deleteOnExit();
 677 
 678                 result = new FileOutputStream(spoolFile);
 679                 return result;
 680             } catch (IOException ex) {
 681                 // If there is an IOError we subvert it to a PrinterException.
 682                 pex = new PrinterIOException(ex);
 683             }
 684             return null;
 685         }
 686     }
 687 
 688     // Inner class to run "privileged" to invoke the system print command
 689 

 690     private class PrinterSpooler implements java.security.PrivilegedAction {
 691         PrinterException pex;
 692 
 693         private void handleProcessFailure(final Process failedProcess,
 694                 final String[] execCmd, final int result) throws IOException {
 695             try (StringWriter sw = new StringWriter();
 696                     PrintWriter pw = new PrintWriter(sw)) {
 697                 pw.append("error=").append(Integer.toString(result));
 698                 pw.append(" running:");
 699                 for (String arg: execCmd) {
 700                     pw.append(" '").append(arg).append("'");
 701                 }
 702                 try (InputStream is = failedProcess.getErrorStream();
 703                         InputStreamReader isr = new InputStreamReader(is);
 704                         BufferedReader br = new BufferedReader(isr)) {
 705                     while (br.ready()) {
 706                         pw.println();
 707                         pw.append("\t\t").append(br.readLine());
 708                     }
 709                 } finally {




 670                     /* Write to a temporary file which will be spooled to
 671                      * the printer then deleted. In the case that the file
 672                      * is not removed for some reason, request that it is
 673                      * removed when the VM exits.
 674                      */
 675                     spoolFile = Files.createTempFile("javaprint", ".ps").toFile();
 676                     spoolFile.deleteOnExit();
 677 
 678                 result = new FileOutputStream(spoolFile);
 679                 return result;
 680             } catch (IOException ex) {
 681                 // If there is an IOError we subvert it to a PrinterException.
 682                 pex = new PrinterIOException(ex);
 683             }
 684             return null;
 685         }
 686     }
 687 
 688     // Inner class to run "privileged" to invoke the system print command
 689 
 690     @SuppressWarnings("finally") // Exception always thrown in finally block
 691     private class PrinterSpooler implements java.security.PrivilegedAction {
 692         PrinterException pex;
 693 
 694         private void handleProcessFailure(final Process failedProcess,
 695                 final String[] execCmd, final int result) throws IOException {
 696             try (StringWriter sw = new StringWriter();
 697                     PrintWriter pw = new PrintWriter(sw)) {
 698                 pw.append("error=").append(Integer.toString(result));
 699                 pw.append(" running:");
 700                 for (String arg: execCmd) {
 701                     pw.append(" '").append(arg).append("'");
 702                 }
 703                 try (InputStream is = failedProcess.getErrorStream();
 704                         InputStreamReader isr = new InputStreamReader(is);
 705                         BufferedReader br = new BufferedReader(isr)) {
 706                     while (br.ready()) {
 707                         pw.println();
 708                         pw.append("\t\t").append(br.readLine());
 709                     }
 710                 } finally {