dion        2004/01/07 23:03:49

  Modified:    src/java/org/apache/maven/repository Tag: MAVEN-1_0-BRANCH
                        AbstractArtifact.java
  Log:
  Code Cleanup:
  - Use plexus FileUtils for fileRead
  - rename parameters for usability
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.22.4.2  +13 -43    maven/src/java/org/apache/maven/repository/AbstractArtifact.java
  
  Index: AbstractArtifact.java
  ===================================================================
  RCS file: 
/home/cvs/maven/src/java/org/apache/maven/repository/AbstractArtifact.java,v
  retrieving revision 1.22.4.1
  retrieving revision 1.22.4.2
  diff -u -r1.22.4.1 -r1.22.4.2
  --- AbstractArtifact.java     8 Jan 2004 05:25:51 -0000       1.22.4.1
  +++ AbstractArtifact.java     8 Jan 2004 07:03:49 -0000       1.22.4.2
  @@ -56,17 +56,16 @@
    * ====================================================================
    */
   
  +import java.io.File;
  +
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.maven.MavenConstants;
   import org.apache.maven.MavenUtils;
  -import org.apache.maven.verifier.ChecksumVerificationException;
  -import org.apache.maven.util.MD5Sum;
   import org.apache.maven.project.Dependency;
  -
  -import java.io.File;
  -import java.io.IOException;
  -import java.io.FileInputStream;
  +import org.apache.maven.util.MD5Sum;
  +import org.apache.maven.verifier.ChecksumVerificationException;
  +import org.apache.plexus.util.FileUtils;
   
   /**
    * Base class from which all artifact subclasses are derived.
  @@ -81,7 +80,7 @@
       private Log log = LogFactory.getLog(AbstractArtifact.class);
   
       /** Platform specific file separator used for file system operations. */
  -    protected static final String ps = File.separator;
  +    protected static final String fs = File.separator;
   
       /** Dependency this artifact is based on. */
       private Dependency dependency;
  @@ -89,9 +88,6 @@
       /** Path to artifact. */
       private String path;
   
  -    /** buffer size for file reading */
  -    private static final int FILE_BUFFER_SIZE = 512;
  -
       /**
        * Default constructor.
        * @param dependency the dependency the artifact is based on
  @@ -114,9 +110,9 @@
       }
   
       /** @see Artifact#setPath */
  -    public void setPath( String path )
  +    public void setPath( String repositoryPath )
       {
  -        this.path = path;
  +        this.path = repositoryPath;
       }
   
       /** @see Artifact#getPath */
  @@ -133,9 +129,9 @@
       /** @see Artifact#generatePath */
       public String generatePath()
       {
  -        return ps + getDependency().getArtifactDirectory()
  -             + ps + getDependency().getType() + "s"
  -             + ps + getDependency().getArtifact();
  +        return fs + getDependency().getArtifactDirectory()
  +             + fs + getDependency().getType() + "s"
  +             + fs + getDependency().getArtifact();
       }
   
       /** @see Artifact#getUrlPath */
  @@ -210,7 +206,7 @@
               md5.setFile( getFile() );
               md5.execute();
   
  -            actualChecksum = fileRead( checksumFile );
  +            actualChecksum = FileUtils.fileRead( checksumFile.getCanonicalPath() );
               actualChecksum = actualChecksum.substring( 0, actualChecksum.length() - 
1 );
           }
           catch ( Exception e )
  @@ -226,31 +222,5 @@
               throw new ChecksumVerificationException(
                   MavenUtils.getMessage( "checksum.verification.error", getPath() ) );
           }
  -    }
  -
  -    /**
  -     * Reads the contents of a file.
  -     *
  -     * @param file The name of the file to read.
  -     * @return The file contents or null if read failed.
  -     * @throws IOException if there is an error reading the file
  -     */
  -    String fileRead( File file )
  -        throws IOException
  -    {
  -        StringBuffer buf = new StringBuffer();
  -
  -        FileInputStream in = new FileInputStream( file );
  -
  -        int count;
  -        byte[] b = new byte[FILE_BUFFER_SIZE];
  -        while ( ( count = in.read( b ) ) > 0 )  // blocking read
  -        {
  -            buf.append( new String( b, 0, count ) );
  -        }
  -
  -        in.close();
  -
  -        return buf.toString();
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to