Фиксы склейки

This commit is contained in:
serega6531
2019-11-25 21:33:40 +03:00
parent 90894d67cb
commit da66fb4a6a

View File

@@ -155,26 +155,28 @@ public class StreamService {
for (int i = 0; i < packets.size(); i++) { for (int i = 0; i < packets.size(); i++) {
Packet packet = packets.get(i); Packet packet = packets.get(i);
if (packet.isIncoming() != incoming || i == packets.size() - 1) { if (packet.isIncoming() != incoming) {
if (packetsInRow > 1) { if (packetsInRow > 1) {
final List<Packet> cut = packets.subList(start, i); final List<Packet> cut = packets.subList(start, i);
packets.removeAll(cut); final long timestamp = cut.get(0).getTimestamp();
final boolean ungzipped = cut.stream().anyMatch(Packet::isUngzipped);
//noinspection OptionalGetWithoutIsPresent //noinspection OptionalGetWithoutIsPresent
final byte[] content = cut.stream() final byte[] content = cut.stream()
.map(Packet::getContent) .map(Packet::getContent)
.reduce(ArrayUtils::addAll) .reduce(ArrayUtils::addAll)
.get(); .get();
packets.removeAll(cut);
packets.add(start, Packet.builder() packets.add(start, Packet.builder()
.incoming(incoming) .incoming(incoming)
.timestamp(packets.get(0).getTimestamp()) .timestamp(timestamp)
.ungzipped(cut.stream().anyMatch(Packet::isUngzipped)) .ungzipped(ungzipped)
.content(content) .content(content)
.build()); .build());
}
start++; i++;
i = start; }
start = i;
packetsInRow = 1; packetsInRow = 1;
} else { } else {
packetsInRow++; packetsInRow++;
@@ -182,6 +184,25 @@ public class StreamService {
incoming = packet.isIncoming(); incoming = packet.isIncoming();
} }
if (packetsInRow > 1) {
final List<Packet> cut = packets.subList(start, packets.size());
final long timestamp = cut.get(0).getTimestamp();
final boolean ungzipped = cut.stream().anyMatch(Packet::isUngzipped);
//noinspection OptionalGetWithoutIsPresent
final byte[] content = cut.stream()
.map(Packet::getContent)
.reduce(ArrayUtils::addAll)
.get();
packets.removeAll(cut);
packets.add(Packet.builder()
.incoming(incoming)
.timestamp(timestamp)
.ungzipped(ungzipped)
.content(content)
.build());
}
} }
private void unpackGzip(List<Packet> packets) { private void unpackGzip(List<Packet> packets) {