simple.http.serve
Interface Content


public interface Content

The Content interface is used to provide an interface to content within a Context. The contents represented by the Content implementation could be dynamic or static depending on the Context that served it.

Static content represented by resources on the underlying file system such as files are represented as Content objects to provide a simple means of writing that content to HTTP clients using an OutputStream.

The Content interface can also be used to provide a means for writing dynamic content. Dynamic content such as that produced by simple.template.Document objects can be implemented as a Content. The implementation can then be presented to the client using the write methods.

Author:
Niall Gallagher
See Also:
ContentFactory

Method Summary
 java.lang.String getContentType()
          The content that is dynamically generated by the object us written as a specific MIME type, including charset information which determines the content encoding.
 java.lang.String toString()
          This method is used to embed the generated contents into other strings and capture the value of the content as a string.
 void write(java.io.OutputStream out)
          This writes the contents of the instance to the issued stream.
 

Method Detail

write

void write(java.io.OutputStream out)
           throws java.io.IOException
This writes the contents of the instance to the issued stream. This provides a means for the Content to write its contents to an OutputStream. Typically this is used by Service objects when data is to be provided to the client using the Response. Any problems in writing the contents results in an exception.

Parameters:
out - this is the stream to write the content with
Throws:
java.io.IOException - thrown if there is an I/O problem

getContentType

java.lang.String getContentType()
The content that is dynamically generated by the object us written as a specific MIME type, including charset information which determines the content encoding. For example if the output was HTML written using UTF-8 format then this would return "text/html; charset=utf-8".

Returns:
returns the MIME type of the generated content

toString

java.lang.String toString()
This method is used to embed the generated contents into other strings and capture the value of the content as a string. In order to manipulate the contents of a file it is necessary to acquire a handle on its contents. This method allows such a handle. The contents returned by this will typically be UTF-8, however the encoding of a content object is independant as is the MIME type.

Overrides:
toString in class java.lang.Object
Returns:
returns the contents of the generated content