org.opensearch.migrations.replay.ReplayUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of trafficReplayer Show documentation
Show all versions of trafficReplayer Show documentation
Everything opensearch migrations
package org.opensearch.migrations.replay;
import java.io.ByteArrayInputStream;
import java.io.SequenceInputStream;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import io.netty.buffer.ByteBuf;
public class ReplayUtils {
private ReplayUtils() {}
public static SequenceInputStream byteArraysToInputStream(List data) {
return byteArraysToInputStream(data.stream());
}
public static SequenceInputStream byteBufsToInputStream(Stream byteBufStream) {
return byteArraysToInputStream(byteBufStream.map(bb -> {
byte[] asBytes = new byte[bb.readableBytes()];
bb.duplicate().readBytes(asBytes);
return asBytes;
}));
}
public static SequenceInputStream byteArraysToInputStream(Stream data) {
return new SequenceInputStream(
Collections.enumeration(data.map(ByteArrayInputStream::new).collect(Collectors.toList()))
);
}
}