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

org.bukkit.util.io.BukkitObjectInputStream Maven / Gradle / Ivy

package org.bukkit.util.io;

import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.ConfigurationSerialization;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;

/**
 * This class is designed to be used in conjunction with the {@link
 * ConfigurationSerializable} API. It translates objects back to their
 * original implementation after being serialized by {@link
 * BukkitObjectInputStream}.
 * 

* Behavior of implementations extending this class is not guaranteed across * future versions. */ public class BukkitObjectInputStream extends ObjectInputStream { /** * Constructor provided to mirror super functionality. * * @throws IOException if an I/O error occurs while reading stream heade * @see ObjectInputStream#ObjectInputStream() */ protected BukkitObjectInputStream() throws IOException, SecurityException { super(); super.enableResolveObject(true); } /** * Object input stream decoration constructor. * * @param in the input stream to wrap * @throws IOException if an I/O error occurs while reading stream header * @see ObjectInputStream#ObjectInputStream(InputStream) */ public BukkitObjectInputStream(InputStream in) throws IOException { super(in); super.enableResolveObject(true); } private static IOException newIOException(String string, Throwable cause) { IOException exception = new IOException(string, cause); return exception; } @Override protected Object resolveObject(Object obj) throws IOException { if (obj instanceof Wrapper) { try { (obj = ConfigurationSerialization.deserializeObject(((Wrapper) obj).map)).getClass(); // NPE } catch (Throwable ex) { throw newIOException("Failed to deserialize object", ex); } } return super.resolveObject(obj); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy