1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.impl;
18
19 import java.io.IOException;
20 import java.net.URL;
21 import java.util.jar.Attributes;
22
23 import org.apache.commons.vfs2.FileObject;
24 import org.apache.commons.vfs2.FileSystemException;
25 import org.apache.commons.vfs2.util.FileObjectUtils;
26
27
28
29
30
31
32 final class Resource {
33
34 private final FileObject root;
35 private final FileObject resource;
36 private final FileObject packageFolder;
37 private final String packageName;
38
39
40
41
42
43
44
45 public Resource(final String name, final FileObjectObject.html#FileObject">FileObject root, final FileObject resource) throws FileSystemException {
46 this.root = root;
47 this.resource = resource;
48 packageFolder = resource.getParent();
49 final int pos = name.lastIndexOf('/');
50 if (pos == -1) {
51 packageName = null;
52 } else {
53 packageName = name.substring(0, pos).replace('/', '.');
54 }
55 }
56
57
58
59
60 public URL getURL() throws FileSystemException {
61 return resource.getURL();
62 }
63
64
65
66
67 public String getPackageName() {
68 return packageName;
69 }
70
71
72
73
74 public String getPackageAttribute(final Attributes.Name attrName) throws FileSystemException {
75 return (String) packageFolder.getContent().getAttribute(attrName.toString());
76 }
77
78
79
80
81 public FileObject getPackageFolder() {
82 return packageFolder;
83 }
84
85
86
87
88 public FileObject getFileObject() {
89 return resource;
90 }
91
92
93
94
95 public URL getCodeSourceURL() throws FileSystemException {
96 return root.getURL();
97 }
98
99
100
101
102 public byte[] getBytes() throws IOException {
103 return FileObjectUtils.getContentAsByteArray(resource);
104 }
105 }