view servlet/src/digilib/pdf/PDFFileWorker.java @ 570:fd2ef7e46119

more cleanup, set version to 1.8.2
author robcast
date Tue, 21 Dec 2010 20:24:09 +0100
parents 0885f5ca5b24
children 72662bb585ba
line wrap: on
line source

/**
 * 
 */
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);
    }
    
    public File call() throws Exception {
    	OutputStream outstream = streamWorker.call();
    	outstream.flush();
    	// move temporary to final file
    	tempFile.renameTo(finalFile);
        return finalFile;
    }
    
    
}