FileDocCategorySizeDatePackage
NoConversions.javaAPI DocExample1030Fri Feb 21 13:11:10 GMT 2003None

NoConversions

public class NoConversions extends HttpServlet

Fields Summary
String
name
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)

  // demo file to send

       
                                  
    String file = getServletContext().getRealPath(name);

    res.setContentType("text/plain");
    OutputStream out = res.getOutputStream();

    returnFile(file, out);
  
public static voidreturnFile(java.lang.String filename, java.io.OutputStream out)

    InputStream in = null;
    try {
      in = new BufferedInputStream(new FileInputStream(filename));
      byte[] buf = new byte[4 * 1024];  // 4K buffer
      int bytesRead;
      while ((bytesRead = in.read(buf)) != -1) {
        out.write(buf, 0, bytesRead);
      }
    }
    finally {
      if (in != null) in.close();
    }