r3907 - in trunk: lima-business/src/main/java/org/chorem/lima/business lima-business/src/main/java/org/chorem/lima/business/ejb lima-business/src/main/java/org/chorem/lima/business/ejb/csv lima-swing/src/main/java/org/chorem/lima/ui/celleditor lima-swing/src/main/java/org/chorem/lima/ui/common lima-swing/src/main/java/org/chorem/lima/ui/importexport
Author: dcosse Date: 2014-08-09 00:53:39 +0200 (Sat, 09 Aug 2014) New Revision: 3907 Url: http://forge.chorem.org/projects/lima/repository/revisions/3907 Log: refactoring sonar Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java trunk/lima-business/src/main/java/org/chorem/lima/business/LimaInterceptor.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/AbstractLimaModel.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/EntryModel.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/FinancialTransactionModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellEditor.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryBookTableCellEditor.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AbstractLimaTable.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java 2014-08-07 21:37:22 UTC (rev 3906) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java 2014-08-08 22:53:39 UTC (rev 3907) @@ -58,14 +58,14 @@ protected static final Log log = LogFactory.getLog(LimaConfig.class); - protected static LimaConfig instance; + protected static volatile LimaConfig instance; protected static AccountingRules accountingRules; - protected static ApplicationConfig config; - protected static final String LIMA_DEFAULT_CONF_FILENAME = "lima.properties"; + protected static ApplicationConfig config = new ApplicationConfig(LIMA_DEFAULT_CONF_FILENAME); + public LimaConfig() { try { setOption("topia.service.migration", TopiaMigrationEngine.class.getName()); @@ -74,7 +74,6 @@ setOption(TopiaMigrationService.MIGRATION_SHOW_SQL, Boolean.TRUE.toString()); setOption(TopiaMigrationService.MIGRATION_SHOW_PROGRESSION, Boolean.TRUE.toString()); - LimaConfig.config = new ApplicationConfig(LIMA_DEFAULT_CONF_FILENAME); LimaConfig.config.loadDefaultOptions(ServiceConfigOption.values()); LimaConfig.config.parse(); @@ -84,9 +83,9 @@ } public static LimaConfig getInstance() { - if (instance == null) { - instance = new LimaConfig(); - instance.loadConfiguration(); + if (LimaConfig.instance == null) { + LimaConfig.instance = new LimaConfig(); + LimaConfig.instance.loadConfiguration(); } return instance; } @@ -105,30 +104,35 @@ public AccountingRules getAccountingRules() { if (accountingRules == null) { - Class<?> accountingRulesClass = config.getOptionAsClass(ServiceConfigOption.RULES_NATIONALTY.key); - if (accountingRulesClass == null) { + loadAccountingRules(); + } + + return accountingRules; + } + + protected static void loadAccountingRules() { + Class<?> accountingRulesClass = config.getOptionAsClass(ServiceConfigOption.RULES_NATIONALTY.key); + if (accountingRulesClass == null) { + if (log.isErrorEnabled()) { + log.error("No accounting rules defined for:" + ServiceConfigOption.RULES_NATIONALTY.key); + } + accountingRules = new FranceAccountingRules(); + } else { + try { + accountingRules = (AccountingRules) accountingRulesClass.newInstance(); + } catch (Exception ex) { if (log.isErrorEnabled()) { - log.error("No accounting rules defined for:" + ServiceConfigOption.RULES_NATIONALTY.key); + log.error("Can't instantiate accounting rules", ex); } - accountingRules = new FranceAccountingRules(); - } else { - try { - accountingRules = (AccountingRules) accountingRulesClass.newInstance(); - } catch (Exception ex) { - if (log.isErrorEnabled()) { - log.error("Can't instantiate accounting rules", ex); - } - } } } - - return accountingRules; } public void setAccountingRule(String accountingRule) { - LimaConfig.accountingRules = null; // clear cache LimaConfig.config.setOption(ServiceConfigOption.RULES_NATIONALTY.key, accountingRule); + // clear cache + loadAccountingRules(); } public File getDataDir() { Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaInterceptor.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/LimaInterceptor.java 2014-08-07 21:37:22 UTC (rev 3906) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/LimaInterceptor.java 2014-08-08 22:53:39 UTC (rev 3907) @@ -95,7 +95,6 @@ context.getTarget().getClass() + "#" + context.getMethod().getName()); } - ApplicationConfig config = LimaConfig.getInstance().getConfig(); LimaCallaoTopiaApplicationContext rootContext = TopiaApplicationContextCache.getContext(config.getFlatOptions(), CREATE_CONTEXT_FUNCTION); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2014-08-07 21:37:22 UTC (rev 3906) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2014-08-08 22:53:39 UTC (rev 3907) @@ -979,64 +979,4 @@ return entryBookFinancialTransactionByDate; } - //####################################################################################################### - -// @Override -// public String importAsPDF(String datas, -// ImportExportEntityEnum importExportEntityEnum, -// boolean setMode) { -// -// StringBuilder result = new StringBuilder(); -// -// PDDocument doc = null; -// try { -// String path = LimaConfig.getInstance().getReportsDir().getAbsolutePath(); -// -// String filePathDefault = path + File.separator -// + DocumentsEnum.VAT.getFileName() + "_default.pdf"; -// String filePathStructured = path + File.separator -// + DocumentsEnum.VAT.getFileName() + "_structure.pdf"; -// -// InputStream reportsStream = new FileInputStream(datas); -// //DocumentServiceImpl.class.getResourceAsStream("/reports/vat_form_fr.pdf"); -// // load the document -// doc = PDDocument.load(reportsStream); -// -// //save default vat document with empty boxes -// if (setMode) { -// doc.save(filePathDefault); -// } -// -// //search for all PDFBox -// List<PDField> FieldList = doc.getDocumentCatalog().getAcroForm().getFields(); -// -// //display inside each box their name -// for (PDField pdField : FieldList) { -// pdField.setValue(pdField.getFullyQualifiedName()); -// } -// -// // save the structured document -// doc.save(filePathStructured); -// -// //sets the new pdf url to be used as pdf document edited for reports -// if (setMode) { -// LimaConfig.getInstance().setVatPDFUrl(datas); -// } -// } catch (IOException ex) { -// log.error("Can't read vat pdf", ex); -// result.append("Can't read vat pdf"); -// } catch (COSVisitorException ex) { -// log.error("Can't save vat pdf", ex); -// result.append("Can't save vat pdf"); -// } finally { -// try { -// if (doc != null) { -// doc.close(); -// } -// } catch (Exception e) { -// // Nothing to do -// } -// } -// return result.toString(); -// } } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/AbstractLimaModel.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/AbstractLimaModel.java 2014-08-07 21:37:22 UTC (rev 3906) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/AbstractLimaModel.java 2014-08-08 22:53:39 UTC (rev 3907) @@ -22,16 +22,11 @@ * #L% */ -import com.google.common.base.Preconditions; import com.google.common.base.Strings; import org.apache.commons.lang3.StringUtils; import org.chorem.lima.FinancialStatementWayEnum; -import org.chorem.lima.business.api.AccountService; -import org.chorem.lima.business.api.EntryBookService; -import org.chorem.lima.business.api.FinancialTransactionService; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.Entry; -import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.FinancialStatement; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.VatStatement; @@ -50,32 +45,12 @@ */ public abstract class AbstractLimaModel<E> extends AbstractImportModel<E> { - - protected static EntryBookService entryBookService; - - protected static FinancialTransactionService financialTransactionService; - - protected static AccountService accountService; - - protected static Boolean humanReadable; - protected static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy"); public AbstractLimaModel(char separator) { super(separator); } - public AbstractLimaModel(char separator, EntryBookService entryBookService) { - super(separator); - AbstractLimaModel.entryBookService = entryBookService; - } - - public AbstractLimaModel(char separator, AccountService accountService, FinancialTransactionService financialTransactionService, Boolean humanReadable) { - super(separator); - AbstractLimaModel.accountService = accountService; - AbstractLimaModel.financialTransactionService = financialTransactionService; - AbstractLimaModel.humanReadable = humanReadable; - } /** * String to integer converter. */ @@ -228,33 +203,10 @@ } }; - protected static final ValueFormatter<EntryBook> ENTRY_BOOK_TO_ENTRY_BOOK_CODE_FORMATTER = new ValueFormatter<EntryBook>() { - @Override - public String format(EntryBook value) { - String result; - if (value != null) { - result = value.getCode(); - } else { - result = ""; - } - return result; - } - }; - protected static final ValueParser<EntryBook> ENTRY_BOOK_CODE_TO_ENTRY_BOOK_PARSER = new ValueParser<EntryBook>() { - @Override - public EntryBook parse(String value) { - EntryBook result; - if (StringUtils.isNotBlank(value)) { - result = AbstractLimaModel.entryBookService.getEntryBookByCode(value); - } else { - result = null; - } - return result; - } - }; + protected static final ValueParser<BigDecimal> BIG_DECIMAL_WITH_NULL_PARSER = new ValueParser<BigDecimal>() { @Override public BigDecimal parse(String value) throws ParseException { @@ -294,45 +246,6 @@ } }; - protected static final ValueParser<Account> ACCOUNT_NUMBER_TO_ACCOUNT_TRANSACTION_PARSER = new ValueParser<Account>() { - - @Override - public Account parse(String value) { - Account result; - if (StringUtils.isNotBlank(value)) { - result = AbstractLimaModel.accountService.getAccountByNumber(value); - } else { - result = null; - } - return result; - } - }; - - protected static final ValueFormatter<FinancialTransaction> FINANCIAL_TRANSACTION_TO_FINANCIAL_TRANSACTION_FORMATTER = new ValueFormatter<FinancialTransaction>() { - @Override - public String format(FinancialTransaction value) { - String result; - if (value != null) { - result = AbstractLimaModel.humanReadable ? AbstractLimaModel.simpleDateFormat.format(value.getTransactionDate()) : value.getTopiaId(); - } else { - result = ""; - } - return result; - } - }; - - protected static final ValueParser<FinancialTransaction> FINANCIAL_TRANSACTION_ID_TO_FINANCIAL_TRANSACTION_PARSER = new ValueParser<FinancialTransaction>() { - - @Override - public FinancialTransaction parse(String value) { - Preconditions.checkArgument(!Strings.isNullOrEmpty(value)); - FinancialTransaction result; - result = AbstractLimaModel.financialTransactionService.getFinancialTransactionWithId(value); - return result; - } - }; - - protected static final ValueFormatter<FinancialStatementWayEnum> FINANCIAL_STATEMENT_WAY_ENUM_VALUE_FORMATTER = new ValueFormatter<FinancialStatementWayEnum>() { @Override public String format(FinancialStatementWayEnum value) { Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/EntryModel.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/EntryModel.java 2014-08-07 21:37:22 UTC (rev 3906) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/EntryModel.java 2014-08-08 22:53:39 UTC (rev 3907) @@ -22,21 +22,35 @@ * #L% */ +import com.google.common.base.Preconditions; +import com.google.common.base.Strings; +import org.apache.commons.lang3.StringUtils; import org.chorem.lima.business.api.AccountService; import org.chorem.lima.business.api.FinancialTransactionService; +import org.chorem.lima.entity.Account; import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryImpl; +import org.chorem.lima.entity.FinancialTransaction; import org.nuiton.csv.ExportModel; import org.nuiton.csv.ExportableColumn; import org.nuiton.csv.ModelBuilder; +import org.nuiton.csv.ValueFormatter; +import org.nuiton.csv.ValueParser; /** * Created by davidcosse on 03/06/14. */ public class EntryModel extends AbstractLimaModel<Entry> implements ExportModel<Entry> { + protected FinancialTransactionService financialTransactionService; + protected AccountService accountService; + protected boolean humanReadable; + public EntryModel(AccountService accountService, FinancialTransactionService financialTransactionService, boolean humanReadable) { - super(';', accountService, financialTransactionService, humanReadable); + super(';'); + this.accountService = accountService; + this.financialTransactionService = financialTransactionService; + this.humanReadable = humanReadable; newMandatoryColumn("account", Entry.PROPERTY_ACCOUNT, ACCOUNT_NUMBER_TO_ACCOUNT_TRANSACTION_PARSER); newOptionalColumn("amount", Entry.PROPERTY_AMOUNT, BIG_DECIMAL_WITH_NULL_PARSER); @@ -69,4 +83,42 @@ public Entry newEmptyInstance() { return new EntryImpl(); } + + protected final ValueParser<FinancialTransaction> FINANCIAL_TRANSACTION_ID_TO_FINANCIAL_TRANSACTION_PARSER = new ValueParser<FinancialTransaction>() { + + @Override + public FinancialTransaction parse(String value) { + Preconditions.checkArgument(!Strings.isNullOrEmpty(value)); + FinancialTransaction result; + result = financialTransactionService.getFinancialTransactionWithId(value); + return result; + } + }; + + protected final ValueParser<Account> ACCOUNT_NUMBER_TO_ACCOUNT_TRANSACTION_PARSER = new ValueParser<Account>() { + + @Override + public Account parse(String value) { + Account result; + if (StringUtils.isNotBlank(value)) { + result = accountService.getAccountByNumber(value); + } else { + result = null; + } + return result; + } + }; + + protected final ValueFormatter<FinancialTransaction> FINANCIAL_TRANSACTION_TO_FINANCIAL_TRANSACTION_FORMATTER = new ValueFormatter<FinancialTransaction>() { + @Override + public String format(FinancialTransaction value) { + String result; + if (value != null) { + result = humanReadable ? AbstractLimaModel.simpleDateFormat.format(value.getTransactionDate()) : value.getTopiaId(); + } else { + result = ""; + } + return result; + } + }; } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/FinancialTransactionModel.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/FinancialTransactionModel.java 2014-08-07 21:37:22 UTC (rev 3906) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/FinancialTransactionModel.java 2014-08-08 22:53:39 UTC (rev 3907) @@ -22,20 +22,27 @@ * #L% */ +import org.apache.commons.lang3.StringUtils; import org.chorem.lima.business.api.EntryBookService; +import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.FinancialTransactionImpl; import org.nuiton.csv.ExportModel; import org.nuiton.csv.ExportableColumn; import org.nuiton.csv.ModelBuilder; +import org.nuiton.csv.ValueFormatter; +import org.nuiton.csv.ValueParser; /** * Created by davidcosse on 03/06/14. */ public class FinancialTransactionModel extends AbstractLimaModel<FinancialTransaction> implements ExportModel<FinancialTransaction> { + protected EntryBookService entryBookService; + public FinancialTransactionModel(EntryBookService entryBookService) { - super(';', entryBookService); + super(';'); + this.entryBookService = entryBookService; newMandatoryColumn("id", FinancialTransaction.PROPERTY_TOPIA_ID); newOptionalColumn("transactionDate", FinancialTransaction.PROPERTY_TRANSACTION_DATE, DATE_PARSER); newOptionalColumn("entryBook", FinancialTransaction.PROPERTY_ENTRY_BOOK, ENTRY_BOOK_CODE_TO_ENTRY_BOOK_PARSER); @@ -55,4 +62,31 @@ return new FinancialTransactionImpl(); } + protected ValueParser<EntryBook> ENTRY_BOOK_CODE_TO_ENTRY_BOOK_PARSER = new ValueParser<EntryBook>() { + + @Override + public EntryBook parse(String value) { + EntryBook result; + if (StringUtils.isNotBlank(value)) { + result = entryBookService.getEntryBookByCode(value); + } else { + result = null; + } + return result; + } + }; + + protected static final ValueFormatter<EntryBook> ENTRY_BOOK_TO_ENTRY_BOOK_CODE_FORMATTER = new ValueFormatter<EntryBook>() { + @Override + public String format(EntryBook value) { + String result; + if (value != null) { + result = value.getCode(); + } else { + result = ""; + } + return result; + } + }; + } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellEditor.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellEditor.java 2014-08-07 21:37:22 UTC (rev 3906) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellEditor.java 2014-08-08 22:53:39 UTC (rev 3907) @@ -57,11 +57,11 @@ protected static final Log log = LogFactory.getLog(AccountTableCellEditor.class); - private final JWideComboBox comboBox; + protected final JWideComboBox comboBox; - private static final long serialVersionUID = 1L; + protected static final long serialVersionUID = 1L; - private static boolean keyPressed; + protected volatile boolean keyPressed; /** constructor */ public AccountTableCellEditor() { @@ -114,7 +114,7 @@ }); } } - AccountTableCellEditor.keyPressed = false; + keyPressed = false; return !(evt instanceof MouseEvent) || ((MouseEvent) evt).getClickCount() == 1; } @@ -133,7 +133,7 @@ JTextComponent edit = (JTextComponent) comboBox.getEditor().getEditorComponent(); // Met en place le curseur et la selection après la première lettre edit.select(1, edit.getText().length()); - AccountTableCellEditor.keyPressed = true; + keyPressed = true; } // delegate popup list menu Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java 2014-08-07 21:37:22 UTC (rev 3906) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java 2014-08-08 22:53:39 UTC (rev 3907) @@ -40,6 +40,7 @@ */ public class BigDecimalTableCellEditor extends StringTableCellEditor { + private static final long serialVersionUID = -3178887048291878246L; protected String comma = ""; private static final Log log = LogFactory.getLog(BigDecimalTableCellEditor.class); Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryBookTableCellEditor.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryBookTableCellEditor.java 2014-08-07 21:37:22 UTC (rev 3906) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryBookTableCellEditor.java 2014-08-08 22:53:39 UTC (rev 3907) @@ -52,7 +52,7 @@ private static final long serialVersionUID = 1L; // private static EntryBookTableCellEditor editor; - private static boolean keyPressed; + private volatile boolean keyPressed; /** constructor */ public EntryBookTableCellEditor() { @@ -134,7 +134,7 @@ } } // Remet à faux pour la premiere lettre tapée au clavier - EntryBookTableCellEditor.keyPressed = false; + keyPressed = false; return !(evt instanceof MouseEvent) || ((MouseEvent) evt).getClickCount() == 1; } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AbstractLimaTable.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AbstractLimaTable.java 2014-08-07 21:37:22 UTC (rev 3906) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AbstractLimaTable.java 2014-08-08 22:53:39 UTC (rev 3907) @@ -40,14 +40,10 @@ import org.chorem.lima.ui.celleditor.StringTableCellEditor; import org.jdesktop.swingx.JXTable; -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.InputMap; -import javax.swing.JComponent; -import javax.swing.KeyStroke; +import javax.swing.*; import javax.swing.table.TableCellEditor; import javax.swing.table.TableModel; -import java.awt.Color; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; @@ -61,6 +57,7 @@ public abstract class AbstractLimaTable<H> extends JXTable { private static final Log log = LogFactory.getLog(AbstractLimaTable.class); + private static final long serialVersionUID = -4195941654485008887L; protected H handler; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2014-08-07 21:37:22 UTC (rev 3906) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2014-08-08 22:53:39 UTC (rev 3907) @@ -99,6 +99,7 @@ public class ImportExport { private static final Log log = LogFactory.getLog(ImportExport.class); + public static final int BUFFER_SIZE = 1024; /** Parent view. */ protected Component viewComponent; @@ -544,16 +545,20 @@ String data = exportedData.getExportData(); File file = createFile(JAVA_IO_TMPDIR + exportedData.getFromSource().getSimpleName(), charset, data); if (file != null) { - ZipEntry ze= new ZipEntry(file.getName()); - export.putNextEntry(ze); - int len; - byte[] buffer = new byte[1024]; - FileInputStream stream = new FileInputStream(file); - while ((len = stream.read(buffer)) > 0) { - export.write(buffer, 0, len); + FileInputStream stream = null; + try { + ZipEntry ze = new ZipEntry(file.getName()); + export.putNextEntry(ze); + int len; + byte[] buffer = new byte[BUFFER_SIZE]; + stream = new FileInputStream(file); + while ((len = stream.read(buffer)) > 0) { + export.write(buffer, 0, len); + } + } finally { + IOUtils.closeQuietly(stream); + FileUtils.forceDelete(file); } - IOUtils.closeQuietly(stream); - FileUtils.forceDelete(file); } } else { // export failed @@ -596,17 +601,20 @@ ZipEntry entry; while ((entry = zipInputStream.getNextEntry()) != null) { - byte[] buffer = new byte[2048]; - String targetFileName= tmpDir + entry.getName() + "-" + determinant +".csv"; - FileOutputStream fileoutputstream = new FileOutputStream(targetFileName); + FileOutputStream fileoutputstream = null; + try { + byte[] buffer = new byte[BUFFER_SIZE]; + String targetFileName= tmpDir + entry.getName() + "-" + determinant +".csv"; + fileoutputstream = new FileOutputStream(targetFileName); - int n; - while ((n = zipInputStream.read(buffer, 0, 2048)) > -1) { - fileoutputstream.write(buffer, 0, n); + int n; + while ((n = zipInputStream.read(buffer, 0, BUFFER_SIZE)) > -1) { + fileoutputstream.write(buffer, 0, n); + } + zipInputStream.closeEntry(); + } finally { + IOUtils.closeQuietly(fileoutputstream); } - fileoutputstream.close(); - - zipInputStream.closeEntry(); } } catch (Exception e) { result.addInitException(new ImportFileException(t("lima.ui.importexport.import.extractFileError")));
participants (1)
-
dcosse@users.chorem.org