1 16 package javazoom.download.util; 17 18 import java.io.BufferedReader ; 19 import java.io.BufferedWriter ; 20 import java.io.File ; 21 import java.io.FileReader ; 22 import java.io.FileWriter ; 23 import java.io.Serializable ; 24 import java.util.List ; 25 26 public class FileInfo implements Serializable { 27 28 public static String PATH = ""; 29 30 public FileInfo(String fileName){ 31 this.filename = fileName; 32 loadData(); 33 } 34 35 public FileInfo(String s, String s1, String s2, String s3, String s4, 36 boolean flag, int i, String s5, String s6, String s7) { 37 path = null; 38 filename = null; 39 urlMapping = null; 40 contentType = null; 41 contentDisposition = null; 42 contentDispositionHeader = null; 43 customField = null; 44 zipEnabled = false; 45 maxDownload = -1; 46 login = null; 47 password = null; 48 download = 0; 49 incompleteDownload = 0; 50 size = -1L; 51 path = s; 52 filename = s1; 53 urlMapping = s2; 54 contentType = s3; 55 contentDisposition = s4; 56 zipEnabled = flag; 57 maxDownload = i; 58 login = s5; 59 password = s6; 60 customField = s7; 61 loadData(); 63 } 64 65 public static FileInfo getFileInfo(List files, String filename){ 66 for(int i=0;i<files.size();i++){ 67 FileInfo fi = (FileInfo)files.get(i); 68 Debug.getInstance().trace(Debug.PANIC, filename+","+fi.getFilename()); 69 if(filename.equals(fi.getFilename())) 70 return fi; 71 } 72 return null; 73 } 74 75 protected void loadData() { 76 String fn = filename + ".sav"; 77 BufferedReader reader = null; 78 try{ 79 reader = new BufferedReader (new FileReader (PATH+File.separator+fn)); 80 String line = reader.readLine(); 81 int idx = line.indexOf(','); 82 download = Integer.parseInt(line.substring(0,idx)); 83 incompleteDownload = Integer.parseInt(line.substring(idx+1)); 84 Debug.getInstance().trace(Debug.PANIC, "filename="+filename+"download="+download+",incompleteDownload="+incompleteDownload); 85 }catch(Exception e){ 86 e.printStackTrace(); 87 }finally{ 88 try{ 89 reader.close(); 90 }catch(Exception e){} 91 } 92 } 93 94 protected void saveData(int d1, int d2){ 95 String fn = filename + ".sav"; 96 BufferedWriter writer = null; 97 try{ 98 writer = new BufferedWriter (new FileWriter (PATH+File.separator+fn)); 99 writer.write(d1+","+d2); 100 }catch(Exception e){ 101 e.printStackTrace(); 102 }finally{ 103 try{ 104 writer.close(); 105 }catch(Exception e){} 106 } 107 } 108 109 public void addDownload() { 110 download++; 111 saveData(download, incompleteDownload); 112 } 113 114 public void addIncompleteDownload() { 115 incompleteDownload++; 116 saveData(download, incompleteDownload); 117 } 118 119 public boolean checkLogin(String s) { 120 return login.equals(s); 121 } 122 123 public boolean checkPassword(String s) { 124 return password.equals(s); 125 } 126 127 public String getContentDisposition() { 128 return contentDisposition; 129 } 130 131 public String getContentDispositionHeader() { 132 return contentDispositionHeader; 133 } 134 135 public String getContentType() { 136 return contentType; 137 } 138 139 public String getCustomField() { 140 return customField; 141 } 142 143 public static String getExtension(String s) { 144 String s1 = ""; 145 int i = s.lastIndexOf("."); 146 if (i != -1) 147 s1 = s.substring(i + 1, s.length()); 148 return s1; 149 } 150 151 public String getFilename() { 152 return filename; 153 } 154 155 public String getFilenameExtension() { 156 return getExtension(filename); 157 } 158 159 public String getLogin() { 160 return login; 161 } 162 163 public int getMaxDownload() { 164 return maxDownload; 165 } 166 167 public String getPassword() { 168 return password; 169 } 170 171 public String getPath() { 172 return path; 173 } 174 175 public String getRelativeFilename() { 176 int i = filename.lastIndexOf("/"); 177 if (i != -1) 178 return filename.substring(i + 1, filename.length()); 179 else 180 return filename; 181 } 182 183 public String getRelativePath() { 184 int i = filename.lastIndexOf("/"); 185 if (i != -1) 186 return filename.substring(0, i); 187 else 188 return ""; 189 } 190 191 public long getSize() { 192 return size; 193 } 194 195 public int getTotalDownload() { 196 return download; 197 } 198 199 public int getTotalIncompleteDownload() { 200 return incompleteDownload; 201 } 202 203 public String getUrlMapping() { 204 return urlMapping; 205 } 206 207 public boolean isZipEnabled() { 208 return zipEnabled; 209 } 210 211 public void resetTotalDownload() { 212 download = 0; 213 } 214 215 public void resetTotalIncompleteDownload() { 216 incompleteDownload = 0; 217 } 218 219 public void setContentDisposition(String s) { 220 contentDisposition = s; 221 } 222 223 public void setContentDispositionHeader(String s) { 224 contentDispositionHeader = s; 225 } 226 227 public void setContentType(String s) { 228 contentType = s; 229 } 230 231 public void setSize(long l) { 232 size = l; 233 } 234 235 public void updateDownload(int i) { 236 System.out.println("updateDownload i="+i); 237 download = i; 238 } 239 240 public void updateIncompleteDownload(int i) { 241 System.out.println("updateIncompleteDownload i="+i); 242 incompleteDownload = i; 243 } 244 245 private String contentDisposition; 246 247 private String contentDispositionHeader; 248 249 private String contentType; 250 251 private String customField; 252 253 private boolean zipEnabled; 254 255 private String filename; 256 257 private String login; 258 259 private int maxDownload; 260 261 private String password; 262 263 private String path; 264 265 private long size; 266 267 private int download; 268 269 private int incompleteDownload; 270 271 private String urlMapping; 272 } | Popular Tags |