1 16 package org.apache.commons.vfs.impl; 17 18 import org.apache.commons.vfs.FileObject; 19 import org.apache.commons.vfs.FileSystemException; 20 import org.apache.commons.vfs.FileUtil; 21 22 import java.io.IOException ; 23 import java.net.URL ; 24 import java.util.jar.Attributes ; 25 26 33 class Resource 34 { 35 private final FileObject root; 36 private final FileObject resource; 37 private final FileObject packageFolder; 38 private final String packageName; 39 40 46 public Resource(final String name, 47 final FileObject root, 48 final FileObject resource) 49 throws FileSystemException 50 { 51 this.root = root; 52 this.resource = resource; 53 packageFolder = resource.getParent(); 54 final int pos = name.lastIndexOf('/'); 55 if (pos == -1) 56 { 57 packageName = null; 58 } 59 else 60 { 61 packageName = name.substring(0, pos).replace('/', '.'); 62 } 63 } 64 65 68 public URL getURL() throws FileSystemException 69 { 70 return resource.getURL(); 71 } 72 73 76 public String getPackageName() 77 { 78 return packageName; 79 } 80 81 84 public String getPackageAttribute(final Attributes.Name attrName) throws FileSystemException 85 { 86 return (String ) packageFolder.getContent().getAttribute(attrName.toString()); 87 } 88 89 92 public FileObject getPackageFolder() 93 { 94 return packageFolder; 95 } 96 97 100 public FileObject getFileObject() 101 { 102 return resource; 103 } 104 105 108 public URL getCodeSourceURL() throws FileSystemException 109 { 110 return root.getURL(); 111 } 112 113 116 public byte[] getBytes() throws IOException 117 { 118 return FileUtil.getContent(resource); 119 } 120 } 121 | Popular Tags |