Skip to content

Commit 5d2d990

Browse files
committed
Download files fully before write to disk
1 parent 49e11d1 commit 5d2d990

File tree

1 file changed

+4
-7
lines changed
  • frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib

1 file changed

+4
-7
lines changed

frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/FileDownloader.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package com.github.eirslett.maven.plugins.frontend.lib;
22

33
import java.io.File;
4-
import java.io.FileOutputStream;
54
import java.io.IOException;
65
import java.net.URI;
76
import java.net.URISyntaxException;
87
import java.net.URL;
9-
import java.nio.channels.Channels;
10-
import java.nio.channels.ReadableByteChannel;
118

9+
import org.apache.commons.io.IOUtils;
1210
import org.apache.commons.io.FileUtils;
1311
import org.apache.commons.io.FilenameUtils;
1412
import org.apache.http.HttpHost;
@@ -71,11 +69,10 @@ public void download(String downloadUrl, String destination, String userName, St
7169
if(statusCode != 200){
7270
throw new DownloadException("Got error code "+ statusCode +" from the server.");
7371
}
72+
73+
byte[] data = IOUtils.toByteArray(response.getEntity().getContent());
7474
new File(FilenameUtils.getFullPathNoEndSeparator(destination)).mkdirs();
75-
ReadableByteChannel rbc = Channels.newChannel(response.getEntity().getContent());
76-
FileOutputStream fos = new FileOutputStream(destination);
77-
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
78-
fos.close();
75+
FileUtils.writeByteArrayToFile(new File(destination), data);
7976
}
8077
} catch (IOException | URISyntaxException e) {
8178
throw new DownloadException("Could not download " + fixedDownloadUrl, e);

0 commit comments

Comments
 (0)