]> source.dussan.org Git - archiva.git/commitdiff
clean up, use IOUtil
authorBrett Porter <brett@apache.org>
Wed, 7 Jun 2006 04:38:04 +0000 (04:38 +0000)
committerBrett Porter <brett@apache.org>
Wed, 7 Jun 2006 04:38:04 +0000 (04:38 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@412289 13f79535-47bb-0310-9956-ffa450edef68

maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/EclipseRepositoryIndex.java

index e4ad5ab00b61c47c9ec0b1516b5ba71cacde5d2e..f96c3032eae4a84dade2d1ac2252765ee8214d15 100644 (file)
@@ -27,6 +27,7 @@ import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.repository.digest.Digester;
 import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -184,26 +185,7 @@ public class EclipseRepositoryIndex
         {
             for ( int i = 0; i < files.length; i++ )
             {
-                ZipEntry e = new ZipEntry( files[i].getName() );
-                zos.putNextEntry( e );
-
-                FileInputStream is = new FileInputStream( files[i] );
-                byte[] buf = new byte[4096];
-                int n;
-                try
-                {
-                    while ( ( n = is.read( buf ) ) > 0 )
-                    {
-                        zos.write( buf, 0, n );
-                    }
-                }
-                finally
-                {
-                    is.close();
-                }
-                zos.flush();
-
-                zos.closeEntry();
+                writeFile( zos, files[i] );
             }
         }
         finally
@@ -214,6 +196,26 @@ public class EclipseRepositoryIndex
         return outputFile;
     }
 
+    private static void writeFile( ZipOutputStream zos, File file )
+        throws IOException
+    {
+        ZipEntry e = new ZipEntry( file.getName() );
+        zos.putNextEntry( e );
+
+        FileInputStream is = new FileInputStream( file );
+        try
+        {
+            IOUtil.copy( is, zos );
+        }
+        finally
+        {
+            is.close();
+        }
+        zos.flush();
+
+        zos.closeEntry();
+    }
+
     /**
      * @see AbstractRepositoryIndex#deleteIfIndexed(Object)
      */
@@ -257,7 +259,7 @@ public class EclipseRepositoryIndex
     /**
      * Class used to analyze the lucene index
      */
-    private class EclipseIndexAnalyzer
+    private static class EclipseIndexAnalyzer
         extends Analyzer
     {
         private Analyzer defaultAnalyzer;
@@ -267,7 +269,7 @@ public class EclipseRepositoryIndex
          *
          * @param defaultAnalyzer the analyzer to use as default for the general fields of the artifact indeces
          */
-        public EclipseIndexAnalyzer( Analyzer defaultAnalyzer )
+        EclipseIndexAnalyzer( Analyzer defaultAnalyzer )
         {
             this.defaultAnalyzer = defaultAnalyzer;
         }
@@ -294,33 +296,33 @@ public class EclipseRepositoryIndex
 
             return tokenStream;
         }
+    }
 
+    /**
+     * Class used to tokenize the eclipse index
+     */
+    private static class EclipseIndexTokenizer
+        extends CharTokenizer
+    {
         /**
-         * Class used to tokenize the eclipse index
+         * Constructor with the required reader to the index stream
+         *
+         * @param reader the Reader object of the index stream
          */
-        private class EclipseIndexTokenizer
-            extends CharTokenizer
+        EclipseIndexTokenizer( Reader reader )
         {
-            /**
-             * Constructor with the required reader to the index stream
-             *
-             * @param reader the Reader object of the index stream
-             */
-            EclipseIndexTokenizer( Reader reader )
-            {
-                super( reader );
-            }
+            super( reader );
+        }
 
-            /**
-             * method that lucene calls to check tokenization of a stream character
-             *
-             * @param character char currently being processed
-             * @return true if the char is a token, false if the char is a stop char
-             */
-            protected boolean isTokenChar( char character )
-            {
-                return true;
-            }
+        /**
+         * method that lucene calls to check tokenization of a stream character
+         *
+         * @param character char currently being processed
+         * @return true if the char is a token, false if the char is a stop char
+         */
+        protected boolean isTokenChar( char character )
+        {
+            return true;
         }
     }
 }