Browse Source

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.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272588 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
df6e16ab5f
1 changed files with 17 additions and 13 deletions
  1. +17
    -13
      src/main/org/apache/tools/ant/taskdefs/Get.java

+ 17
- 13
src/main/org/apache/tools/ant/taskdefs/Get.java View File

@@ -189,8 +189,6 @@ public class Get extends Task {
//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 @@ public class Get extends Task {
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


Loading…
Cancel
Save