1 5 package org.h2.server.ftp; 6 7 import java.io.File ; 8 import java.io.FileInputStream ; 9 import java.io.FileOutputStream ; 10 import java.io.IOException ; 11 import java.io.InputStream ; 12 import java.io.OutputStream ; 13 14 import org.h2.util.IOUtils; 15 16 public class FileObjectNative implements FileObject { 17 private File file; 18 19 static FileObjectNative get(String name) { 20 return new FileObjectNative(new File (name)); 21 } 22 23 private FileObjectNative(File f) { 24 this.file = f; 25 } 26 27 public boolean exists() { 28 return file.exists(); 29 } 30 31 public boolean isDirectory() { 32 return file.isDirectory(); 33 } 34 35 public boolean canRead() { 36 return file.canRead(); 37 } 38 39 public boolean canWrite() { 40 return file.canWrite(); 41 } 42 43 public boolean delete() { 44 return file.delete(); 45 } 46 47 public String getName() { 48 return file.getName(); 49 } 50 51 public boolean isFile() { 52 return file.isFile(); 53 } 54 55 public long lastModified() { 56 return file.lastModified(); 57 } 58 59 public long length() { 60 return file.length(); 61 } 62 63 public FileObject[] listFiles() { 64 File [] list = file.listFiles(); 65 FileObject[] result = new FileObject[list.length]; 66 for(int i=0; i<list.length; i++) { 67 result[i] = get(list[i].getAbsolutePath()); 68 } 69 return result; 70 } 71 72 public boolean mkdirs() { 73 return file.mkdirs(); 74 } 75 76 public boolean renameTo(FileObject newFile) { 77 return file.renameTo(((FileObjectNative)newFile).file); 78 } 79 80 public void write(InputStream in) throws IOException { 81 FileOutputStream out = new FileOutputStream (file); 82 IOUtils.copyAndClose(in, out); 83 } 84 85 public void read(long skip, OutputStream out) throws IOException { 86 InputStream in = new FileInputStream (file); 87 IOUtils.skipFully(in, skip); 88 IOUtils.copyAndClose(in, out); 89 } 90 91 } 92 | Popular Tags |