You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Kare Nuorteva <ka...@satama.com> on 2000/01/02 23:54:57 UTC

[PATCH] jakarta-tools/ant/src/main/org/apache/tools/ant/taskdefs/Get.java

Fixed some minor bugs and wrote some docs.

Index: Get.java
===================================================================
RCS file:
/home/cvspublic/jakarta-tools/ant/src/main/org/apache/tools/ant/taskdefs/Get.java,v
retrieving revision 1.4
diff -u -r1.4 Get.java
--- Get.java    1999/12/31 15:46:10     1.4
+++ Get.java    2000/01/02 22:51:20
@@ -54,35 +54,55 @@
 
 package org.apache.tools.ant.taskdefs;
 
-import org.apache.tools.ant.*;
-import java.io.*;
-import java.net.*;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.BuildException;
+import java.io.InputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.net.URL;
+import java.net.MalformedURLException;
+
 /**
  * Get a particular source. 
  *
  * @author costin@dnt.ro
  */
 public class Get extends Task {
-    String source; // required
-    String dest; // required
-    String verbose;
+    private String source; // required
+    private String dest; // required
+    private String verbose = "";
     
+
+    /**
+     * Does the work.
+     *
+     * @exception BuildException Thrown in unrecovrable error.
+     */
     public void execute() throws BuildException {
        try {
-           URL url=new URL( source );
+           URL url = null;
+           try {
+               url = new URL(source);
+           } catch (MalformedURLException e) {
+               throw new BuildException(e.toString());
+           }
+
            project.log("Getting: " + source);
+
            File destF=new File(dest);
            FileOutputStream fos = new FileOutputStream(destF);
 
-           InputStream is=url.openStream();
+           InputStream is = url.openStream();
            byte[] buffer = new byte[100 * 1024];
            int length;
            
            while ((length = is.read(buffer)) >= 0) {
                fos.write(buffer, 0, length);
-               if( "true".equals(verbose)) System.out.print(".");
+               if ("true".equals(verbose)) System.out.print(".");
            }
-           if( "true".equals(verbose)) System.out.println();
+           if ("true".equals(verbose)) System.out.println();
            fos.close();
            is.close();
        } catch (IOException ioe) {
@@ -91,15 +111,30 @@
        }
     }
 
+    /**
+     * Set the URL.
+     *
+     * @param d URL for the file.
+     */
     public void setSrc(String d) {
-       this.source=d;
+       this.source = d;
     }
 
+    /**
+     * Where to copy the source file.
+     *
+     * @param dest Path to file.
+     */
     public void setDest(String dest) {
        this.dest = dest;
     }
 
+    /**
+     * Be verbose, if set to "<CODE>true</CODE>".
+     *
+     * @param v if "true" then be verbose
+     */
     public void setVerbose(String v) {
-       verbose=v;
+       this.verbose = v;
     }
 }

cheers,
Kare 8^)

-- 
Kare Nuorteva, programmer
Satama Interactive, Henry Fordin katu 6 FIN-00150 HELSINKI
tel. +3589 680 51 396, GSM +35840 57 833 57
http://www.satama.com/ http://www.satama.de/