Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
BukkitObjectOutputStream.java
1 package org.bukkit.util.io;
2 
3 import java.io.IOException;
4 import java.io.ObjectOutputStream;
5 import java.io.OutputStream;
6 import java.io.Serializable;
7 
9 
10 /**
11  * This class is designed to be used in conjunction with the {@link
12  * ConfigurationSerializable} API. It translates objects to an internal
13  * implementation for later deserialization using {@link
14  * BukkitObjectInputStream}.
15  * <p>
16  * Behavior of implementations extending this class is not guaranteed across
17  * future versions.
18  */
19 public class BukkitObjectOutputStream extends ObjectOutputStream {
20 
21  /**
22  * Constructor provided to mirror super functionality.
23  *
24  * @throws IOException
25  * @throws SecurityException
26  * @see ObjectOutputStream#ObjectOutputStream()
27  */
28  protected BukkitObjectOutputStream() throws IOException, SecurityException {
29  super();
30  super.enableReplaceObject(true);
31  }
32 
33  /**
34  * Object output stream decoration constructor.
35  *
36  * @param out
37  * @throws IOException
38  * @see ObjectOutputStream#ObjectOutputStream(OutputStream)
39  */
40  public BukkitObjectOutputStream(OutputStream out) throws IOException {
41  super(out);
42  super.enableReplaceObject(true);
43  }
44 
45  @Override
46  protected Object replaceObject(Object obj) throws IOException {
47  if (!(obj instanceof Serializable) && (obj instanceof ConfigurationSerializable)) {
48  obj = Wrapper.newWrapper((ConfigurationSerializable) obj);
49  }
50 
51  return super.replaceObject(obj);
52  }
53 }