Mercurial > hg > digilib-old
annotate servlet/src/digilib/pdf/PDFFileWorker.java @ 844:73dd59b48c5e stream
Merge from jquery branch
a7e157d258e86b9ba7470239f6b49d73ff200486
| author | robcast |
|---|---|
| date | Fri, 04 Mar 2011 17:49:15 +0100 |
| parents | 72662bb585ba |
| children |
| rev | line source |
|---|---|
| 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 { |
|
801
72662bb585ba
remove all ServletOutputStream.flush(). (stupid me ;-)
robcast
parents:
570
diff
changeset
|
49 OutputStream outstream = null; |
|
72662bb585ba
remove all ServletOutputStream.flush(). (stupid me ;-)
robcast
parents:
570
diff
changeset
|
50 try { |
|
72662bb585ba
remove all ServletOutputStream.flush(). (stupid me ;-)
robcast
parents:
570
diff
changeset
|
51 outstream = streamWorker.call(); |
|
72662bb585ba
remove all ServletOutputStream.flush(). (stupid me ;-)
robcast
parents:
570
diff
changeset
|
52 outstream.flush(); |
|
72662bb585ba
remove all ServletOutputStream.flush(). (stupid me ;-)
robcast
parents:
570
diff
changeset
|
53 outstream.close(); |
|
72662bb585ba
remove all ServletOutputStream.flush(). (stupid me ;-)
robcast
parents:
570
diff
changeset
|
54 // move temporary to final file |
|
72662bb585ba
remove all ServletOutputStream.flush(). (stupid me ;-)
robcast
parents:
570
diff
changeset
|
55 tempFile.renameTo(finalFile); |
|
72662bb585ba
remove all ServletOutputStream.flush(). (stupid me ;-)
robcast
parents:
570
diff
changeset
|
56 } finally { |
|
72662bb585ba
remove all ServletOutputStream.flush(). (stupid me ;-)
robcast
parents:
570
diff
changeset
|
57 if (outstream != null) { |
|
72662bb585ba
remove all ServletOutputStream.flush(). (stupid me ;-)
robcast
parents:
570
diff
changeset
|
58 outstream.close(); |
|
72662bb585ba
remove all ServletOutputStream.flush(). (stupid me ;-)
robcast
parents:
570
diff
changeset
|
59 } |
|
72662bb585ba
remove all ServletOutputStream.flush(). (stupid me ;-)
robcast
parents:
570
diff
changeset
|
60 } |
| 556 | 61 return finalFile; |
| 555 | 62 } |
| 63 | |
| 64 | |
| 65 } |
