001 /** 002 * ================================================ 003 * LibLoader : a free Java resource loading library 004 * ================================================ 005 * 006 * Project Info: http://reporting.pentaho.org/libloader/ 007 * 008 * (C) Copyright 2006, by Pentaho Corporation and Contributors. 009 * 010 * This library is free software; you can redistribute it and/or modify it under the terms 011 * of the GNU Lesser General Public License as published by the Free Software Foundation; 012 * either version 2.1 of the License, or (at your option) any later version. 013 * 014 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 015 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 016 * See the GNU Lesser General Public License for more details. 017 * 018 * You should have received a copy of the GNU Lesser General Public License along with this 019 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, 020 * Boston, MA 02111-1307, USA. 021 * 022 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 023 * in the United States and other countries.] 024 * 025 * 026 * ------------ 027 * $Id: ResourceData.java 2777 2007-05-04 14:21:56Z taqua $ 028 * ------------ 029 * (C) Copyright 2006, by Pentaho Corporation. 030 */ 031 package org.jfree.resourceloader; 032 033 import java.io.InputStream; 034 035 /** 036 * A resource data object encapsulates the raw data of an resource at a given 037 * point in the past. 038 * 039 * Any change to the resource increases the version number. Version numbers 040 * are not needed to be checked regulary, but must be checked on each call to 041 * 'getVersion()'. 042 * 043 * This definitly does *not* solve the problem of concurrent modifications; if 044 * you need to be sure that the resource has not been altered between the last 045 * call to 'getVersion' and 'getResource..' external locking mechanism have to 046 * be implemented. 047 * 048 * @author Thomas Morgner 049 */ 050 public interface ResourceData 051 { 052 public static final String CONTENT_LENGTH = "content-length"; 053 public static final String CONTENT_TYPE = "content-type"; 054 public static final String FILENAME = "filename"; 055 056 public InputStream getResourceAsStream(ResourceManager caller) throws ResourceLoadingException; 057 058 /** 059 * This is dangerous, especially if the resource is large. 060 * 061 * @param caller 062 * @return 063 * @throws ResourceLoadingException 064 */ 065 public byte[] getResource(ResourceManager caller) throws ResourceLoadingException; 066 067 /** 068 * Tries to read data into the given byte-array. 069 * 070 * @param caller 071 * @param target 072 * @param offset 073 * @param length 074 * @return the number of bytes read or -1 if no more data can be read. 075 * @throws ResourceLoadingException 076 */ 077 public int getResource(ResourceManager caller, byte[] target, int offset, int length) 078 throws ResourceLoadingException; 079 080 public Object getAttribute (String key); 081 public ResourceKey getKey(); 082 public long getVersion(ResourceManager caller) 083 throws ResourceLoadingException; 084 085 }