Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
BukkitObjectInputStream.java
1 package org.bukkit.util.io;
2 
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.io.ObjectInputStream;
6 
9 
10 /**
11  * This class is designed to be used in conjunction with the {@link
12  * ConfigurationSerializable} API. It translates objects back to their
13  * original implementation after being serialized by {@link
14  * BukkitObjectInputStream}.
15  * <p>
16  * Behavior of implementations extending this class is not guaranteed across
17  * future versions.
18  */
19 public class BukkitObjectInputStream extends ObjectInputStream {
20 
21  /**
22  * Constructor provided to mirror super functionality.
23  *
24  * @throws IOException
25  * @throws SecurityException
26  * @see ObjectInputStream#ObjectInputStream()
27  */
28  protected BukkitObjectInputStream() throws IOException, SecurityException {
29  super();
30  super.enableResolveObject(true);
31  }
32 
33  /**
34  * Object input stream decoration constructor.
35  *
36  * @param in
37  * @throws IOException
38  * @see ObjectInputStream#ObjectInputStream(InputStream)
39  */
40  public BukkitObjectInputStream(InputStream in) throws IOException {
41  super(in);
42  super.enableResolveObject(true);
43  }
44 
45  @Override
46  protected Object resolveObject(Object obj) throws IOException {
47  if (obj instanceof Wrapper) {
48  try {
49  (obj = ConfigurationSerialization.deserializeObject(((Wrapper<?>) obj).map)).getClass(); // NPE
50  } catch (Throwable ex) {
51  throw newIOException("Failed to deserialize object", ex);
52  }
53  }
54 
55  return super.resolveObject(obj);
56  }
57 
58  private static IOException newIOException(String string, Throwable cause) {
59  IOException exception = new IOException(string);
60  exception.initCause(cause);
61  return exception;
62  }
63 }
static ConfigurationSerializable deserializeObject(Map< String,?> args, Class<?extends ConfigurationSerializable > clazz)