directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r487432 - in /directory/branches/trunks/schema/apacheds/bootstrap-partition/src: main/java/org/apache/directory/server/core/schema/bootstrap/partition/ test/java/org/apache/directory/server/core/schema/bootstrap/partition/
Date Fri, 15 Dec 2006 02:33:58 GMT
Author: akarasulu
Date: Thu Dec 14 18:33:57 2006
New Revision: 487432

URL: http://svn.apache.org/viewvc?view=rev&rev=487432
Log:
adding some formal error handling

Modified:
    directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/core/schema/bootstrap/partition/SchemaPartitionExtractor.java
    directory/branches/trunks/schema/apacheds/bootstrap-partition/src/test/java/org/apache/directory/server/core/schema/bootstrap/partition/SchemaPartitionExtractorTest.java

Modified: directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/core/schema/bootstrap/partition/SchemaPartitionExtractor.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/core/schema/bootstrap/partition/SchemaPartitionExtractor.java?view=diff&rev=487432&r1=487431&r2=487432
==============================================================================
--- directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/core/schema/bootstrap/partition/SchemaPartitionExtractor.java
(original)
+++ directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/core/schema/bootstrap/partition/SchemaPartitionExtractor.java
Thu Dec 14 18:33:57 2006
@@ -32,7 +32,7 @@
 
 
 /**
- * Document me!
+ * Dumps a schema partition onto disk from a jar.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
@@ -41,7 +41,17 @@
 {
     private static final String[] EMPTY = new String[0];
 
-    
+
+    /**
+     * Extracts the contents of a partition jar file into a destination 
+     * directory.
+     * 
+     * @param jarFile the jar file to extract the schema partition from
+     * @param destDir the destination directory to extract into: the destination 
+     *  directory will contain the schema directory
+     * @return the list of db files extracted 
+     * @throws IOException
+     */
     public static String[] extract( File jarFile, File destDir ) throws IOException
     {
         byte[] buf = new byte[512];
@@ -60,22 +70,40 @@
             System.out.println( "entry name = " + entry.getName() );
             if ( entry.getName().startsWith( "schema" ) )
             {
-                if ( entry.isDirectory() )
+                // we're only interested in db files
+                if ( entry.isDirectory() || ! entry.getName().endsWith( ".db" ) )
                 {
                     continue;
                 }
                 
                 File outFile = new File( destDir, entry.getName() );
-                FileOutputStream out = new FileOutputStream( outFile );
-                InputStream in = jar.getInputStream( entry );
-                while ( in.available() > 0 )
+                FileOutputStream out = null;
+                InputStream in = null;
+
+                try
+                {
+                    out = new FileOutputStream( outFile );
+                    in = jar.getInputStream( entry );
+                    while ( in.available() > 0 )
+                    {
+                        int readCount = in.read( buf );
+                        out.write( buf, 0, readCount );
+                    }
+                    out.flush();
+                    files.add( outFile.getAbsolutePath() );
+                }
+                finally
                 {
-                    int readCount = in.read( buf );
-                    out.write( buf, 0, readCount );
+                    if ( out != null )
+                    {
+                        out.close();
+                    }
+                    
+                    if ( in != null )
+                    {
+                        in.close();
+                    }
                 }
-                out.flush();
-                out.close();
-                in.close();
             }
         }
         

Modified: directory/branches/trunks/schema/apacheds/bootstrap-partition/src/test/java/org/apache/directory/server/core/schema/bootstrap/partition/SchemaPartitionExtractorTest.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/bootstrap-partition/src/test/java/org/apache/directory/server/core/schema/bootstrap/partition/SchemaPartitionExtractorTest.java?view=diff&rev=487432&r1=487431&r2=487432
==============================================================================
--- directory/branches/trunks/schema/apacheds/bootstrap-partition/src/test/java/org/apache/directory/server/core/schema/bootstrap/partition/SchemaPartitionExtractorTest.java
(original)
+++ directory/branches/trunks/schema/apacheds/bootstrap-partition/src/test/java/org/apache/directory/server/core/schema/bootstrap/partition/SchemaPartitionExtractorTest.java
Thu Dec 14 18:33:57 2006
@@ -37,6 +37,14 @@
     {
         String jarFilePath = System.getProperty( "jarFilePath" );
         String destDirPath = System.getProperty( "destDirPath" );
+        
         SchemaPartitionExtractor.extract( new File( jarFilePath ), new File( destDirPath
) );
+        
+//        String[] files = SchemaPartitionExtractor.extract( new File( jarFilePath ), new
File( destDirPath ) );
+//        
+//        for ( String file: files )
+//        {
+//            System.out.println( file );
+//        }
     }
 }



Mime
View raw message