KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > core > io > Resource


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.core.io;
18
19 import java.io.File JavaDoc;
20 import java.io.IOException JavaDoc;
21 import java.net.URL JavaDoc;
22
23 /**
24  * Interface for a resource descriptor that abstracts from the actual
25  * type of underlying resource, such as a file or class path resource.
26  *
27  * <p>An InputStream can be opened for every resource if it exists in
28  * physical form, but a URL or File handle can just be returned for
29  * certain resources. The actual behavior is implementation-specific.
30  *
31  * @author Juergen Hoeller
32  * @since 28.12.2003
33  * @see #getInputStream()
34  * @see #getURL()
35  * @see #getFile()
36  * @see FileSystemResource
37  * @see ClassPathResource
38  * @see UrlResource
39  * @see ByteArrayResource
40  * @see InputStreamResource
41  * @see org.springframework.web.context.support.ServletContextResource
42  */

43 public interface Resource extends InputStreamSource {
44
45     /**
46      * Return whether this resource actually exists in physical form.
47      */

48     boolean exists();
49
50     /**
51      * Return whether this resource represents a handle with an open
52      * stream. If true, the InputStream cannot be read multiple times,
53      * and must be read and closed to avoid resource leaks.
54      * <p>Will be false for all usual resource descriptors.
55      */

56     boolean isOpen();
57
58     /**
59      * Return a URL handle for this resource.
60      * @throws IOException if the resource cannot be resolved as URL,
61      * i.e. if the resource is not available as descriptor
62      */

63     URL JavaDoc getURL() throws IOException JavaDoc;
64
65     /**
66      * Return a File handle for this resource.
67      * @throws IOException if the resource cannot be resolved as absolute
68      * file path, i.e. if the resource is not available in a file system
69      */

70     File JavaDoc getFile() throws IOException JavaDoc;
71
72     /**
73      * Create a resource relative to this resource.
74      * @param relativePath the relative path (relative to this resource)
75      * @return the resource handle for the relative resource
76      * @throws IOException if the relative resource cannot be determined
77      */

78     Resource createRelative(String JavaDoc relativePath) throws IOException JavaDoc;
79
80     /**
81      * Return a filename for this resource, i.e. typically the last
82      * part of the path: for example, "myfile.txt".
83      */

84     String JavaDoc getFilename();
85
86     /**
87      * Return a description for this resource,
88      * to be used for error output when working with the resource.
89      * <p>Implementations are also encouraged to return this value
90      * from their <code>toString</code> method.
91      * @see java.lang.Object#toString
92      */

93     String JavaDoc getDescription();
94
95 }
96
Popular Tags