PDFDocumentPassivationHandler.java
3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* 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;
}
}