KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javazoom > download > util > FileInfo


1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  */

16 package javazoom.download.util;
17
18 import java.io.BufferedReader JavaDoc;
19 import java.io.BufferedWriter JavaDoc;
20 import java.io.File JavaDoc;
21 import java.io.FileReader JavaDoc;
22 import java.io.FileWriter JavaDoc;
23 import java.io.Serializable JavaDoc;
24 import java.util.List JavaDoc;
25
26 public class FileInfo implements Serializable JavaDoc {
27
28     public static String JavaDoc PATH = "";
29     
30     public FileInfo(String JavaDoc fileName){
31         this.filename = fileName;
32         loadData();
33     }
34
35     public FileInfo(String JavaDoc s, String JavaDoc s1, String JavaDoc s2, String JavaDoc s3, String JavaDoc s4,
36             boolean flag, int i, String JavaDoc s5, String JavaDoc s6, String JavaDoc 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         //load the saving data
62
loadData();
63     }
64     
65     public static FileInfo getFileInfo(List JavaDoc files, String JavaDoc 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 JavaDoc fn = filename + ".sav";
77         BufferedReader JavaDoc reader = null;
78         try{
79             reader = new BufferedReader JavaDoc(new FileReader JavaDoc(PATH+File.separator+fn));
80             String JavaDoc 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 JavaDoc e){
86             e.printStackTrace();
87         }finally{
88             try{
89                 reader.close();
90             }catch(Exception JavaDoc e){}
91         }
92     }
93     
94     protected void saveData(int d1, int d2){
95         String JavaDoc fn = filename + ".sav";
96         BufferedWriter JavaDoc writer = null;
97         try{
98             writer = new BufferedWriter JavaDoc(new FileWriter JavaDoc(PATH+File.separator+fn));
99             writer.write(d1+","+d2);
100         }catch(Exception JavaDoc e){
101             e.printStackTrace();
102         }finally{
103             try{
104                 writer.close();
105             }catch(Exception JavaDoc 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 JavaDoc s) {
120         return login.equals(s);
121     }
122
123     public boolean checkPassword(String JavaDoc s) {
124         return password.equals(s);
125     }
126
127     public String JavaDoc getContentDisposition() {
128         return contentDisposition;
129     }
130
131     public String JavaDoc getContentDispositionHeader() {
132         return contentDispositionHeader;
133     }
134
135     public String JavaDoc getContentType() {
136         return contentType;
137     }
138
139     public String JavaDoc getCustomField() {
140         return customField;
141     }
142
143     public static String JavaDoc getExtension(String JavaDoc s) {
144         String JavaDoc 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 JavaDoc getFilename() {
152         return filename;
153     }
154
155     public String JavaDoc getFilenameExtension() {
156         return getExtension(filename);
157     }
158
159     public String JavaDoc getLogin() {
160         return login;
161     }
162
163     public int getMaxDownload() {
164         return maxDownload;
165     }
166
167     public String JavaDoc getPassword() {
168         return password;
169     }
170
171     public String JavaDoc getPath() {
172         return path;
173     }
174
175     public String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc s) {
220         contentDisposition = s;
221     }
222
223     public void setContentDispositionHeader(String JavaDoc s) {
224         contentDispositionHeader = s;
225     }
226
227     public void setContentType(String JavaDoc 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 JavaDoc contentDisposition;
246
247     private String JavaDoc contentDispositionHeader;
248
249     private String JavaDoc contentType;
250
251     private String JavaDoc customField;
252
253     private boolean zipEnabled;
254
255     private String JavaDoc filename;
256
257     private String JavaDoc login;
258
259     private int maxDownload;
260
261     private String JavaDoc password;
262
263     private String JavaDoc path;
264
265     private long size;
266
267     private int download;
268
269     private int incompleteDownload;
270
271     private String JavaDoc urlMapping;
272 }
Popular Tags