forked from jasder/antlr
resource leak fix from Coverity Scan
This commit is contained in:
parent
9c186c8d52
commit
d4f2abc5e3
|
@ -81,14 +81,14 @@ public class GraphicsSupport {
|
||||||
public static void saveImage(final JComponent comp, String fileName)
|
public static void saveImage(final JComponent comp, String fileName)
|
||||||
throws IOException, PrintException
|
throws IOException, PrintException
|
||||||
{
|
{
|
||||||
if (fileName.endsWith(".ps") || fileName.endsWith(".eps") ) {
|
if ( fileName.endsWith(".ps") || fileName.endsWith(".eps") ) {
|
||||||
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
|
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
|
||||||
String mimeType = "application/postscript";
|
String mimeType = "application/postscript";
|
||||||
StreamPrintServiceFactory[] factories =
|
StreamPrintServiceFactory[] factories =
|
||||||
StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, mimeType);
|
StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, mimeType);
|
||||||
System.out.println(Arrays.toString(factories));
|
System.out.println(Arrays.toString(factories));
|
||||||
FileOutputStream out = new FileOutputStream(fileName);
|
|
||||||
if (factories.length > 0) {
|
if (factories.length > 0) {
|
||||||
|
FileOutputStream out = new FileOutputStream(fileName);
|
||||||
PrintService service = factories[0].getPrintService(out);
|
PrintService service = factories[0].getPrintService(out);
|
||||||
SimpleDoc doc = new SimpleDoc(new Printable() {
|
SimpleDoc doc = new SimpleDoc(new Printable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -115,6 +115,7 @@ public class GraphicsSupport {
|
||||||
DocPrintJob job = service.createPrintJob();
|
DocPrintJob job = service.createPrintJob();
|
||||||
PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
|
PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
|
||||||
job.print(doc, attributes);
|
job.print(doc, attributes);
|
||||||
|
out.close();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// parrt: works with [image/jpeg, image/png, image/x-png, image/vnd.wap.wbmp, image/bmp, image/gif]
|
// parrt: works with [image/jpeg, image/png, image/x-png, image/vnd.wap.wbmp, image/bmp, image/gif]
|
||||||
|
|
Loading…
Reference in New Issue