|
| 1 | + |
| 2 | +package org.xbib.classloader; |
| 3 | + |
| 4 | +import java.io.IOException; |
| 5 | +import java.io.InputStream; |
| 6 | +import java.net.URL; |
| 7 | +import java.security.cert.Certificate; |
| 8 | +import java.util.jar.Attributes; |
| 9 | +import java.util.jar.Manifest; |
| 10 | + |
| 11 | +/** |
| 12 | + * This is a handle (a connection) to some resource, which may |
| 13 | + * be a class, native library, text file, image, etc. Handles are returned |
| 14 | + * by a ResourceFinder. A resource handle allows easy access to the resource data |
| 15 | + * (using methods {@link #getInputStream} or {@link #getBytes}) as well as |
| 16 | + * access resource metadata, such as attributes, certificates, etc. |
| 17 | + * <p/> |
| 18 | + * As soon as the handle is no longer in use, it should be explicitly |
| 19 | + * {@link #close}d, similarly to I/O streams. |
| 20 | + */ |
| 21 | +public interface ResourceHandle { |
| 22 | + /** |
| 23 | + * Return the name of the resource. The name is a "/"-separated path |
| 24 | + * name that identifies the resource. |
| 25 | + */ |
| 26 | + String getName(); |
| 27 | + |
| 28 | + /** |
| 29 | + * Returns the URL of the resource. |
| 30 | + */ |
| 31 | + URL getUrl(); |
| 32 | + |
| 33 | + /** |
| 34 | + * Does this resource refer to a directory. Directory resources are commly used |
| 35 | + * as the basis for a URL in client application. A directory resource has 0 bytes for it's content. |
| 36 | + */ |
| 37 | + boolean isDirectory(); |
| 38 | + |
| 39 | + /** |
| 40 | + * Returns the CodeSource URL for the class or resource. |
| 41 | + */ |
| 42 | + URL getCodeSourceUrl(); |
| 43 | + |
| 44 | + /** |
| 45 | + * Returns and InputStream for reading this resource data. |
| 46 | + */ |
| 47 | + InputStream getInputStream() throws IOException; |
| 48 | + |
| 49 | + /** |
| 50 | + * Returns the length of this resource data, or -1 if unknown. |
| 51 | + */ |
| 52 | + int getContentLength(); |
| 53 | + |
| 54 | + /** |
| 55 | + * Returns this resource data as an array of bytes. |
| 56 | + */ |
| 57 | + byte[] getBytes() throws IOException; |
| 58 | + |
| 59 | + /** |
| 60 | + * Returns the Manifest of the JAR file from which this resource |
| 61 | + * was loaded, or null if none. |
| 62 | + */ |
| 63 | + Manifest getManifest() throws IOException; |
| 64 | + |
| 65 | + /** |
| 66 | + * Return the Certificates of the resource, or null if none. |
| 67 | + */ |
| 68 | + Certificate[] getCertificates(); |
| 69 | + |
| 70 | + /** |
| 71 | + * Return the Attributes of the resource, or null if none. |
| 72 | + */ |
| 73 | + Attributes getAttributes() throws IOException; |
| 74 | + |
| 75 | + /** |
| 76 | + * Closes a connection to the resource indentified by this handle. Releases |
| 77 | + * any I/O objects associated with the handle. |
| 78 | + */ |
| 79 | + void close(); |
| 80 | +} |
0 commit comments