FileContent.java
5.51 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.commons.io.FileUtils
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.replication.impl;
import com.day.cq.replication.ReplicationContentFacade;
import com.day.cq.replication.impl.AbstractReplicationContent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FileContent
extends AbstractReplicationContent {
private static final long serialVersionUID = 5152314972876828947L;
private static final Logger log = LoggerFactory.getLogger(FileContent.class);
public FileContent(ReplicationContentFacade facade) {
super(facade);
}
public FileContent(String filePath, String contentType, long size) {
super(filePath, contentType, size);
}
@Override
public long getLastModified() {
File f = new File(this.facade.getPath());
if (f.exists()) {
return f.lastModified();
}
return -1;
}
@Override
public InputStream getInputStream() throws IOException {
File file = new File(this.facade.getPath());
if (!file.canRead()) {
log.error("Unable to read replication content stored in {}.", (Object)this.facade.getPath());
return null;
}
return new FileInputStream(file);
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public void acquire(String agentName) {
Class class_ = this.getClass();
synchronized (class_) {
Status status = this.getStatus();
if (status == null) {
status = new Status();
}
if (status.agents.add(agentName)) {
this.writeStatus(status);
}
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public void release(String agentName) {
Class class_ = this.getClass();
synchronized (class_) {
Status status = this.getStatus();
if (status != null) {
if (status.agents.remove(agentName)) {
if (status.agents.isEmpty()) {
this.destroy();
} else {
this.writeStatus(status);
}
} else if (status.agents.isEmpty()) {
this.destroy();
}
} else {
this.destroy();
}
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public Collection<String> getAcquiredBy() {
Class class_ = this.getClass();
synchronized (class_) {
Status status = this.getStatus();
return status == null ? Collections.emptySet() : status.agents;
}
}
@Override
public void destroy() {
FileUtils.deleteQuietly((File)new File(this.facade.getPath()));
FileUtils.deleteQuietly((File)this.getStatusFile());
}
private File getStatusFile() {
return new File(this.facade.getPath() + ".status");
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private void writeStatus(Status status) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(this.getStatusFile());
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(status);
oos.close();
}
catch (IOException oos) {}
finally {
if (fos != null) {
try {
fos.close();
}
catch (IOException oos) {}
}
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
* Enabled aggressive block sorting
* Enabled unnecessary exception pruning
* Enabled aggressive exception aggregation
*/
private Status getStatus() {
FileInputStream fis = null;
try {
fis = new FileInputStream(this.getStatusFile());
ObjectInputStream ois = new ObjectInputStream(fis);
Status result = (Status)ois.readObject();
ois.close();
Status status = result;
return status;
}
catch (IOException ioe) {
Status result = null;
return result;
}
catch (ClassNotFoundException e) {
try {
Status result = null;
return result;
}
catch (Throwable var6_12) {}
throw var6_12;
finally {
if (fis != null) {
try {
fis.close();
}
catch (IOException var4_10) {}
}
}
}
}
private static final class Status
implements Serializable {
private static final long serialVersionUID = 8607944593208680928L;
public Set<String> agents = new HashSet<String>();
private Status() {
}
}
}