martedì, gennaio 29, 2008

[JSP] Binary output stream

<%@ page import="java.io.*" %>
<%@ page import="java.net.*" %>
<%@ page contentType="image/gif" %>
<%
OutputStream o = response.getOutputStream();
InputStream is = new URL("").openStream();

byte[] buf = new byte[32 * 1024];

// 32k buffer int nRead = 0;
int nRead = 0;
while( (nRead=is.read(buf)) != -1 ) {
o.write(buf, 0, nRead);
}

o.flush();
o.close();
%>


Riferimento: Link

Nessun commento: