core-jgi/org.adempiere.ui.zk/labeldata.jsp

53 lines
1.3 KiB
Plaintext
Raw Normal View History

<%@ page trimDirectiveWhitespaces="true" %>
<%@page import="java.io.ByteArrayOutputStream"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.File"%>
2012-12-21 17:48:41 +07:00
<%@page import="java.io.BufferedOutputStream"%>
<%@page import="java.io.OutputStream"%>
<%@ page language="java" contentType="application/octet-stream"%>
<%
String filepath = request.getParameter("filepath");
if (filepath == null || filepath.trim().length() == 0 )
2012-12-21 17:48:41 +07:00
return;
File file = new File(filepath);
if (file.exists())
{
FileInputStream fis = null;
ByteArrayOutputStream baos = null;
byte[] data = null;
try
{
fis = new FileInputStream (file);
baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024*8]; // 8kB
int length = -1;
while ((length = fis.read(buffer)) != -1)
baos.write(buffer, 0, length);
data = baos.toByteArray();
fis.close();
baos.close();
2012-12-21 17:48:41 +07:00
response.setContentLength(data.length);
OutputStream os = response.getOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(os);
bos.write(data);
bos.flush();
bos.close();
file.delete();
}
catch (Exception e)
{
e.printStackTrace();
2012-12-21 17:48:41 +07:00
response.setContentLength(0);
}
}
else
{
System.out.println("file not found=" + filepath);
2012-12-21 17:48:41 +07:00
response.setContentLength(0);
}
%>