ReplicationContentWrapper.java
5.13 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
/*
* Decompiled with CFR 0_118.
*/
package com.day.cq.replication.impl.queue;
import com.day.cq.replication.ReplicationAction;
import com.day.cq.replication.ReplicationActionType;
import com.day.cq.replication.ReplicationContent;
import com.day.cq.replication.ReplicationContentFacade;
import com.day.cq.replication.impl.queue.ReplicationQueueImpl;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.SequenceInputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Vector;
public class ReplicationContentWrapper
implements ReplicationContent {
public static final String BATCH_ACTION_PATH = "batch:";
private final List<Entry> entries;
private long contentLength;
private Vector<InputStream> streams;
public ReplicationContentWrapper(List<Entry> entries) {
this.entries = entries;
}
private void init() {
if (this.streams == null) {
Vector<InputStream> streamVector = new Vector<InputStream>();
long size = 0;
StringBuilder sb = new StringBuilder();
boolean first = true;
for (Entry entry : this.entries) {
if (entry.failed) continue;
boolean added = false;
try {
InputStream is = entry.content.getInputStream();
if (is != null) {
streamVector.add(this.getInputStream(entry.content.getContentLength()));
streamVector.add(is);
size += 8;
size += entry.content.getContentLength();
added = true;
}
}
catch (IOException is) {
// empty catch block
}
if (added) {
if (first) {
first = false;
} else {
sb.append(':');
}
sb.append(entry.path);
sb.append(':');
sb.append(entry.action);
continue;
}
entry.failed = true;
}
try {
byte[] batchPathsBytes = sb.toString().getBytes("UTF-8");
streamVector.add(0, new ByteArrayInputStream(batchPathsBytes));
streamVector.add(0, this.getInputStream(batchPathsBytes.length));
size += 8;
size += (long)batchPathsBytes.length;
}
catch (UnsupportedEncodingException batchPathsBytes) {
// empty catch block
}
this.streams = streamVector;
this.contentLength = size;
}
}
private InputStream getInputStream(long length) {
byte[] bytes = ByteBuffer.allocate(8).order(ByteOrder.BIG_ENDIAN).putLong(length).array();
return new ByteArrayInputStream(bytes);
}
@Override
public InputStream getInputStream() throws IOException {
this.init();
Vector<InputStream> streamVector = this.streams;
this.streams = null;
return new SequenceInputStream(streamVector.elements());
}
@Override
public String getContentType() {
return this.entries.get((int)0).content.getContentType();
}
@Override
public long getContentLength() {
this.init();
return this.contentLength;
}
@Override
public long getLastModified() {
return -1;
}
@Override
public void acquire(String agentName) {
for (Entry rc : this.entries) {
rc.content.acquire(agentName);
}
}
@Override
public void release(String agentName) {
for (Entry rc : this.entries) {
rc.content.release(agentName);
}
}
@Override
public Collection<String> getAcquiredBy() {
HashSet<String> result = new HashSet<String>();
for (Entry rc : this.entries) {
result.addAll(rc.content.getAcquiredBy());
}
return result;
}
@Override
public void destroy() {
for (Entry rc : this.entries) {
rc.content.destroy();
}
}
@Override
public ReplicationContentFacade getFacade() {
return null;
}
public static final class Entry {
public final String path;
public final String action;
public final ReplicationContent content;
public boolean failed = false;
public Entry(ReplicationQueueImpl.EntryData data, ReplicationContent content) {
String path = data.getAction().getPath();
try {
path = URLEncoder.encode(path, "UTF-8");
}
catch (UnsupportedEncodingException var4_4) {
// empty catch block
}
this.path = path;
this.action = data.getAction().getType().name();
this.content = content;
}
}
}