directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r552366 - /directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/ConnectionManager.java
Date Sun, 01 Jul 2007 21:57:46 GMT
Author: seelmann
Date: Sun Jul  1 14:57:45 2007
New Revision: 552366

URL: http://svn.apache.org/viewvc?view=rev&rev=552366
Log:
DIRSTUDIO-101: Flush file before copying it. Use temp file if real file is corrupt. 

Modified:
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/ConnectionManager.java

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/ConnectionManager.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/ConnectionManager.java?view=diff&rev=552366&r1=552365&r2=552366
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/ConnectionManager.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/ConnectionManager.java
Sun Jul  1 14:57:45 2007
@@ -543,8 +543,23 @@
         }
         catch ( Exception e )
         {
-            e.printStackTrace();
-            return null;
+            // if loading failed, try with temp file
+            String tempFilename = filename + "-temp";
+            try
+            {
+                XMLDecoder decoder = new XMLDecoder( new BufferedInputStream( ( new FileInputStream(
tempFilename ) ) ) );
+                Object object = decoder.readObject();
+                decoder.close();
+                return object;
+            }
+            catch ( IOException ioe2 )
+            {
+                return null;
+            }
+            catch ( Exception e2 )
+            {
+                return null;
+            }
         }
     }
 
@@ -574,6 +589,7 @@
                 }
             } );
             encoder.writeObject( object );
+            encoder.close();
             
             // move temp file to good file
             File file = new File( filename );



Mime
View raw message