-
-
Notifications
You must be signed in to change notification settings - Fork 938
Expand file tree
/
Copy pathJarFileResource.java
More file actions
83 lines (67 loc) · 1.94 KB
/
JarFileResource.java
File metadata and controls
83 lines (67 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package org.jruby.util;
import java.io.IOException;
import java.io.InputStream;
import java.nio.channels.Channel;
import java.nio.channels.Channels;
import java.nio.file.attribute.FileTime;
import java.util.jar.JarEntry;
/**
* Represents a file in a jar.
*
* <p>
* Note: while directories can be contained within a jar, they're still represented by
* JarDirectoryResource, since Ruby expects a directory to exist as long as any files in that
* directory do, or Dir.glob would break.
* </p>
*/
class JarFileResource extends JarResource {
private final JarCache.JarIndex index;
private final JarEntry entry;
JarFileResource(String jarPath, boolean rootSlashPrefix, JarCache.JarIndex index, JarEntry entry) {
super(jarPath, rootSlashPrefix);
this.index = index;
this.entry = entry;
}
@Override
public String entryName() {
return entry.getName();
}
@Override
public boolean isDirectory() {
return false;
}
@Override
public boolean isFile() {
return true;
}
@Override
public long length() {
return entry.getSize();
}
public FileTime creationTime() {
return entry.getCreationTime();
}
public FileTime lastAccessTime() {
return entry.getLastAccessTime();
}
public FileTime lastModifiedTime() {
return entry.getLastModifiedTime();
}
@Override
public String[] list() {
return null; // Files cannot be listed
}
@Override
public InputStream openInputStream() throws IOException {
return index.getInputStream(entry);
}
@Override
public Channel openChannel(int flags, int perm) throws IOException {
return Channels.newChannel(openInputStream());
}
@Override
public <T> T unwrap(Class<T> type) {
if (type == JarEntry.class) return (T) entry;
throw new UnsupportedOperationException("unwrap: " + type.getName());
}
}