W3C home > Mailing lists > Public > www-jigsaw@w3.org > November to December 1996

HtmlGenerator.getInputStream(), Reply.setStream()

From: Dave Makower <davemak@pencom.com>
Date: Fri, 8 Nov 1996 17:14:02 -0500
Message-Id: <v01540b00aea95e7877ff@[]>
To: www-jigsaw@w3.org
Below, you will find some source code (significantly simplified) 
from a project I'm working on.  I need to have a method, other 
than get(), which returns an InputStream (sometimes created by 
an HtmlGenerator, but not always) that is converted into a Reply
by get().

The problem is that when I put this Resource() into Jigsaw, 
it stalls before the output is completed.  That is, the entire 
page content gets transmitted, but the connection is not closed.  
If I hit the browser's STOP button, then I get "Transfer 

I think that there may be something wrong with the method 
HtmlGenerator.getInputStream(), or with Reply.setStream()... 
either that, or perhaps I am using them incorrectly.

Try it and see what I mean.

Any suggestions?

//------------------- StreamResource.java -------------------
// Copyright (c) 1996 Pencom Systems, Inc.

import w3c.jigsaw.html.*;

import w3c.www.http.*;

import java.io.*;

public class StreamResource extends FilteredResource {
    public StreamResource() {
    public InputStream makeStream() {
        StringBuffer contentBuf = new StringBuffer();
        contentBuf.append("What I am doing here may seem a little strange.\n");
        contentBuf.append("In fact, the real version reads its data from an external source.\n");
        contentBuf.append("Then it reads it in a little at a time, ");
        contentBuf.append("appending it to a StringBuffer.\n");
        contentBuf.append("For reasons particular to the project I'm working on,\n");
        contentBuf.append("I need to have this method that returns an InputStream,");
        contentBuf.append("rather than having the get() method create an HTML generator.");
        contentBuf.append("Still, one would think this method should work, right?");
        contentBuf.append("I'd rather use Jigsaw's HTML generator than take care of all\n");
        contentBuf.append("of the details myself.\n\n");
        contentBuf.append("Note that this content might contain HTML tags, like\n");
        contentBuf.append("<HTML> or <TABLE>, so it needs to be escaped.\n\n");
        String contentString = contentBuf.toString();
        // Emit preliminary HTML
        HtmlGenerator gen = new HtmlGenerator("Who cares what the title is?");
        gen.append("<BODY BGCOLOR=\"#FFFFFF\">\n");
        gen.append("<H1 ALIGN=\"CENTER\">\n");
        gen.append("Why doesn't this work?");
        // Emit the content
        // Emit tail HTML
        // gen.close(); // redundant
        // Return an InputStream from the HTML generator
        return gen.getInputStream();
    public Reply get(Request request) {
        Reply reply = request.makeReply(HTTP.OK);
        InputStream content = null;
        // Present the content
        content = makeStream();
        // Put the content in the Reply object
        if (content != null) {
        } else {
            HtmlGenerator gen = new HtmlGenerator("Not Found");
            gen.append("<H1 ALIGN=\"CENTER\">\n");
            gen.append("404 - Not Found\n");
            gen.append("The resource" + getURL() + "has no content.\n");
            if (request != null) {
                gen.append("Referring URL: ");
                gen.append("<A HREF=\"" + request.getReferer() + "\">");
        return reply;
Received on Friday, 8 November 1996 17:12:47 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:25:30 UTC