Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 // Copyright 2007, 2008, 2010 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
 //
 // http://www.apache.org/licenses/LICENSE-2.0
 //
 // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.tapestry5.util;
public class TextStreamResponse implements StreamResponse
    private final ContentType contentType;
    private final String text;

    
Constructor that defaults the character set to "utf-8".
    public TextStreamResponse(String contentTypeString text)
    {
        this(contentType"UTF-8"text);
    }

    
Constructor allowing the content type and character set to the specified.

Parameters:
contentType type of content, often "text/xml"
charset character set of output, usually "UTF-8"
text text to be streamed in the response
See also:
org.apache.tapestry5.SymbolConstants.CHARSET
    public TextStreamResponse(String contentTypeString charsetString text)
    {
        this(new ContentType(contentTypecharset), text);
    }
    public TextStreamResponse(ContentType contentTypeString text)
    {
        assert contentType != null;
        assert text != null;
        this. = contentType;
        this. = text;
    }
    public String getContentType()
    {
        return .toString();
    }

    
Converts the text to a byte array (as per the character set, which is usually "UTF-8"), and returns a stream for that byte array.

Returns:
the text as a byte array stram
Throws:
java.io.IOException
    public InputStream getStream() throws IOException
    {
        byte[] textBytes = .getBytes(.getCharset());
        return new ByteArrayInputStream(textBytes);
    }

    
Does nothing; subclasses may override.
    public void prepareResponse(Response response)
    {
    }
New to GrepCode? Check out our FAQ X