TempFileManagerImpl.java
3.21 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
90
91
92
93
94
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aemds.bedrock.CoreConfigService
* com.adobe.aemds.bedrock.internal.Utilities
* com.adobe.service.ConnectionFactory
* com.adobe.service.DataManager
* com.adobe.service.DataManagerHelper
* com.adobe.service.InvalidSourceException
* org.apache.commons.io.FileUtils
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
*/
package com.adobe.aemfd.docmanager.impl;
import com.adobe.aemds.bedrock.CoreConfigService;
import com.adobe.aemds.bedrock.internal.Utilities;
import com.adobe.aemfd.docmanager.TempFileManager;
import com.adobe.service.ConnectionFactory;
import com.adobe.service.DataManager;
import com.adobe.service.DataManagerHelper;
import com.adobe.service.InvalidSourceException;
import java.io.File;
import java.io.IOException;
import javax.naming.NameNotFoundException;
import org.apache.commons.io.FileUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
@Component
@Service(value={TempFileManager.class})
public class TempFileManagerImpl
implements TempFileManager {
@Reference
private CoreConfigService coreConfigService;
private static final String TEMP_FILE_DIR_NAME = "tfmgr";
private static final String TEMP_FILE_NAME_PREFIX = "tfm";
private File tempDirectory;
public File getTempFile() throws IOException {
return this.getTempFile("tfm", null);
}
private synchronized void createTempDirectory() throws IOException {
if (this.tempDirectory == null) {
this.tempDirectory = new File(this.coreConfigService.getServerTempDir(), "tfmgr");
FileUtils.forceMkdir((File)this.tempDirectory);
}
}
public File getTempFile(String prefix, String suffix) throws IOException {
this.createTempDirectory();
return File.createTempFile(prefix, suffix, this.tempDirectory);
}
public DataManager getDataManager() {
ConnectionFactory cf;
try {
cf = Utilities.serviceLookup((String)"DataManagerService");
}
catch (NameNotFoundException e) {
throw new IllegalStateException("DataManager service not found in registry!", e);
}
return DataManagerHelper.narrow((Object)cf.getConnection());
}
public File getTransactionBoundTempFile() throws IOException {
DataManager dm = this.getDataManager();
String fp = dm.getTempFileName(true);
File res = new File(fp);
try {
dm.manageTempFile(fp);
}
catch (InvalidSourceException e) {
FileUtils.deleteQuietly((File)res);
throw new IOException("Error registering temp file for auto-cleanup", (Throwable)e);
}
return res;
}
protected void bindCoreConfigService(CoreConfigService coreConfigService) {
this.coreConfigService = coreConfigService;
}
protected void unbindCoreConfigService(CoreConfigService coreConfigService) {
if (this.coreConfigService == coreConfigService) {
this.coreConfigService = null;
}
}
}