mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-18 01:54:47 +02:00
6218397: Printing to file does not throw a PrinterException if the file cannot be created
Reviewed-by: prr, jdv
This commit is contained in:
parent
41e155e1e1
commit
fa55ad2d91
2 changed files with 9 additions and 1 deletions
|
@ -501,7 +501,7 @@ public class PSPrinterJob extends RasterPrinterJob {
|
|||
// Note that we only open a file if it has been nominated by
|
||||
// the end-user in a dialog that we ouselves put up.
|
||||
|
||||
OutputStream output;
|
||||
OutputStream output = null;
|
||||
|
||||
if (epsPrinter == null) {
|
||||
if (getPrintService() instanceof PSStreamPrintService) {
|
||||
|
@ -526,6 +526,7 @@ public class PSPrinterJob extends RasterPrinterJob {
|
|||
spoolFile = new File(mDestination);
|
||||
output = new FileOutputStream(spoolFile);
|
||||
} catch (IOException ex) {
|
||||
abortDoc();
|
||||
throw new PrinterIOException(ex);
|
||||
}
|
||||
} else {
|
||||
|
@ -771,6 +772,10 @@ public class PSPrinterJob extends RasterPrinterJob {
|
|||
if (mPSStream != null) {
|
||||
mPSStream.println(EOF_COMMENT);
|
||||
mPSStream.flush();
|
||||
if (mPSStream.checkError()) {
|
||||
abortDoc();
|
||||
throw new PrinterException("Error while writing to file");
|
||||
}
|
||||
if (mDestType != RasterPrinterJob.STREAM) {
|
||||
mPSStream.close();
|
||||
}
|
||||
|
|
|
@ -1627,6 +1627,9 @@ public abstract class RasterPrinterJob extends PrinterJob {
|
|||
(!f.isFile() || !f.canWrite())) ||
|
||||
((pFile != null) &&
|
||||
(!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
|
||||
if (f.exists()) {
|
||||
f.delete();
|
||||
}
|
||||
throw new PrinterException("Cannot write to file:"+
|
||||
dest);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue