001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.util.resource; 018 019import java.io.Closeable; 020import java.io.IOException; 021import java.io.InputStream; 022import java.util.Locale; 023 024import org.apache.wicket.util.io.IClusterable; 025import org.apache.wicket.util.lang.Bytes; 026import org.apache.wicket.util.watch.IModifiable; 027 028 029/** 030 * Interface to a streamed resource. The resource stream can be retrieved by calling 031 * getInputStream(), but the resource should later be closed by calling close() on the 032 * IResourceStream (as opposed to calling close on the InputStream returned by getInputStream()). 033 * <p> 034 * Once a resource has been closed with a call to close(), it is normally possible to call 035 * getInputStream() again to retrieve a new input stream on the same resource. 036 * <p> 037 * Implementations of this interface are typically unsafe for use from multiple threads. 038 * 039 * @author Jonathan Locke 040 */ 041public interface IResourceStream extends IModifiable, IClusterable, Closeable 042{ 043 /** 044 * Gets the mime type of this resource 045 * 046 * @return The mime type of this resource, such as "image/jpeg" or "text/html". Return null to 047 * let ResourceStreamRequestHandler handle the Content-Type automatically 048 */ 049 String getContentType(); 050 051 /** 052 * Gets the size of this resource 053 * 054 * @return The size of this resource in the number of bytes, or <code>null</code> if unknown 055 */ 056 Bytes length(); 057 058 /** 059 * Gets the resource stream. You should not directly close this stream. Instead call the close() 060 * method on IResourceStream. 061 * 062 * @see IResourceStream#close() 063 * @return Returns the inputStream. 064 * @throws ResourceStreamNotFoundException 065 */ 066 InputStream getInputStream() throws ResourceStreamNotFoundException; 067 068 /** 069 * Closes the resource. Normally, this includes closing any underlying input stream returned by 070 * getInputStream(). 071 * 072 * @throws IOException 073 */ 074 @Override 075 void close() throws IOException; 076 077 /** 078 * @return The Locale where this stream did resolve to 079 */ 080 Locale getLocale(); 081 082 /** 083 * This method shouldn't be used from the outside. It is used by the Loaders to set the resolved 084 * locale. 085 * 086 * @param locale 087 * The Locale where this stream did resolve to. 088 */ 089 void setLocale(Locale locale); 090 091 /** 092 * @return The Style where this stream did resolve to 093 */ 094 String getStyle(); 095 096 /** 097 * This method shouldn't be used from the outside. It is used by the Loaders to set the resolved 098 * Style. 099 * 100 * @param style 101 * The style where this stream did resolve to. 102 */ 103 void setStyle(String style); 104 105 /** 106 * @return The Variation where this stream did resolve to 107 */ 108 String getVariation(); 109 110 /** 111 * This method shouldn't be used from the outside. It is used by the Loaders to set the resolved 112 * variation. 113 * 114 * @param variation 115 * The Variation where this stream did resolve to. 116 */ 117 void setVariation(String variation); 118}