Mercurial > hg > digilib-old
comparison servlet/src/main/java/digilib/pdf/PDFFileWorker.java @ 892:ba1eb2d821a2 mvnify
rearrange sources to maven directory standard
| author | robcast |
|---|---|
| date | Tue, 19 Apr 2011 18:44:25 +0200 |
| parents | servlet/src/digilib/pdf/PDFFileWorker.java@72662bb585ba |
| children |
comparison
equal
deleted
inserted
replaced
| 891:6584af320296 | 892:ba1eb2d821a2 |
|---|---|
| 1 /** | |
| 2 * | |
| 3 */ | |
| 4 package digilib.pdf; | |
| 5 | |
| 6 import java.io.File; | |
| 7 import java.io.FileNotFoundException; | |
| 8 import java.io.FileOutputStream; | |
| 9 import java.io.OutputStream; | |
| 10 import java.util.concurrent.Callable; | |
| 11 | |
| 12 import digilib.image.DocuImage; | |
| 13 import digilib.servlet.DigilibConfiguration; | |
| 14 import digilib.servlet.PDFRequest; | |
| 15 import digilib.util.DigilibJobCenter; | |
| 16 | |
| 17 /** | |
| 18 * @author casties | |
| 19 * | |
| 20 */ | |
| 21 public class PDFFileWorker implements Callable<File> { | |
| 22 /** the wrapped PDFStreamWorker */ | |
| 23 protected PDFStreamWorker streamWorker; | |
| 24 | |
| 25 /** the temporary output file */ | |
| 26 protected File tempFile; | |
| 27 | |
| 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, | |
| 40 PDFRequest job_info, | |
| 41 DigilibJobCenter<DocuImage> imageJobCenter) throws FileNotFoundException { | |
| 42 this.tempFile = tempFile; | |
| 43 OutputStream outstream = new FileOutputStream(tempFile); | |
| 44 this.finalFile = finalFile; | |
| 45 this.streamWorker = new PDFStreamWorker(dlConfig, outstream, job_info, imageJobCenter); | |
| 46 } | |
| 47 | |
| 48 public File call() throws Exception { | |
| 49 OutputStream outstream = null; | |
| 50 try { | |
| 51 outstream = streamWorker.call(); | |
| 52 outstream.flush(); | |
| 53 outstream.close(); | |
| 54 // move temporary to final file | |
| 55 tempFile.renameTo(finalFile); | |
| 56 } finally { | |
| 57 if (outstream != null) { | |
| 58 outstream.close(); | |
| 59 } | |
| 60 } | |
| 61 return finalFile; | |
| 62 } | |
| 63 | |
| 64 | |
| 65 } |
