Mercurial > hg > digilib-old
diff servlet/src/digilib/pdf/PDFFileWorker.java @ 557:0885f5ca5b24 digilibPDF
more refactoring and rearranging
pdf and image generation works now
author | robcast |
---|---|
date | Thu, 16 Dec 2010 21:19:11 +0100 |
parents | servlet/src/digilib/servlet/PDFFileWorker.java@5cc180bb0a5c |
children | fd2ef7e46119 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/servlet/src/digilib/pdf/PDFFileWorker.java Thu Dec 16 21:19:11 2010 +0100 @@ -0,0 +1,58 @@ +/** + * + */ +package digilib.pdf; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.util.concurrent.Callable; + +import digilib.image.DocuImage; +import digilib.servlet.DigilibConfiguration; +import digilib.servlet.PDFRequest; +import digilib.util.DigilibJobCenter; + +/** + * @author casties + * + */ +public class PDFFileWorker implements Callable<File> { + /** the wrapped PDFStreamWorker */ + protected PDFStreamWorker streamWorker; + + /** the temporary output file */ + protected File tempFile; + + /** the final output file */ + protected File finalFile; + + /** Create new PDFFileWorker. + * @param dlConfig + * @param tempFile + * @param job_info + * @param imageJobCenter + * @throws FileNotFoundException + */ + public PDFFileWorker(DigilibConfiguration dlConfig, + File tempFile, File finalFile, + PDFRequest job_info, + DigilibJobCenter<DocuImage> imageJobCenter) throws FileNotFoundException { + this.tempFile = tempFile; + OutputStream outstream = new FileOutputStream(tempFile); + this.finalFile = finalFile; + this.streamWorker = new PDFStreamWorker(dlConfig, outstream, job_info, imageJobCenter); + } + + @Override + public File call() throws Exception { + OutputStream outstream = streamWorker.call(); + outstream.flush(); + // move temporary to final file + tempFile.renameTo(finalFile); + return finalFile; + } + + +}