    001    // Copyright 2007, 2008 The Apache Software Foundation
    002    //
    003    // Licensed under the Apache License, Version 2.0 (the "License");
    004    // you may not use this file except in compliance with the License.
    005    // You may obtain a copy of the License at
    006    //
    007    //     http://www.apache.org/licenses/LICENSE-2.0
    008    //
    009    // Unless required by applicable law or agreed to in writing, software
    010    // distributed under the License is distributed on an "AS IS" BASIS,
    011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    012    // See the License for the specific language governing permissions and
    013    // limitations under the License.
    014
    015    package org.apache.tapestry5;
    016
    017    import org.apache.tapestry5.services.Response;
    018
    019    import java.io.BufferedInputStream;
    020    import java.io.IOException;
    021    import java.io.InputStream;
    022
    023    /**
    024     * An alternate response from a component event handler method used to directly provide a stream of data to be sent to
    025     * the client, rather than indicating what page to send a render redirect request to.
    026     */
    027    public interface StreamResponse
    028    {
    029        /**
    030         * Returns the content type to be reported to the client.
    031         */
    032        String getContentType();
    033
    034        /**
    035         * Returns the stream of bytes to be sent to the client. The stream will be closed when the end of the stream is
    036         * reached. The provided stream will be wrapped in a {@link BufferedInputStream} for efficiency.
    037         */
    038        InputStream getStream() throws IOException;
    039
    040
    041        /**
    042         * Prepares the response before it is sent to the client. This is the place to set any response headers (e.g.
    043         * content-disposition).
    044         *
    045         * @param response Response that will be sent.
    046         */
    047        void prepareResponse(Response response);
    048
    049    }