slcom/slangc/streams/File.sauce

53 lines
1.1 KiB
Plaintext
Raw Permalink Normal View History

package slangc.streams;
public class File {
private VFS vfs;
private String path;
File(VFS vfs, String path) {
this.vfs = vfs;
this.path = path;
}
public VFS getVFS() {
return vfs;
}
FileInput openInput() throws Error {
return vfs.openInput(path);
}
FileOutput openOutput() throws Error {
return vfs.openOutput(path);
}
File[] list() throws Error {
return vfs.list(path);
}
public String path() {
return path;
}
private static String trimPathSeparator(String path, String sep) {
int l = path.searchLast(sep);
if (l >= 0) {
return path.sub(l + sep.ints().length);
} else {
return path;
}
}
public String name() {
String p = path;
String[] seps = vfs.allSeparators();
for (int i = 0; i < seps.length; i++) {
p = trimPathSeparator(p, seps[i]);
}
return p;
}
public long size() {
return vfs.size(path);
}
}