PDFDocumentPassivationHandler.java 3.88 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.aemfd.docmanager.io.IOUtils
 *  com.adobe.aemfd.docmanager.passivation.AbstractPassivationHandler
 *  com.adobe.aemfd.docmanager.passivation.PassivationConnection
 *  com.adobe.aemfd.docmanager.passivation.PassivationType
 *  com.adobe.aemfd.docmanager.source.DocumentSourceHandler
 *  com.adobe.internal.io.ByteWriter
 *  com.adobe.internal.io.RandomAccessFileByteWriter
 *  com.adobe.internal.pdftoolkit.core.exceptions.PDFException
 *  com.adobe.internal.pdftoolkit.pdf.document.PDFDocument
 *  com.adobe.internal.pdftoolkit.pdf.document.PDFSaveOptions
 */
package com.adobe.aemfd.pdfdocmanager.internal.passivation;

import com.adobe.aemfd.docmanager.io.IOUtils;
import com.adobe.aemfd.docmanager.passivation.AbstractPassivationHandler;
import com.adobe.aemfd.docmanager.passivation.PassivationConnection;
import com.adobe.aemfd.docmanager.passivation.PassivationType;
import com.adobe.aemfd.docmanager.source.DocumentSourceHandler;
import com.adobe.aemfd.pdfdocmanager.internal.io.ManagedSharedFileBasedFilterByteWriter;
import com.adobe.aemfd.pdfdocmanager.internal.source.ManagedSharedFileSourceHandler;
import com.adobe.internal.io.ByteWriter;
import com.adobe.internal.io.RandomAccessFileByteWriter;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFException;
import com.adobe.internal.pdftoolkit.pdf.document.PDFDocument;
import com.adobe.internal.pdftoolkit.pdf.document.PDFSaveOptions;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.net.URLConnection;

public class PDFDocumentPassivationHandler
extends AbstractPassivationHandler {
    private PDFDocument pdfDoc;
    private PDFSaveOptions options;

    public PDFDocumentPassivationHandler(PDFDocument pdfDoc, PDFSaveOptions options) {
        super(false, true, false);
        this.pdfDoc = pdfDoc;
        this.options = options;
    }

    protected ManagedSharedFileBasedFilterByteWriter getPassivationSource() throws IOException {
        File f = IOUtils.createTempFile((String)".pdf");
        RandomAccessFile raf = new RandomAccessFile(f, "rw");
        RandomAccessFileByteWriter bw = new RandomAccessFileByteWriter(raf);
        ManagedSharedFileBasedFilterByteWriter mbw = new ManagedSharedFileBasedFilterByteWriter((ByteWriter)bw, f);
        try {
            this.pdfDoc.save((ByteWriter)mbw, this.options);
        }
        catch (PDFException e) {
            throw new IOException("Error saving PDF to file " + f.getPath(), (Throwable)e);
        }
        return mbw;
    }

    public PassivationConnection openConnectionForPassivation() throws IOException {
        ManagedSharedFileBasedFilterByteWriter bw = this.getPassivationSource();
        File f = bw.getSourceFile();
        FileInputStream fis = new FileInputStream(f);
        String ct = URLConnection.guessContentTypeFromName(f.getName());
        PassivationConnection pc = new PassivationConnection((InputStream)fis, f.length(), ct);
        pc.setPayload((Object)bw);
        return pc;
    }

    protected DocumentSourceHandler doPassivate(byte[] preBuffer, PassivationConnection conn, long length) throws IOException {
        ManagedSharedFileBasedFilterByteWriter bw = (ManagedSharedFileBasedFilterByteWriter)((Object)conn.getPayload());
        return new ManagedSharedFileSourceHandler(bw, conn.getContentType());
    }

    protected void doDispose(PassivationConnection conn, boolean passivated, PassivationType pType) {
        if (!passivated || pType.equals((Object)PassivationType.INLINED)) {
            ManagedSharedFileBasedFilterByteWriter bw = (ManagedSharedFileBasedFilterByteWriter)((Object)conn.getPayload());
            bw.dispose();
        }
    }

    public void release(boolean passivated, PassivationType pType) {
        this.pdfDoc = null;
        this.options = null;
    }
}