6218397: Printing to file does not throw a PrinterException if the file cannot be created

Reviewed-by: prr, jdv
This commit is contained in:
Prasanta Sadhukhan 2016-07-01 10:54:18 +05:30
parent 41e155e1e1
commit fa55ad2d91
2 changed files with 9 additions and 1 deletions

View file

@ -501,7 +501,7 @@ public class PSPrinterJob extends RasterPrinterJob {
// Note that we only open a file if it has been nominated by // Note that we only open a file if it has been nominated by
// the end-user in a dialog that we ouselves put up. // the end-user in a dialog that we ouselves put up.
OutputStream output; OutputStream output = null;
if (epsPrinter == null) { if (epsPrinter == null) {
if (getPrintService() instanceof PSStreamPrintService) { if (getPrintService() instanceof PSStreamPrintService) {
@ -526,6 +526,7 @@ public class PSPrinterJob extends RasterPrinterJob {
spoolFile = new File(mDestination); spoolFile = new File(mDestination);
output = new FileOutputStream(spoolFile); output = new FileOutputStream(spoolFile);
} catch (IOException ex) { } catch (IOException ex) {
abortDoc();
throw new PrinterIOException(ex); throw new PrinterIOException(ex);
} }
} else { } else {
@ -771,6 +772,10 @@ public class PSPrinterJob extends RasterPrinterJob {
if (mPSStream != null) { if (mPSStream != null) {
mPSStream.println(EOF_COMMENT); mPSStream.println(EOF_COMMENT);
mPSStream.flush(); mPSStream.flush();
if (mPSStream.checkError()) {
abortDoc();
throw new PrinterException("Error while writing to file");
}
if (mDestType != RasterPrinterJob.STREAM) { if (mDestType != RasterPrinterJob.STREAM) {
mPSStream.close(); mPSStream.close();
} }

View file

@ -1627,6 +1627,9 @@ public abstract class RasterPrinterJob extends PrinterJob {
(!f.isFile() || !f.canWrite())) || (!f.isFile() || !f.canWrite())) ||
((pFile != null) && ((pFile != null) &&
(!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) { (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
if (f.exists()) {
f.delete();
}
throw new PrinterException("Cannot write to file:"+ throw new PrinterException("Cannot write to file:"+
dest); dest);
} }