001 // Copyright 2011 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.services.assets;
016
017 import org.apache.tapestry5.ioc.Resource;
018
019 import java.io.IOException;
020 import java.io.InputStream;
021 import java.io.OutputStream;
022
023 /**
024 * An object, derived from a {@link Resource}, that can be streamed (ultimately, to a client web browser).
025 *
026 * @since 5.3
027 */
028 public interface StreamableResource
029 {
030 /**
031 * Describes the underlying {@link Resource} (or resources} for this streamble resource; expressly used
032 * as part of the object's {@code toString()}.
033 */
034 String getDescription();
035
036 /**
037 * Indicates if the content is compressed, or compressable.
038 */
039 CompressionStatus getCompression();
040
041 /**
042 * Returns the MIME content type, e.g., "image/jpeg".
043 */
044 String getContentType();
045
046 /**
047 * The size, in bytes, of the underlying bytestream.
048 */
049 int getSize();
050
051 /**
052 * Streams the resource's content to the provided stream. The caller is responsible for flushing or closing
053 * the output stream.
054 */
055 void streamTo(OutputStream os) throws IOException;
056
057 /**
058 * Opens the content of the resource as an input stream; the caller is responsible for closing the stream
059 * after reading it.
060 *
061 * @return stream of the contents of the resource
062 * @throws IOException
063 */
064 InputStream openStream() throws IOException;
065
066 /**
067 * Returns the time the resource was last modified, with accuracy to one second (so as to match
068 * the HTTP request/response date headers.
069 */
070 long getLastModified();
071 }