| 1 | |
package org.webslinger.vfs; |
| 2 | |
|
| 3 | |
import java.io.File; |
| 4 | |
import java.io.FileInputStream; |
| 5 | |
import java.io.FileOutputStream; |
| 6 | |
import java.io.InputStream; |
| 7 | |
import java.io.IOException; |
| 8 | |
import java.io.OutputStream; |
| 9 | |
import java.util.Collection; |
| 10 | |
|
| 11 | |
import org.webslinger.io.Charsets; |
| 12 | |
import org.webslinger.io.IOUtil; |
| 13 | |
|
| 14 | 27 | public class FileVFSDelegate extends VFSDelegate<File, File, File> { |
| 15 | |
public File getId(File file) { |
| 16 | 0 | return file; |
| 17 | |
} |
| 18 | |
|
| 19 | |
public Type getType(File file) { |
| 20 | 0 | if (!file.exists()) return Type.IMAGINARY; |
| 21 | 0 | return file.isDirectory() ? Type.DIRECTORY : Type.FILE; |
| 22 | |
} |
| 23 | |
|
| 24 | |
public long getLastModifiedTime(File file) { |
| 25 | 0 | return file.lastModified(); |
| 26 | |
} |
| 27 | |
|
| 28 | |
public Collection<Permission> getPermissions(File file) throws IOException { |
| 29 | 0 | if (file.canRead()) { |
| 30 | 0 | return file.canWrite() ? Permission.ALL_SET : Permission.READABLE_SET; |
| 31 | |
} else { |
| 32 | 0 | return file.canWrite() ? Permission.WRITEABLE_SET : Permission.NONE_SET; |
| 33 | |
} |
| 34 | |
} |
| 35 | |
|
| 36 | |
public String absolutePath(File file) throws IOException { |
| 37 | 0 | return file.getAbsolutePath(); |
| 38 | |
} |
| 39 | |
|
| 40 | |
public String getBaseName(File file) throws IOException { |
| 41 | 0 | return file.getName(); |
| 42 | |
} |
| 43 | |
|
| 44 | |
public File getParent(File file) throws IOException { |
| 45 | 0 | return file.getParentFile(); |
| 46 | |
} |
| 47 | |
|
| 48 | |
public File resolve(File file, String name) throws IOException { |
| 49 | 0 | return new File(file, name.replaceAll("/", File.separator)); |
| 50 | |
} |
| 51 | |
|
| 52 | |
public File[] getChildren(File file) throws IOException { |
| 53 | 0 | return file.listFiles(); |
| 54 | |
} |
| 55 | |
|
| 56 | |
public boolean attributeExists(File file, String name) throws IOException { |
| 57 | 0 | return false; |
| 58 | |
} |
| 59 | |
|
| 60 | |
public Object getAttribute(File file, String name) throws IOException { |
| 61 | 0 | return null; |
| 62 | |
} |
| 63 | |
|
| 64 | |
public String getContentType(File file) throws IOException { |
| 65 | 0 | return null; |
| 66 | |
} |
| 67 | |
|
| 68 | |
public long getLength(File file) throws IOException { |
| 69 | 0 | return file.length(); |
| 70 | |
} |
| 71 | |
|
| 72 | |
public String getString(File file) throws IOException { |
| 73 | 0 | return IOUtil.readStringFromFile(file, Charsets.UTF8); |
| 74 | |
} |
| 75 | |
|
| 76 | |
public InputStream openInput(File file) throws IOException { |
| 77 | 0 | return new FileInputStream(file); |
| 78 | |
} |
| 79 | |
|
| 80 | |
public OutputStream openOutput(File file, boolean append) throws IOException { |
| 81 | 0 | return new FileOutputStream(file, append); |
| 82 | |
} |
| 83 | |
} |