OutputStream out = res.getOutputStream();  int bufferSize = 4096; byte buffer[] = new byte[bufferSize]; int l = bufferSize;  while (length>0) { if (length < bufferSize) l = in.read(buffer, 0, length); else l=in.read(buffer, 0, bufferSize);  if (l == -1) break;  length -= l; out.write(buffer, 0, l);
try { OutputStream out = res.getOutputStream();  int bufferSize = 4096; byte buffer[] = new byte[bufferSize]; int l = bufferSize;  while (length>0) { if (length < bufferSize) l = in.read(buffer, 0, length); else l=in.read(buffer, 0, bufferSize);  if (l == -1) break;  length -= l; out.write(buffer, 0, l); } } finally { in.close();
    void sendForward(HttpServletResponse res, ResponseTrans hopres) throws IOException {        String forward = hopres.getForward();        ServletContext cx = getServletConfig().getServletContext();        String path = cx.getRealPath(forward);        if (path == null)            throw new IOException("Resource "+forward+" not found");        File file = new File(path);        int length = (int) file.length();        res.setContentLength(length);        res.setContentType(hopres.getContentType());        InputStream in = cx.getResourceAsStream(forward);        if (in == null)            throw new IOException("Can't read "+path);        OutputStream out = res.getOutputStream();        int bufferSize = 4096;        byte buffer[] = new byte[bufferSize];        int l = bufferSize;        while (length>0) {            if (length < bufferSize)                l = in.read(buffer, 0, length);            else                l=in.read(buffer, 0, bufferSize);            if (l == -1)                break;            length -= l;            out.write(buffer, 0, l);        }    }