1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.provider.jar;
18
19 import java.io.IOException;
20 import java.security.cert.Certificate;
21 import java.util.HashMap;
22 import java.util.Map;
23 import java.util.jar.Attributes;
24 import java.util.jar.JarEntry;
25 import java.util.jar.JarFile;
26 import java.util.jar.Manifest;
27 import java.util.zip.ZipEntry;
28
29 import org.apache.commons.vfs2.FileSystemException;
30 import org.apache.commons.vfs2.provider.AbstractFileName;
31 import org.apache.commons.vfs2.provider.zip.ZipFileObject;
32
33
34
35
36 public class JarFileObject extends ZipFileObject {
37
38 private final JarFileSystem fs;
39
40 private Attributes attributes;
41
42
43
44
45
46
47
48
49
50
51 protected JarFileObject(final AbstractFileName fileName, final ZipEntry entry, final JarFileSystem fileSystem,
52 final boolean zipExists) throws FileSystemException {
53 super(fileName, entry, fileSystem, zipExists);
54 if (entry != null) {
55
56
57
58 ((JarEntry) entry).getCertificates();
59 }
60 this.fs = fileSystem;
61
62 try {
63 getAttributes();
64 } catch (final IOException e) {
65 throw new FileSystemException(e);
66 }
67 }
68
69
70
71
72 private void addAll(final Attributes src, final Map<String, Object> dest) {
73 src.forEach((k, v) -> dest.put(String.valueOf(k), v));
74 }
75
76
77
78
79 @Override
80 protected Map<String, Object> doGetAttributes() throws Exception {
81 final Map<String, Object> attrs = new HashMap<>();
82
83
84 final JarFileSystem fs = (JarFileSystem) getFileSystem();
85 addAll(fs.getAttributes(), attrs);
86
87
88 addAll(getAttributes(), attrs);
89
90 return attrs;
91 }
92
93
94
95
96 @Override
97 protected Certificate[] doGetCertificates() {
98 if (entry == null) {
99 return null;
100 }
101
102 return ((JarEntry) entry).getCertificates();
103 }
104
105
106
107
108 Attributes getAttributes() throws IOException {
109 if (attributes == null) {
110 if (entry == null) {
111 attributes = new Attributes(1);
112 } else {
113 attributes = ((JarEntry) entry).getAttributes();
114 if (attributes == null) {
115 attributes = new Attributes(1);
116 }
117 }
118 }
119
120 return attributes;
121 }
122
123
124
125
126 Manifest getManifest() throws IOException {
127 if (fs.getZipFile() == null) {
128 return null;
129 }
130
131 return ((JarFile) fs.getZipFile()).getManifest();
132 }
133 }