2025-11-24 22:52:51 +03:00

65 lines
2.0 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* com.google.gson.JsonElement
* com.google.gson.JsonParseException
* com.google.gson.JsonParser
* com.google.gson.Strictness
* com.google.gson.stream.JsonReader
* com.mojang.serialization.Codec
* com.mojang.serialization.DynamicOps
* com.mojang.serialization.JsonOps
* org.jspecify.annotations.Nullable
*/
package net.minecraft.util.eventlog;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import com.google.gson.Strictness;
import com.google.gson.stream.JsonReader;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.JsonOps;
import java.io.Closeable;
import java.io.EOFException;
import java.io.IOException;
import java.io.Reader;
import org.jspecify.annotations.Nullable;
public interface JsonEventLogReader<T>
extends Closeable {
public static <T> JsonEventLogReader<T> create(final Codec<T> codec, Reader reader) {
final JsonReader jsonReader = new JsonReader(reader);
jsonReader.setStrictness(Strictness.LENIENT);
return new JsonEventLogReader<T>(){
@Override
public @Nullable T next() throws IOException {
try {
if (!jsonReader.hasNext()) {
return null;
}
JsonElement json = JsonParser.parseReader((JsonReader)jsonReader);
return codec.parse((DynamicOps)JsonOps.INSTANCE, (Object)json).getOrThrow(IOException::new);
}
catch (JsonParseException e) {
throw new IOException(e);
}
catch (EOFException e) {
return null;
}
}
@Override
public void close() throws IOException {
jsonReader.close();
}
};
}
public @Nullable T next() throws IOException;
}