-
-
Notifications
You must be signed in to change notification settings - Fork 947
Expand file tree
/
Copy pathFileResource.java
More file actions
122 lines (103 loc) · 3.28 KB
/
Copy pathFileResource.java
File metadata and controls
122 lines (103 loc) · 3.28 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package org.jruby.util;
import java.io.IOException;
import java.io.InputStream;
import jnr.posix.FileStat;
import jnr.posix.POSIX;
import org.jruby.util.io.ModeFlags;
import java.nio.channels.Channel;
/**
* This is a shared interface for files loaded as {@link java.io.File} and {@link java.util.zip.ZipEntry}.
*/
public interface FileResource {
static FileResource wrap(POSIX posix, JRubyFile file) {
return new RegularFileResource(posix, file, file.getPathDefault());
}
String absolutePath();
String canonicalPath();
String path();
boolean exists();
boolean isDirectory();
boolean isFile();
boolean canExecute();
int errno();
long lastModified();
long length();
boolean canRead();
boolean canWrite();
/**
* @return is this a NUL device?
*/
default boolean isNull() { return false; }
/**
* @see java.io.File#list()
*/
String[] list();
boolean isSymLink();
FileStat stat();
FileStat lstat();
/**
* Unwrap the resource backend (replacement for {@link #hackyGetJRubyFile()}).
* @param type
* @param <T>
* @return backend if supported
* @throws UnsupportedOperationException
*/
<T> T unwrap(Class<T> type) throws UnsupportedOperationException ;
/**
* @deprecated
*
* Opens a new input stream to read the contents of a resource and returns it.
* Note that implementations may be allocating native memory for the stream, so
* callers need to close this when they are done with it. users of this
* method should follow the pattern: close the stream where you open it.
*
* @return just opened InputStream
* @throws ResourceException is the file does not exists or if the resource is a directory
*/
@Deprecated(since = "9.4-")
default InputStream inputStream() throws ResourceException {
if (!exists()) {
throw new ResourceException.NotFound(absolutePath());
}
if (isDirectory()) {
throw new ResourceException.FileIsDirectory(absolutePath());
}
try {
return openInputStream();
}
catch (IOException e) {
throw new ResourceException.IOError(e);
}
}
/**Opens a new input stream to read the contents of a resource and returns it.
*
* Note that implementations may be allocating native memory for the stream, so
* callers need to close this when they are done with it. users of this
* method should follow the pattern: close the stream where you open it.
*
* @return InputStream
* @throws IOException
*/
InputStream openInputStream() throws IOException ;
/**
* @deprecated use {@link #openChannel(int, int)} instead
*
* @param flags
* @param perm
* @return channel
* @throws ResourceException
*/
@Deprecated(since = "9.4-")
default Channel openChannel(ModeFlags flags, int perm) throws ResourceException {
try {
return openChannel(flags.getFlags(), perm);
}
catch (ResourceException ex) {
throw ex;
}
catch (IOException ex) {
throw new ResourceException.IOError(ex);
}
}
Channel openChannel(int flags, int perm) throws IOException ;
}