Skip to content

Commit

Permalink
Fix issue where PDF reports would generate empty files.
Browse files Browse the repository at this point in the history
  • Loading branch information
rrowlands committed Jul 19, 2022
1 parent 9a65dbb commit 2d91a83
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
******************************************************************************/
package dss.vector.solutions.kaleidoscope.report;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -30,6 +33,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -371,7 +375,8 @@ else if (name.equals("pageNumber"))
* are sure the report has rendered. Therefore, first render the report to a temp byte array stream. Once that has rendered, copy the bytes
* from the byte array to the servlet output stream. Note, this may cause memory problems if the report being rendered is too big.
*/
ByteArrayOutputStream rStream = new ByteArrayOutputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BufferedOutputStream rStream = new BufferedOutputStream(baos);

try
{
Expand All @@ -382,7 +387,7 @@ else if (name.equals("pageNumber"))

if (format == null || format.equalsIgnoreCase("html"))
{
req.setAttribute("report", rStream.toString("UTF-8"));
req.setAttribute("report", baos.toString("UTF-8"));
req.setAttribute("pageCount", pageCount);
req.setAttribute("pageNumber", pageNumber);

Expand All @@ -398,7 +403,8 @@ else if (name.equals("pageNumber"))

try
{
oStream.print(rStream.toString("UTF-8"));
InputStream is = new BufferedInputStream(new ByteArrayInputStream(baos.toByteArray()));
IOUtils.copy(is, oStream);
}
finally
{
Expand Down

0 comments on commit 2d91a83

Please sign in to comment.