All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opensearch.migrations.replay.ReplayUtils Maven / Gradle / Ivy

There is a newer version: 0.2.0.4
Show newest version
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()))
        );
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy