AsciiResult.javaAPI DocExample1384Fri Feb 21 13:14:12 GMT 2003None


public class AsciiResult extends HttpServlet

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

    ServletOutputStream out = res.getOutputStream();

    // ServletOutputStream has println() methods for writing strings
    // The println() call only works for single-byte character encodings
    // If you need multibyte, make sure to set the charset in the Content-Type
    // and use for example out.write(str.getBytes("Shift_JIS")) for Japanese 
    out.println("Content current as of");
    out.println(new Date().toString());

    // ... retrieve a database ResultSet here ...
    ResultSet resultSet = null;

    try {
      InputStream ascii = resultSet.getAsciiStream(1);
      returnStream(ascii, out);
    catch (SQLException e) {
      throw new ServletException(e);
public static voidreturnStream( in, out)

    byte[] buf = new byte[4 * 1024];  // 4K buffer
    int bytesRead;
    while ((bytesRead = != -1) {
      out.write(buf, 0, bytesRead);