use of org.compiere.model.MRfQ in project adempiere by adempiere.
the class RfQServlet method streamAttachment.
// doGet
/**
* Stream Attachment
* @param request request
* @param response response
* @return "" or error message
*/
private String streamAttachment(HttpServletRequest request, HttpServletResponse response) {
// Get Note ID
int C_RfQ_ID = WebUtil.getParameterAsInt(request, "C_RfQ_ID");
if (C_RfQ_ID == 0) {
log.fine("streamAttachment - no ID)");
return "No RfQ ID";
}
// Get Note
Properties ctx = JSPEnv.getCtx(request);
MRfQ doc = new MRfQ(ctx, C_RfQ_ID, null);
if (doc.getC_RfQ_ID() != C_RfQ_ID) {
log.fine("streamAttachment - RfQ not found - ID=" + C_RfQ_ID);
return "RfQ not found";
}
if (!doc.isPdfAttachment())
return "No PDF Attachment found";
byte[] data = doc.getPdfAttachment();
if (data == null)
return "No PDF Attachment";
// Send PDF
try {
// 2k Buffer
int bufferSize = 2048;
int fileLength = data.length;
//
response.setContentType("application/pdf");
response.setBufferSize(bufferSize);
response.setContentLength(fileLength);
//
log.fine("streamAttachment - length=" + fileLength);
// timer start
long time = System.currentTimeMillis();
//
ServletOutputStream out = response.getOutputStream();
out.write(data);
out.flush();
out.close();
//
time = System.currentTimeMillis() - time;
double speed = (fileLength / 1024) / ((double) time / 1000);
log.fine("streamInvoice - length=" + fileLength + " - " + time + " ms - " + speed + " kB/sec");
} catch (IOException ex) {
log.log(Level.SEVERE, "streamAttachment - " + ex);
return "Streaming error";
}
return null;
}
Aggregations