You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2006/05/27 03:27:48 UTC

svn commit: r409789 - /incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/util/Util.java

Author: aadamchik
Date: Fri May 26 18:27:47 2006
New Revision: 409789

URL: http://svn.apache.org/viewvc?rev=409789&view=rev
Log:
CAY-525 - optimizing cloning method - it is used in a few palces internally

Modified:
    incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/util/Util.java

Modified: incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/util/Util.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/util/Util.java?rev=409789&r1=409788&r2=409789&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/util/Util.java (original)
+++ incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/util/Util.java Fri May 26 18:27:47 2006
@@ -335,16 +335,24 @@
      * Creates Serializable object copy using serialization/deserialization.
      */
     public static Object cloneViaSerialization(Serializable obj) throws Exception {
-        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+        ByteArrayOutputStream bytes = new ByteArrayOutputStream() {
+
+            public synchronized byte[] toByteArray() {
+                return buf;
+            }
+        };
+
         ObjectOutputStream out = new ObjectOutputStream(bytes);
         out.writeObject(obj);
         out.close();
 
-        byte[] data = bytes.toByteArray();
-
-        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data));
+        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes
+                .toByteArray()));
         Object objCopy = in.readObject();
-        in.close();
+
+        // no need to close the stream - we created it and now will be throwing away...
+        // in.close();
+        
         return objCopy;
     }
 
@@ -635,8 +643,10 @@
                 // try inner class often specified with "." instead of $
                 else {
                     int dot = className.lastIndexOf('.');
-                    if(dot > 0 && dot + 1 < className.length()) {
-                        className = className.substring(0, dot) + "$" + className.substring(dot + 1);
+                    if (dot > 0 && dot + 1 < className.length()) {
+                        className = className.substring(0, dot)
+                                + "$"
+                                + className.substring(dot + 1);
                         try {
                             return Class.forName(className, true, classLoader);
                         }