ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Get.java
Date Mon, 29 Apr 2002 11:19:36 GMT
bodewig     02/04/29 04:19:35

  Modified:    src/main/org/apache/tools/ant/taskdefs Get.java
  Log:
  Make sure dest file is only created if URL can be opened
  
  PR: 8575
  
  and make sure the output file gets closed in case of an error, while
  we are at it.
  
  Revision  Changes    Path
  1.23      +17 -13    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Get.java
  
  Index: Get.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Get.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- Get.java	23 Apr 2002 08:35:05 -0000	1.22
  +++ Get.java	29 Apr 2002 11:19:35 -0000	1.23
  @@ -189,8 +189,6 @@
               //newer. Some protocols (FTP) dont include dates, of
               //course.
   
  -            FileOutputStream fos = new FileOutputStream(dest);
  -
               InputStream is = null;
               for (int i = 0; i < 3 ; i++) {
                   try {
  @@ -209,20 +207,26 @@
                                             location);
               }
   
  -            byte[] buffer = new byte[100 * 1024];
  -            int length;
  -
  -            while ((length = is.read(buffer)) >= 0) {
  -                fos.write(buffer, 0, length);
  +            FileOutputStream fos = new FileOutputStream(dest);
  +            try {
  +                byte[] buffer = new byte[100 * 1024];
  +                int length;
  +                
  +                while ((length = is.read(buffer)) >= 0) {
  +                    fos.write(buffer, 0, length);
  +                    if (verbose) {
  +                        System.out.print(".");
  +                    }
  +                }
                   if (verbose) {
  -                    System.out.print(".");
  +                    System.out.println();
                   }
  +            } finally {
  +                if (fos != null) {
  +                    fos.close();
  +                }
  +                is.close();
               }
  -            if (verbose) {
  -                System.out.println();
  -            }
  -            fos.close();
  -            is.close();
   
               //if (and only if) the use file time option is set, then
               //the saved file now has its timestamp set to that of the
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message