com.github.isaichkindanila.g.net.client.util.DataIOUtils Maven / Gradle / Ivy
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;
}
}