Search in sources :

Example 1 with JasperReportViewException

use of org.openlmis.stockmanagement.exception.JasperReportViewException in project openlmis-stockmanagement by OpenLMIS.

the class JasperReportService method saveAndGetUrl.

private String saveAndGetUrl(JasperReport report, String templateName) throws IOException {
    File reportTempFile;
    try {
        reportTempFile = createTempFile(templateName, ".jasper");
    } catch (IOException ex) {
        throw new JasperReportViewException(ERROR_JASPER_FILE_CREATION, ex);
    }
    try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(bos)) {
        out.writeObject(report);
        writeByteArrayToFile(reportTempFile, bos.toByteArray());
        return reportTempFile.toURI().toURL().toString();
    }
}
Also used : IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) File.createTempFile(java.io.File.createTempFile) FileUtils.writeByteArrayToFile(org.apache.commons.io.FileUtils.writeByteArrayToFile) File(java.io.File) JasperReportViewException(org.openlmis.stockmanagement.exception.JasperReportViewException)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 File.createTempFile (java.io.File.createTempFile)1 IOException (java.io.IOException)1 ObjectOutputStream (java.io.ObjectOutputStream)1 FileUtils.writeByteArrayToFile (org.apache.commons.io.FileUtils.writeByteArrayToFile)1 JasperReportViewException (org.openlmis.stockmanagement.exception.JasperReportViewException)1