555
|
1 /**
|
|
2 *
|
|
3 */
|
557
|
4 package digilib.pdf;
|
555
|
5
|
|
6 import java.io.File;
|
556
|
7 import java.io.FileNotFoundException;
|
|
8 import java.io.FileOutputStream;
|
|
9 import java.io.OutputStream;
|
555
|
10 import java.util.concurrent.Callable;
|
|
11
|
556
|
12 import digilib.image.DocuImage;
|
557
|
13 import digilib.servlet.DigilibConfiguration;
|
|
14 import digilib.servlet.PDFRequest;
|
|
15 import digilib.util.DigilibJobCenter;
|
556
|
16
|
555
|
17 /**
|
|
18 * @author casties
|
|
19 *
|
|
20 */
|
|
21 public class PDFFileWorker implements Callable<File> {
|
556
|
22 /** the wrapped PDFStreamWorker */
|
555
|
23 protected PDFStreamWorker streamWorker;
|
556
|
24
|
|
25 /** the temporary output file */
|
|
26 protected File tempFile;
|
555
|
27
|
556
|
28 /** the final output file */
|
|
29 protected File finalFile;
|
|
30
|
|
31 /** Create new PDFFileWorker.
|
|
32 * @param dlConfig
|
|
33 * @param tempFile
|
|
34 * @param job_info
|
|
35 * @param imageJobCenter
|
|
36 * @throws FileNotFoundException
|
|
37 */
|
|
38 public PDFFileWorker(DigilibConfiguration dlConfig,
|
|
39 File tempFile, File finalFile,
|
557
|
40 PDFRequest job_info,
|
556
|
41 DigilibJobCenter<DocuImage> imageJobCenter) throws FileNotFoundException {
|
557
|
42 this.tempFile = tempFile;
|
556
|
43 OutputStream outstream = new FileOutputStream(tempFile);
|
|
44 this.finalFile = finalFile;
|
|
45 this.streamWorker = new PDFStreamWorker(dlConfig, outstream, job_info, imageJobCenter);
|
|
46 }
|
|
47
|
555
|
48 public File call() throws Exception {
|
556
|
49 OutputStream outstream = streamWorker.call();
|
|
50 outstream.flush();
|
|
51 // move temporary to final file
|
|
52 tempFile.renameTo(finalFile);
|
|
53 return finalFile;
|
555
|
54 }
|
|
55
|
|
56
|
|
57 }
|