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

com.github.isaichkindanila.g.net.client.util.DataIOUtils Maven / Gradle / Ivy

There is a newer version: 1.0.1
Show newest version
package com.github.isaichkindanila.g.net.client.util;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class DataIOUtils {
    private DataIOUtils() {
        throw new UnsupportedOperationException();
    }

    public static  List readList(DataInput input, DataInputReader reader) throws IOException {
        var size = input.readInt();
        if (size == 0) {
            // return empty list
            return List.of();
        }

        var result = new ArrayList(size);
        for (var i = 0; i < size; i++) {
            result.add(reader.read(input));
        }

        return result;
    }

    public static void writeVector(DataOutput output, Vector vector) throws IOException {
        output.writeDouble(vector.getX());
        output.writeDouble(vector.getY());
    }

    @FunctionalInterface
    public interface DataInputReader {
        T read(DataInput input) throws IOException;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy