IDEMPIERE-5472 Unclosed resources (#1565)

* IDEMPIERE-5472 Unclosed resources

* IDEMPIERE-5472 Unclosed resources
This commit is contained in:
Elaine Tan 2022-11-17 17:35:15 +08:00 committed by GitHub
parent 4d9bc5340c
commit 2ff6378720
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 419 additions and 229 deletions

View File

@ -31,6 +31,7 @@ package org.adempiere.process;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
@ -103,7 +104,7 @@ public class HouseKeeping extends SvrProcess{
String pathFile = houseKeeping.getBackupFolder();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String dateString = dateFormat.format(date);
FileWriter file = new FileWriter(pathFile+File.separator+tableName+dateString+".xml");
FileWriter file = null;
StringBuilder sql = new StringBuilder("SELECT * FROM ").append(tableName);
if (whereClause != null && whereClause.length() > 0)
sql.append(" WHERE ").append(whereClause);
@ -112,6 +113,7 @@ public class HouseKeeping extends SvrProcess{
StringBuffer linexml = null;
try
{
file = new FileWriter(pathFile+File.separator+tableName+dateString+".xml");
pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
rs = pstmt.executeQuery();
while (rs.next()) {
@ -121,7 +123,6 @@ public class HouseKeeping extends SvrProcess{
}
if(linexml != null)
file.write(linexml.toString());
file.close();
}
catch (Exception e)
{
@ -129,6 +130,15 @@ public class HouseKeeping extends SvrProcess{
}
finally
{
if (file != null)
{
try {
file.close();
} catch (IOException e) {
e.printStackTrace();
}
}
DB.close(rs, pstmt);
pstmt = null;
rs=null;

View File

@ -368,6 +368,7 @@ public class ImportAccount extends SvrProcess
.append("WHERE i.C_ElementValue_ID IS NOT NULL AND e.AD_Tree_ID IS NOT NULL")
.append(" AND i.I_IsImported='Y' AND Processed='N' AND i.AD_Client_ID=").append(m_AD_Client_ID);
int noParentUpdate = 0;
PreparedStatement updateStmt = null;
try
{
pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
@ -376,7 +377,7 @@ public class ImportAccount extends SvrProcess
String updateSQL = "UPDATE AD_TreeNode SET Parent_ID=?, SeqNo=? "
+ "WHERE AD_Tree_ID=? AND Node_ID=?";
//begin e-evolution vpj-cd 15 nov 2005 PostgreSQL
PreparedStatement updateStmt = DB.prepareStatement(updateSQL, ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_UPDATABLE, get_TrxName());
updateStmt = DB.prepareStatement(updateSQL, ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_UPDATABLE, get_TrxName());
//end
//
while (rs.next())
@ -405,6 +406,8 @@ public class ImportAccount extends SvrProcess
}
finally
{
DB.close(updateStmt);
updateStmt = null;
DB.close(rs, pstmt);
rs = null;
pstmt = null;

View File

@ -434,10 +434,10 @@ public class ImportReportLine extends SvrProcess
.append(" WHERE I_ReportLine_ID=").append(I_ReportLine_ID).append(") ")
.append("WHERE PA_ReportSource_ID=").append(PA_ReportSource_ID).append(" ")
.append(clientCheck);
PreparedStatement pstmt_updateSource = DB.prepareStatement
(sqlt.toString(), get_TrxName());
PreparedStatement pstmt_updateSource = null;
try
{
pstmt_updateSource = DB.prepareStatement(sqlt.toString(), get_TrxName());
no = pstmt_updateSource.executeUpdate();
if (log.isLoggable(Level.FINEST)) log.finest("Update ReportSource = " + no + ", I_ReportLine_ID=" + I_ReportLine_ID + ", PA_ReportSource_ID=" + PA_ReportSource_ID);
noUpdateSource++;
@ -487,6 +487,8 @@ public class ImportReportLine extends SvrProcess
pstmt_insertSource = null;
DB.close(pstmt_setImported);
pstmt_setImported = null;
DB.close(pstmt_deleteSource);
pstmt_deleteSource = null;
}
// Set Error to indicator to not imported

View File

@ -205,6 +205,7 @@ public class InOutGenerate extends SvrProcess
}
catch (Exception e)
{
DB.close(pstmt);
throw new AdempiereException(e);
}
return generate(pstmt);

View File

@ -206,6 +206,7 @@ public class InvoiceGenerate extends SvrProcess
}
catch (Exception e)
{
DB.close(pstmt);
throw new AdempiereException(e);
}
return generate(pstmt);

View File

@ -175,7 +175,9 @@ public class RollUpCosts extends SvrProcess {
" JOIN PP_PRODUCT_BOMLINE bl ON b.PP_PRODUCT_BOM_ID = bl.PP_PRODUCT_BOM_ID" +
" WHERE b.AD_Client_ID=" + getAD_Client_ID() +" AND b.IsActive='Y' AND bl.IsActive='Y' AND b.BOMType='A' AND b.BOMUse='A')";
Trx trx = Trx.get(get_TrxName(), false);
RowSet results = DB.getRowSet(sql);
RowSet results = null;
try {
results = DB.getRowSet(sql);
while (results.next())
{
Savepoint savepoint = trx.setSavepoint(null);
@ -193,6 +195,9 @@ public class RollUpCosts extends SvrProcess {
count++;
}
}
} finally {
DB.close(results);
}
}
else //do it for all products
{
@ -201,7 +206,9 @@ public class RollUpCosts extends SvrProcess {
" JOIN PP_PRODUCT_BOMLINE bl ON b.PP_PRODUCT_BOM_ID = bl.PP_PRODUCT_BOM_ID" +
" WHERE b.AD_Client_ID=" + getAD_Client_ID() +" AND b.IsActive='Y' AND bl.IsActive='Y' AND b.BOMType='A' AND b.BOMUse='A')";
Trx trx = Trx.get(get_TrxName(), false);
RowSet results = DB.getRowSet(sql);
RowSet results = null;
try {
results = DB.getRowSet(sql);
while (results.next())
{
Savepoint savepoint = trx.setSavepoint(null);
@ -219,6 +226,9 @@ public class RollUpCosts extends SvrProcess {
count++;
}
}
} finally {
DB.close(results);
}
}
return count + " Product Cost Updated.";

View File

@ -115,8 +115,13 @@ public class TableCreateColumns extends SvrProcess
if (DB.isPostgreSQL())
tableName = tableName.toLowerCase();
// end globalqss 2005-10-24
ResultSet rs = md.getColumns(catalog, schema, tableName, null);
ResultSet rs = null;
try {
rs = md.getColumns(catalog, schema, tableName, null);
addTableColumn(rs, table);
} finally {
DB.close(rs);
}
}
StringBuilder msgreturn = new StringBuilder("#").append(m_count);
return msgreturn.toString();
@ -191,8 +196,12 @@ public class TableCreateColumns extends SvrProcess
if (DB.isPostgreSQL())
tableName = tableName.toLowerCase();
// end globalqss 2005-10-24
try {
rsC = md.getColumns(catalog, schema, tableName, null);
addTableColumn(rsC, table);
} finally {
DB.close(rsC);
}
}
} catch (Exception e) {
throw e;

View File

@ -476,14 +476,15 @@ public class MInfoWindow extends X_AD_InfoWindow implements ImmutablePOSupport
// try run sql
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(builder.toString(), get_TrxName());
pstmt.executeQuery();
rs = pstmt.executeQuery();
}catch (Exception ex){
log.log(Level.WARNING, ex.getMessage());
throw new AdempiereException(ex);
} finally {
DB.close(pstmt);
DB.close(rs, pstmt);
}
// valid state

View File

@ -1218,9 +1218,14 @@ public final class DB
{
// Bugfix Gunther Hoppe, 02.09.2005, vpj-cd e-evolution
CStatementVO info = new CStatementVO (RowSet.TYPE_SCROLL_INSENSITIVE, RowSet.CONCUR_READ_ONLY, DB.getDatabase().convertStatement(sql));
CPreparedStatement stmt = ProxyFactory.newCPreparedStatement(info);
RowSet retValue = stmt.getRowSet();
CPreparedStatement stmt = null;
RowSet retValue = null;
try {
stmt = ProxyFactory.newCPreparedStatement(info);
retValue = stmt.getRowSet();
} finally {
close(stmt);
}
return retValue;
} // getRowSet

View File

@ -20,6 +20,7 @@ package org.adempiere.pipo2;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.PreparedStatement;
@ -405,8 +406,6 @@ public class PackRollProcess extends SvrProcess {
target.write(data);
byteCount++;
}
source.close();
target.close();
System.out.println("Successfully copied " + byteCount + " bytes.");
} catch (Exception e) {
@ -415,6 +414,21 @@ public class PackRollProcess extends SvrProcess {
System.out.println(e.toString());
success = -1;
} finally {
if (source != null) {
try {
source.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (target != null) {
try {
target.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return success;
}

View File

@ -103,9 +103,10 @@ public class AdempiereActivator extends AbstractActivator {
localSession.saveEx();
}
FileOutputStream zipstream = null;
InputStream stream = null;
try {
// copy the resource to a temporary file to process it with 2pack
InputStream stream = context.getBundle().getEntry("/META-INF/2Pack.zip").openStream();
stream = context.getBundle().getEntry("/META-INF/2Pack.zip").openStream();
File zipfile = File.createTempFile(getName(), ".zip");
zipstream = new FileOutputStream(zipfile);
byte[] buffer = new byte[1024];
@ -124,6 +125,11 @@ public class AdempiereActivator extends AbstractActivator {
zipstream.close();
} catch (Exception e2) {}
}
if (stream != null) {
try {
stream.close();
} catch (Exception e2) {}
}
if (localSession != null)
localSession.logout();
}

View File

@ -225,9 +225,10 @@ public class Incremental2PackActivator extends AbstractActivator {
String suffix = "_"+path.substring(path.lastIndexOf("2Pack_"));
logger.log(Level.WARNING, "Installing " + getName() + " " + path + " ...");
FileOutputStream zipstream = null;
InputStream stream = null;
try {
// copy the resource to a temporary file to process it with 2pack
InputStream stream = packout.openStream();
stream = packout.openStream();
File zipfile = File.createTempFile(getName()+"_", suffix);
zipstream = new FileOutputStream(zipfile);
byte[] buffer = new byte[1024];
@ -247,6 +248,11 @@ public class Incremental2PackActivator extends AbstractActivator {
zipstream.close();
} catch (Exception e2) {}
}
if (stream != null) {
try {
stream.close();
} catch (Exception e2) {}
}
if (localSession != null)
localSession.logout();
}

View File

@ -194,9 +194,10 @@ public class Version2PackActivator extends AbstractActivator{
String suffix = "_"+path.substring(path.lastIndexOf("2Pack_"));
logger.log(Level.WARNING, "Installing " + getName() + " " + path + " ...");
FileOutputStream zipstream = null;
InputStream stream = null;
try {
// copy the resource to a temporary file to process it with 2pack
InputStream stream = packout.openStream();
stream = packout.openStream();
File zipfile = File.createTempFile(getName()+"_", suffix);
zipstream = new FileOutputStream(zipfile);
byte[] buffer = new byte[1024];
@ -216,6 +217,11 @@ public class Version2PackActivator extends AbstractActivator{
zipstream.close();
} catch (Exception e2) {}
}
if (stream != null) {
try {
stream.close();
} catch (Exception e2) {}
}
}
logger.log(Level.WARNING, getName() + " " + packout.getPath() + " installed");
}

View File

@ -114,7 +114,7 @@ public class EMailProcessor
// Cleanup
try
{
if (m_store.isConnected())
if (m_store != null && m_store.isConnected())
m_store.close();
}
catch (Exception e)
@ -181,12 +181,18 @@ public class EMailProcessor
protected int processInBox() throws Exception
{
// Folder
Folder folder;
Folder folder = null;
Folder inbox = null;
Folder requestFolder = null;
Folder workflowFolder = null;
Folder errorFolder = null;
int noProcessed = 0;
try {
folder = m_store.getDefaultFolder();
if (folder == null)
throw new IllegalStateException("No default folder");
// Open Inbox
Folder inbox = folder.getFolder("INBOX");
inbox = folder.getFolder("INBOX");
if (!inbox.exists())
throw new IllegalStateException("No Inbox");
inbox.open(Folder.READ_WRITE);
@ -195,19 +201,19 @@ public class EMailProcessor
+ "; New=" + inbox.getNewMessageCount());
// Open Request
Folder requestFolder = folder.getFolder("CRequest");
requestFolder = folder.getFolder("CRequest");
if (!requestFolder.exists() && !requestFolder.create(Folder.HOLDS_MESSAGES))
throw new IllegalStateException("Cannot create Request Folder");
requestFolder.open(Folder.READ_WRITE);
// Open Workflow
Folder workflowFolder = folder.getFolder("CWorkflow");
workflowFolder = folder.getFolder("CWorkflow");
if (!workflowFolder.exists() && !workflowFolder.create(Folder.HOLDS_MESSAGES))
throw new IllegalStateException("Cannot create Workflow Folder");
workflowFolder.open(Folder.READ_WRITE);
// Open Error
Folder errorFolder = folder.getFolder("AdempiereError");
errorFolder = folder.getFolder("AdempiereError");
if (!errorFolder.exists() && !errorFolder.create(Folder.HOLDS_MESSAGES))
throw new IllegalStateException("Cannot create Error Folder");
errorFolder.open(Folder.READ_WRITE);
@ -222,7 +228,6 @@ public class EMailProcessor
inbox.fetch(messages, fp);
**/
//
int noProcessed = 0;
int noError = 0;
for (int i = 0; i < messages.length; i++)
// for (int i = messages.length-1; i >= 0; i--) // newest first
@ -261,12 +266,47 @@ public class EMailProcessor
}
if (log.isLoggable(Level.INFO)) log.info("processInBox - Total=" + noProcessed + " - Errors=" + noError);
// Fini
} finally {
if (errorFolder != null && errorFolder.isOpen()) {
try {
errorFolder.close(false);
} catch (Exception e) {
e.printStackTrace();
}
}
if (requestFolder != null && requestFolder.isOpen()) {
try {
requestFolder.close(false);
} catch (Exception e) {
e.printStackTrace();
}
}
if (workflowFolder != null && workflowFolder.isOpen()) {
try {
workflowFolder.close(false);
//
} catch (Exception e) {
e.printStackTrace();
}
}
if (inbox != null && inbox.isOpen()) {
try {
inbox.close(true);
} catch (Exception e) {
e.printStackTrace();
}
}
if (folder != null && folder.isOpen()) {
try {
folder.close(false);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return noProcessed;
} // processInBox
@ -462,12 +502,16 @@ public class EMailProcessor
if (content instanceof InputStream)
{
StringBuilder sb = new StringBuilder();
InputStream is = (InputStream)content;
InputStream is = null;
try {
is = (InputStream)content;
int c;
while ((c = is.read()) != -1)
sb.append((char)c);
} finally {
if (is != null)
is.close();
}
deliveryMessage = sb.toString().trim();
}
else

View File

@ -571,6 +571,7 @@ public class ProcessDialog extends AbstractProcessDialog implements EventListene
}
if (pdfList.size() > 1) {
List<PdfReader> pdfReaders = new ArrayList<PdfReader>();
try {
File outFile = File.createTempFile("PrintShipments", ".pdf");
Document document = null;
@ -579,6 +580,7 @@ public class ProcessDialog extends AbstractProcessDialog implements EventListene
{
String fileName = f.getAbsolutePath();
PdfReader reader = new PdfReader(fileName);
pdfReaders.add(reader);
reader.consolidateNamedDestinations();
if (document == null)
{
@ -602,6 +604,11 @@ public class ProcessDialog extends AbstractProcessDialog implements EventListene
} catch (Exception e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
} finally {
for (PdfReader reader : pdfReaders)
{
if (reader != null)
reader.close();
}
//do no harm calling this twice
hideBusyDialog();
}
@ -656,6 +663,7 @@ public class ProcessDialog extends AbstractProcessDialog implements EventListene
}
if (pdfList.size() > 1) {
List<PdfReader> pdfReaders = new ArrayList<PdfReader>();
try {
File outFile = File.createTempFile("PrintInvoices", ".pdf");
Document document = null;
@ -663,6 +671,7 @@ public class ProcessDialog extends AbstractProcessDialog implements EventListene
for (File f : pdfList)
{
PdfReader reader = new PdfReader(f.getAbsolutePath());
pdfReaders.add(reader);
if (document == null)
{
document = new Document(reader.getPageSizeWithRotation(1));
@ -685,6 +694,11 @@ public class ProcessDialog extends AbstractProcessDialog implements EventListene
} catch (Exception e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
} finally {
for (PdfReader reader : pdfReaders)
{
if (reader != null)
reader.close();
}
//do no harm calling this twice
hideBusyDialog();
}

View File

@ -756,9 +756,10 @@ public class WArchiveViewer extends Archive implements IFormController, EventLis
descriptionField.setText(ar.getDescription());
helpField.setText(ar.getHelp());
InputStream in = null;
try
{
InputStream in = ar.getInputStream();
in = ar.getInputStream();
//pdfViewer.setScale(reportField.isSelected() ? 50 : 75);
if (in != null)
reportViewer(ar.getName(), ar.getBinaryData());//pdfViewer.loadPDF(in);
@ -770,6 +771,17 @@ public class WArchiveViewer extends Archive implements IFormController, EventLis
log.log(Level.SEVERE, "pdf", e);
iframe.getChildren().clear();//pdfViewer.clearDocument();
}
finally
{
if (in != null)
{
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
} // updateVDisplay
/**

View File

@ -170,13 +170,19 @@ public class WFilenameEditor extends WEditor
if (file.inMemory()) {
bytes = file.getByteData();
} else {
InputStream is = file.getStreamData();
InputStream is = null;
try {
is = file.getStreamData();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[ 1000 ];
int byteread = 0;
while (( byteread=is.read(buf) )!=-1)
baos.write(buf,0,byteread);
bytes = baos.toByteArray();
} finally {
if (is != null)
is.close();
}
}
fos.write(bytes);

View File

@ -758,20 +758,25 @@ public class WAttachment extends Window implements EventListener<Event>
private byte[] getMediaData(Media media) {
byte[] bytes = null;
try{
try {
if (media.inMemory())
bytes = media.isBinary() ? media.getByteData() : media.getStringData().getBytes(getCharset(media.getContentType()));
else {
InputStream is = media.getStreamData();
InputStream is = null;
try {
is = media.getStreamData();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[ 1000 ];
byte[] buf = new byte[1000];
int byteread = 0;
while (( byteread=is.read(buf) )!=-1)
baos.write(buf,0,byteread);
while ((byteread = is.read(buf)) != -1)
baos.write(buf, 0, byteread);
bytes = baos.toByteArray();
} finally {
if (is != null)
is.close();
}
}
} catch (IOException e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);

View File

@ -165,9 +165,10 @@ public class HTMLExtension implements IHTMLExtension {
if (urlFile != null) {
FileOutputStream cssStream = null;
File cssFile = null;
InputStream stream = null;
try {
// copy the resource to a temporary file to process it with 2pack
InputStream stream = urlFile.openStream();
stream = urlFile.openStream();
cssFile = File.createTempFile("report", ".css");
cssStream = new FileOutputStream(cssFile);
byte[] buffer = new byte[1024];
@ -183,6 +184,13 @@ public class HTMLExtension implements IHTMLExtension {
cssStream.close();
} catch (Exception e2) {}
}
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return cssFile.getAbsolutePath();
} else {

View File

@ -650,8 +650,9 @@ public class WEMailDialog extends Window implements EventListener<Event>, ValueC
if (media.inMemory()) {
bytes = media.isBinary() ? media.getByteData() : media.getStringData().getBytes(getCharset(media.getContentType()));
} else {
InputStream is = media.getStreamData();
InputStream is = null;
try {
is = media.getStreamData();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[ 1000 ];
int byteread = 0;
@ -660,6 +661,10 @@ public class WEMailDialog extends Window implements EventListener<Event>, ValueC
baos.write(buf,0,byteread);
bytes = baos.toByteArray();
} finally {
if (is != null)
is.close();
}
}
} catch (IOException e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);

View File

@ -432,7 +432,9 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
prefix += "_".repeat(3-prefix.length());
if (log.isLoggable(Level.FINE)) log.log(Level.FINE, "Path="+path + " Prefix="+prefix);
File file = File.createTempFile(prefix, ".xls", new File(path));
FileOutputStream fos = new FileOutputStream(file);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
// coding For Excel:
JRXlsExporter exporterXLS = new JRXlsExporter();
@ -447,6 +449,10 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
exporterXLS.setExporterOutput(new SimpleOutputStreamExporterOutput(fos));
exporterXLS.setConfiguration(xlsConfig);
exporterXLS.exportReport();
} finally {
if (fos != null)
fos.close();
}
return new AMedia(m_title+"."+EXCEL_FILE_EXT, EXCEL_FILE_EXT, EXCEL_MIME_TYPE, file, true);
} catch (Exception e) {
if (e instanceof RuntimeException)
@ -468,7 +474,9 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
prefix += "_".repeat(3-prefix.length());
if (log.isLoggable(Level.FINE)) log.log(Level.FINE, "Path="+path + " Prefix="+prefix);
File file = File.createTempFile(prefix, "."+EXCEL_XML_FILE_EXT, new File(path));
FileOutputStream fos = new FileOutputStream(file);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
// coding For Excel:
JRXlsxExporter exporterXLSX = new JRXlsxExporter();
@ -483,6 +491,10 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
exporterXLSX.setExporterOutput(new SimpleOutputStreamExporterOutput(fos));
exporterXLSX.setConfiguration(xlsxConfig);
exporterXLSX.exportReport();
} finally {
if (fos != null)
fos.close();
}
return new AMedia(m_title+"."+EXCEL_XML_FILE_EXT, EXCEL_XML_FILE_EXT, EXCEL_XML_MIME_TYPE, file, true);
} catch (Exception e) {
if (e instanceof RuntimeException)
@ -504,7 +516,9 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
prefix += "_".repeat(3-prefix.length());
if (log.isLoggable(Level.FINE)) log.log(Level.FINE, "Path="+path + " Prefix="+prefix);
File file = File.createTempFile(prefix, "."+CSV_FILE_EXT, new File(path));
FileOutputStream fos = new FileOutputStream(file);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
JRCsvExporter exporter= new JRCsvExporter();
if (!isList){
jasperPrintList = new ArrayList<>();
@ -513,7 +527,10 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList));
exporter.setExporterOutput(new SimpleWriterExporterOutput(fos));
exporter.exportReport();
} finally {
if (fos != null)
fos.close();
}
return new AMedia(m_title+"."+CSV_FILE_EXT, CSV_FILE_EXT, CSV_MIME_TYPE, file, false);
} catch (Exception e) {
if (e instanceof RuntimeException)
@ -535,7 +552,9 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
prefix += "_".repeat(3-prefix.length());
if (log.isLoggable(Level.FINE)) log.log(Level.FINE, "Path="+path + " Prefix="+prefix);
File file = File.createTempFile(prefix, "."+SSV_FILE_EXT, new File(path));
FileOutputStream fos = new FileOutputStream(file);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
JRCsvExporter exporter= new JRCsvExporter();
SimpleCsvExporterConfiguration csvConfig = new SimpleCsvExporterConfiguration();
csvConfig.setFieldDelimiter(";");
@ -547,7 +566,10 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
exporter.setExporterOutput(new SimpleWriterExporterOutput(fos));
exporter.setConfiguration(csvConfig);
exporter.exportReport();
} finally {
if (fos != null)
fos.close();
}
return new AMedia(m_title+"."+SSV_FILE_EXT, SSV_FILE_EXT, CSV_MIME_TYPE, file, false);
} catch (Exception e) {
if (e instanceof RuntimeException)