import fr.gouv.finances.cp.xemelios.data.impl.mysql.serialization.DrswParser;
import fr.gouv.finances.cp.xemelios.data.impl.mysql.serialization.ExportJobImpl;
import fr.gouv.finances.dgfip.utils.Pair;
-import fr.gouv.finances.dgfip.utils.QueryProvider;
import fr.gouv.finances.dgfip.utils.xml.FactoryProvider;
import fr.gouv.finances.dgfip.utils.xml.InvalidPathExpressionException;
import fr.gouv.finances.dgfip.utils.xml.PathNotFoundException;
}
ps.setString(3, pj.getPjName());
ps.setString(4, pj.getFileName());
+
+ InputStream dataInpStr = null;
+ int pjLength = (int) pj.getUncompressedSize();
+
if ((pj.getData() != null) && (pj.getData().length > 0)) {
- ps.setBinaryStream(5, pj.getDataInputStream(), (int) pj.getUncompressedSize());
+ dataInpStr = pj.getDataInputStream();
} else if (pj.getTmpFileName() != null) {
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- final byte[] buffer = new byte[1024];
- final FileInputStream fis = new FileInputStream(pj.getTmpFileName());
- int read = fis.read(buffer);
- while (read > 0) {
- baos.write(buffer, 0, read);
- read = fis.read(buffer);
- }
- fis.close();
- baos.flush();
- baos.close();
- ps.setBinaryStream(5, new ByteArrayInputStream(baos.toByteArray()), (int) pj.getUncompressedSize());
+ dataInpStr = new FileInputStream(pj.getTmpFileName());
} else {
- ps.setBinaryStream(5, new ByteArrayInputStream(new byte[0]), 0);
+ dataInpStr = new ByteArrayInputStream(new byte[0]);
+ pjLength = 0;
+ }
+
+ ps.setBinaryStream(5, dataInpStr, pjLength);
+
+ try {
+ ps.executeUpdate();
+ } finally {
+ dataInpStr.close();
}
- ps.executeUpdate();
} catch (final SQLException sqlEx) {
throw new DataAccessException(sqlEx);
} catch (final Exception ex) {