Mercurial > hg > digilib-old
annotate servlet/src/digilib/servlet/PDFCache.java @ 555:88ed97d08b97 digilibPDF
still refactoring
author | robcast |
---|---|
date | Thu, 16 Dec 2010 14:31:48 +0100 |
parents | 785fc58b68b1 |
children | 5cc180bb0a5c |
rev | line source |
---|---|
500 | 1 package digilib.servlet; |
2 | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
3 import java.io.BufferedInputStream; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
4 import java.io.File; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
5 import java.io.FileInputStream; |
548 | 6 import java.io.FileNotFoundException; |
7 import java.io.FileOutputStream; | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
8 import java.io.IOException; |
546 | 9 import java.io.OutputStream; |
548 | 10 import java.util.concurrent.Future; |
500 | 11 |
505 | 12 import javax.servlet.RequestDispatcher; |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
13 import javax.servlet.ServletConfig; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
14 import javax.servlet.ServletContext; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
15 import javax.servlet.ServletException; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
16 import javax.servlet.ServletOutputStream; |
500 | 17 import javax.servlet.http.HttpServletRequest; |
18 import javax.servlet.http.HttpServletResponse; | |
19 | |
548 | 20 import digilib.image.DocuImage; |
21 | |
509 | 22 /** |
23 * A class for handling user requests for pdf documents from digilib images. | |
24 * | |
511 | 25 * If a document does not already exist, it will be enqueued for generation; if it does exist, it is sent |
26 * to the user. | |
27 * | |
509 | 28 * @author cmielack |
29 * | |
30 */ | |
31 | |
533 | 32 @SuppressWarnings("serial") |
500 | 33 public class PDFCache extends RequestHandler { |
34 | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
35 private DigilibConfiguration dlConfig = null; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
36 |
533 | 37 public static String instanceKey = "digilib.servlet.PDFCache"; |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
38 |
546 | 39 private DigilibJobCenter<OutputStream> pdfJobCenter = null; |
40 | |
548 | 41 private DigilibJobCenter<DocuImage> pdfImageJobCenter = null; |
42 | |
533 | 43 private File cache_directory = new File("cache"); |
505 | 44 |
533 | 45 private File temp_directory = new File("pdf_temp"); |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
46 |
505 | 47 private static String JSP_WIP = "/pdf/wip.jsp"; |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
48 |
505 | 49 private static String JSP_ERROR = "/pdf/error.jsp"; |
500 | 50 |
51 public static Integer STATUS_DONE = 0; // document exists in cache | |
52 | |
53 public static Integer STATUS_WIP = 1; // document is "work in progress" | |
54 | |
55 public static Integer STATUS_NONEXISTENT = 2; // document does not exist in cache and is not in progress | |
56 | |
57 public static Integer STATUS_ERROR = 3; // an error occurred while processing the request | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
58 |
550 | 59 public static String version = "0.3a"; |
509 | 60 |
511 | 61 // TODO ? functionality for the pre-generation of complete books/chapters using default values |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
62 |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
63 |
548 | 64 public void init(ServletConfig config) throws ServletException { |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
65 super.init(config); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
66 |
531
9cedd170b581
* PDF generation works now even with subdirectories
robcast
parents:
511
diff
changeset
|
67 System.out.println("***** Digital Image Library Image PDF-Cache Servlet (version " |
9cedd170b581
* PDF generation works now even with subdirectories
robcast
parents:
511
diff
changeset
|
68 + version + ") *****"); |
546 | 69 // say hello in the log file |
531
9cedd170b581
* PDF generation works now even with subdirectories
robcast
parents:
511
diff
changeset
|
70 logger.info("***** Digital Image Library Image PDF-Cache Servlet (version " |
9cedd170b581
* PDF generation works now even with subdirectories
robcast
parents:
511
diff
changeset
|
71 + version + ") *****"); |
9cedd170b581
* PDF generation works now even with subdirectories
robcast
parents:
511
diff
changeset
|
72 |
552 | 73 ServletContext context = getServletContext(); |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
74 dlConfig = (DigilibConfiguration) context.getAttribute("digilib.servlet.configuration"); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
75 if (dlConfig == null) { |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
76 // no Configuration |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
77 throw new ServletException("No Configuration!"); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
78 } |
533 | 79 |
80 String temp_fn = dlConfig.getAsString("pdf-temp-dir"); | |
81 temp_directory = new File(temp_fn); | |
550 | 82 if (!temp_directory.exists()) { |
83 // try to create | |
84 temp_directory.mkdirs(); | |
85 } | |
533 | 86 if (!temp_directory.isDirectory()) { |
87 throw new ServletException("Configuration error: problem with pdf-temp-dir="+temp_fn); | |
88 } | |
89 // rid the temporary directory of possible incomplete document files | |
90 emptyDirectory(temp_directory); | |
91 | |
92 String cache_fn = dlConfig.getAsString("pdf-cache-dir"); | |
93 cache_directory = new File(cache_fn); | |
550 | 94 if (!cache_directory.exists()) { |
95 // try to create | |
96 cache_directory.mkdirs(); | |
97 } | |
533 | 98 if (!cache_directory.isDirectory()) { |
99 throw new ServletException("Configuration error: problem with pdf-cache-dir="+cache_fn); | |
100 } | |
500 | 101 |
546 | 102 pdfJobCenter = (DigilibJobCenter<OutputStream>) dlConfig.getValue("servlet.worker.pdfexecutor"); |
548 | 103 pdfImageJobCenter = (DigilibJobCenter<DocuImage>) dlConfig.getValue("servlet.worker.pdfimageexecutor"); |
546 | 104 |
509 | 105 // register this instance globally |
533 | 106 context.setAttribute(instanceKey, this); |
509 | 107 |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
108 } |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
109 |
511 | 110 /** |
111 * clean up any broken and unfinished files from the temporary directory. | |
112 */ | |
533 | 113 public void emptyDirectory(File temp_dir){ |
114 File[] temp_files = temp_dir.listFiles(); | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
115 |
533 | 116 for (File f: temp_files){ |
117 f.delete(); | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
118 } |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
119 } |
500 | 120 |
121 | |
122 public void processRequest(HttpServletRequest request, | |
123 HttpServletResponse response) { | |
124 | |
555 | 125 String docid = ""; |
126 try { | |
500 | 127 // evaluate request ( make a PDFJobDeclaration , get the DocumentId) |
548 | 128 PDFJobDescription pdfji = new PDFJobDescription(request, dlConfig); |
500 | 129 |
555 | 130 docid = pdfji.getDocumentId(); |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
131 |
505 | 132 // if some invalid data has been entered ... |
133 if(!pdfji.checkValidity()) { | |
134 notifyUser(STATUS_ERROR, docid, request, response); | |
135 return; | |
136 } | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
137 |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
138 int status = getStatus(docid); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
139 |
531
9cedd170b581
* PDF generation works now even with subdirectories
robcast
parents:
511
diff
changeset
|
140 if (status == STATUS_NONEXISTENT) { |
548 | 141 // not there -- start creation |
549 | 142 try { |
143 createNewPdfDocument(pdfji, docid); | |
144 notifyUser(status, docid, request, response); | |
145 } catch (FileNotFoundException e) { | |
146 // error in pdf creation | |
147 logger.error(e.getMessage()); | |
148 notifyUser(STATUS_ERROR, docid, request, response); | |
149 } | |
531
9cedd170b581
* PDF generation works now even with subdirectories
robcast
parents:
511
diff
changeset
|
150 } else if (status == STATUS_DONE) { |
548 | 151 // pdf created -- send it |
531
9cedd170b581
* PDF generation works now even with subdirectories
robcast
parents:
511
diff
changeset
|
152 try { |
542
e2ff961001af
first step towards more standard java.util.concurrent design
robcast
parents:
533
diff
changeset
|
153 sendFile(docid, getDownloadFilename(pdfji), response); |
531
9cedd170b581
* PDF generation works now even with subdirectories
robcast
parents:
511
diff
changeset
|
154 } catch (IOException e) { |
549 | 155 // sending didn't work |
531
9cedd170b581
* PDF generation works now even with subdirectories
robcast
parents:
511
diff
changeset
|
156 logger.error(e.getMessage()); |
9cedd170b581
* PDF generation works now even with subdirectories
robcast
parents:
511
diff
changeset
|
157 } |
9cedd170b581
* PDF generation works now even with subdirectories
robcast
parents:
511
diff
changeset
|
158 } else { |
549 | 159 // should be work in progress |
531
9cedd170b581
* PDF generation works now even with subdirectories
robcast
parents:
511
diff
changeset
|
160 notifyUser(status, docid, request, response); |
9cedd170b581
* PDF generation works now even with subdirectories
robcast
parents:
511
diff
changeset
|
161 } |
555 | 162 } catch (Exception e) { |
163 // error in pdf creation | |
164 logger.error(e.getMessage()); | |
165 notifyUser(STATUS_ERROR, docid, request, response); | |
166 } | |
500 | 167 } |
168 | |
511 | 169 /** |
549 | 170 * depending on the documents status, redirect the user to the appropriate waiting or download page. |
511 | 171 * |
172 * @param status | |
173 * @param documentid | |
174 * @param request | |
175 * @param response | |
176 */ | |
505 | 177 public void notifyUser(int status, String documentid, HttpServletRequest request, HttpServletResponse response){ |
500 | 178 |
505 | 179 String jsp=null; |
180 | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
181 if(status == STATUS_NONEXISTENT){ |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
182 // tell the user that the document has to be created before he/she can download it |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
183 logger.debug("PDFCache: "+documentid+" has STATUS_NONEXISTENT."); |
505 | 184 jsp = JSP_WIP; |
533 | 185 } else if(status == STATUS_WIP){ |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
186 logger.debug("PDFCache: "+documentid+" has STATUS_WIP."); |
505 | 187 jsp = JSP_WIP; |
500 | 188 |
549 | 189 // TODO: estimate remaining work time |
190 // TODO: tell the user he/she has to wait | |
533 | 191 } else if(status == STATUS_DONE){ |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
192 logger.debug("PDFCache: "+documentid+" has STATUS_DONE."); |
533 | 193 } else { |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
194 logger.debug("PDFCache: "+documentid+" has STATUS_ERROR."); |
505 | 195 jsp = JSP_ERROR; |
196 } | |
500 | 197 |
505 | 198 try { |
548 | 199 // forward to the relevant jsp |
552 | 200 ServletContext context = getServletContext(); |
548 | 201 RequestDispatcher dispatch = context.getRequestDispatcher(jsp); |
505 | 202 dispatch.forward(request, response); |
203 } catch (ServletException e) { | |
204 logger.debug(e.getMessage()); | |
205 e.printStackTrace(); | |
206 } catch (IOException e) { | |
207 logger.debug(e.getMessage()); | |
208 e.printStackTrace(); | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
209 } |
505 | 210 |
500 | 211 } |
212 | |
213 | |
214 /** check the status of the document corresponding to the documentid */ | |
215 public Integer getStatus(String documentid){ | |
505 | 216 // looks into the cache and temp directory in order to find out the status of the document |
533 | 217 File cached = new File(cache_directory, documentid); |
218 File wip = new File(temp_directory, documentid); | |
505 | 219 if(cached.exists()){ |
220 return STATUS_DONE; | |
533 | 221 } else if (wip.exists()){ |
505 | 222 return STATUS_WIP; |
533 | 223 } else { |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
224 return STATUS_NONEXISTENT; |
505 | 225 } |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
226 } |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
227 |
511 | 228 /** |
229 * create new thread for pdf generation. | |
230 * | |
231 * @param pdfji | |
232 * @param filename | |
548 | 233 * @return |
234 * @throws FileNotFoundException | |
511 | 235 */ |
548 | 236 public Future<OutputStream> createNewPdfDocument(PDFJobDescription pdfji, String filename) throws FileNotFoundException{ |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
237 // start new worker |
548 | 238 File of = this.getTempFile(filename); |
239 OutputStream os = new FileOutputStream(of); | |
240 PDFStreamWorker job = new PDFStreamWorker(dlConfig, os, pdfji, pdfImageJobCenter); | |
241 // start job | |
242 Future<OutputStream> jobTicket = pdfJobCenter.submit(job); | |
243 // what do we do with the result? | |
244 return jobTicket; | |
245 /* PDFMaker pdf_maker = new PDFMaker(context, pdfji,filename); | |
246 new Thread(pdf_maker, "PDFMaker").start();*/ | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
247 } |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
248 |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
249 |
511 | 250 /** |
251 * generate the filename the user is going to receive the pdf as | |
252 * | |
253 * @param pdfji | |
254 * @return | |
255 */ | |
548 | 256 public String getDownloadFilename(PDFJobDescription pdfji){ |
511 | 257 // filename example: digilib_example_pgs1-3.pdf |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
258 String filename; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
259 filename = "digilib_"; |
552 | 260 filename += pdfji.getAsString("fn"); |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
261 filename += "_pgs" + pdfji.getAsString("pgs"); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
262 filename += ".pdf"; |
500 | 263 |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
264 return filename; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
265 } |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
266 |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
267 /** |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
268 * sends a document to the user |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
269 * |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
270 * @param cachefile The filename of the document in cache. |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
271 * @param filename The filename used for downloading. |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
272 * @param response |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
273 * @throws IOException |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
274 */ |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
275 public void sendFile(String cachefile, String filename, HttpServletResponse response) throws IOException{ |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
276 File cached_file = null; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
277 FileInputStream fis = null; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
278 ServletOutputStream sos = null; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
279 BufferedInputStream bis = null; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
280 |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
281 try { |
511 | 282 // get file handle |
533 | 283 cached_file = new File(cache_directory, cachefile); |
511 | 284 // create necessary streams |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
285 fis = new FileInputStream(cached_file); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
286 sos = response.getOutputStream(); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
287 bis = new BufferedInputStream(fis); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
288 |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
289 int bytes = 0; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
290 |
511 | 291 // set http headers |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
292 response.setContentType("application/pdf"); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
293 response.addHeader("Content-Disposition", "attachment; filename="+filename); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
294 response.setContentLength( (int) cached_file.length()); |
511 | 295 |
296 // send the bytes | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
297 while ((bytes = bis.read()) != -1){ |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
298 sos.write(bytes); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
299 } |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
300 } |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
301 catch(Exception e){ |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
302 logger.error(e.getMessage()); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
303 } |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
304 finally{ |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
305 // close all streams |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
306 if (fis != null) |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
307 fis.close(); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
308 if (bis != null) |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
309 bis.close(); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
310 if (sos != null) |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
311 sos.close(); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
312 } |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
500
diff
changeset
|
313 |
500 | 314 } |
509 | 315 |
533 | 316 public File getCacheDirectory(){ |
509 | 317 return cache_directory; |
318 } | |
319 | |
533 | 320 public File getTempDirectory(){ |
509 | 321 return temp_directory; |
322 } | |
533 | 323 |
324 /** | |
325 * returns a File object based on filename in the temp directory. | |
326 * @param filename | |
327 * @return | |
328 */ | |
329 public File getTempFile(String filename) { | |
330 return new File(temp_directory, filename); | |
331 } | |
332 | |
333 /** | |
334 * returns a File object based on filename in the cache directory. | |
335 * @param filename | |
336 * @return | |
337 */ | |
338 public File getCacheFile(String filename) { | |
339 return new File(cache_directory, filename); | |
340 } | |
500 | 341 } |