AbstractPassivationHandler.java
2.78 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemfd.docmanager.passivation;
import com.adobe.aemfd.docmanager.internal.persistence.PersistenceUtils;
import com.adobe.aemfd.docmanager.io.IOUtils;
import com.adobe.aemfd.docmanager.passivation.DocumentPassivationHandler;
import com.adobe.aemfd.docmanager.passivation.PassivationConnection;
import com.adobe.aemfd.docmanager.passivation.PassivationType;
import com.adobe.aemfd.docmanager.source.DocumentSourceHandler;
import java.io.IOException;
import java.io.InputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class AbstractPassivationHandler
implements DocumentPassivationHandler {
private static final Logger logger = LoggerFactory.getLogger(AbstractPassivationHandler.class);
private boolean persistOnPassivate;
private boolean closeStreamOnDispose;
private boolean computeUnknownLengthIfNonPersistent;
protected AbstractPassivationHandler(boolean persistOnPassivate, boolean closeStreamOnDispose, boolean computeUnknownLengthIfNonPersistent) {
this.persistOnPassivate = persistOnPassivate;
this.closeStreamOnDispose = closeStreamOnDispose;
this.computeUnknownLengthIfNonPersistent = computeUnknownLengthIfNonPersistent;
}
public void inlined() {
}
protected DocumentSourceHandler doPassivate(byte[] preBuffer, PassivationConnection conn, long length) throws IOException {
throw new UnsupportedOperationException("Sub-classes must implement doPassivate() for non-persistent scenarios!");
}
public DocumentSourceHandler handlePassivation(byte[] preBuffer, PassivationConnection conn) throws IOException {
if (this.persistOnPassivate) {
return PersistenceUtils.passivatePersistently(preBuffer, conn);
}
long pcl = conn.getLength();
if (pcl == -1 && this.computeUnknownLengthIfNonPersistent) {
int pbl = preBuffer == null ? 0 : preBuffer.length;
pcl = (long)pbl + IOUtils.length(conn.getContentStream());
}
return this.doPassivate(preBuffer, conn, pcl);
}
protected void doDispose(PassivationConnection conn, boolean passivated, PassivationType pType) {
}
public void dispose(PassivationConnection conn, boolean passivated, PassivationType pType) {
if (this.closeStreamOnDispose) {
try {
conn.getContentStream().close();
}
catch (IOException e) {
logger.warn("Failed to close input-stream of type " + conn.getContentStream().getClass().getName() + " while disposing document passivation handler.", (Throwable)e);
}
}
this.doDispose(conn, passivated, pType);
}
}