OSDN Git Service

Correct some note copy problems & add message auto-hide.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / Global.java
index ded5f8a..19d1a6b 100644 (file)
@@ -22,6 +22,11 @@ package cx.fbn.nevernote;
 \r
 //import java.io.ByteArrayOutputStream;\r
 \r
+import java.io.ByteArrayInputStream;\r
+import java.io.ByteArrayOutputStream;\r
+import java.io.IOException;\r
+import java.io.ObjectInputStream;\r
+import java.io.ObjectOutputStream;\r
 import java.io.PrintStream;\r
 import java.text.SimpleDateFormat;\r
 import java.util.ArrayList;\r
@@ -1566,6 +1571,40 @@ public class Global {
                settings.endGroup();    \r
     }\r
 \r
+    \r
+    \r
+    public static Object deepCopy(Object oldObj) \r
+    {\r
+       ObjectOutputStream oos = null;\r
+       ObjectInputStream ois = null;\r
+       try\r
+       {\r
+          ByteArrayOutputStream bos = \r
+                new ByteArrayOutputStream(); // A\r
+          oos = new ObjectOutputStream(bos); // B\r
+          // serialize and pass the object\r
+          oos.writeObject(oldObj);   // C\r
+          oos.flush();               // D\r
+          ByteArrayInputStream bin = \r
+                new ByteArrayInputStream(bos.toByteArray()); // E\r
+          ois = new ObjectInputStream(bin);                  // F\r
+          // return the new object\r
+          return ois.readObject(); // G\r
+       }\r
+       catch(Exception e)\r
+       {\r
+          Global.logger.log(logger.LOW, "Exception in ObjectCloner = " + e);\r
+       }\r
+          try {\r
+                       oos.close();\r
+               ois.close();\r
+               } catch (IOException e) {\r
+                       Global.logger.log(logger.LOW, "Exception in ObjectCloner = " + e);\r
+                       e.printStackTrace();\r
+               }\r
+\r
+               return null;\r
+    }\r
 \r
 }\r
 \r