1 package de.jwi.jfm; 2 3 24 25 import java.io.File ; 26 import java.io.UnsupportedEncodingException ; 27 import java.net.URLEncoder ; 28 import java.text.DateFormat ; 29 import java.util.Date ; 30 31 import org.apache.commons.io.FileUtils; 32 33 37 public class FileWrapper 38 { 39 40 private Folder folder; 41 42 private File file; 43 44 private String url; 45 46 private String path; 47 48 private DateFormat dateFormat; 49 50 FileWrapper(Folder folder, File file, String url, String path) 51 { 52 this.folder = folder; 53 this.file = file; 54 this.url = url; 55 this.path = path; 56 dateFormat = DateFormat.getDateTimeInstance(); 57 } 58 59 public File getFile() 60 { 61 return file; 62 } 63 64 public String getUrl() 65 { 66 return url; 67 } 68 69 public String getId() 70 { 71 String s = null; 72 try 73 { 74 s = URLEncoder.encode(file.getName() + "." 75 + Long.toString(file.lastModified()), "UTF-8"); 76 } 77 catch (UnsupportedEncodingException e) 78 { 79 } 80 return s; 81 } 82 83 public String getName() 84 { 85 return file.getName(); 86 } 87 88 public String getPath() 90 { 91 return path; 92 } 93 94 public String toString() 95 { 96 return file.toString(); 97 } 98 99 public String getSize() 100 { 101 long l; 102 103 l = file.length(); 104 105 if (file.isDirectory() && folder.isCalcRecursiveFolderSize()) 106 { 107 l = FileUtils.sizeOfDirectory(file); 108 } 109 return FileUtils.byteCountToDisplaySize(l); 110 } 111 112 public boolean getIsDirectory() 113 { 114 return file.isDirectory(); 115 } 116 117 public boolean getIsZip() 118 { 119 if (file.isDirectory()) { return false; } 120 String s = file.getName().toLowerCase(); 121 122 return s.endsWith(".zip"); 123 } 124 125 public String getType() 126 { 127 return file.isDirectory() ? "dir" : "file"; 128 } 129 130 public String getLastModified() 131 { 132 long l = file.lastModified(); 133 String s = dateFormat.format(new Date (l)); 134 return s; 135 } 136 137 } | Popular Tags |