Skip to content

Commit 316293f

Browse files
committed
Download to a temp file before copy over
CommonWealthRobotics/CaDoodle-Application#44
1 parent d224592 commit 316293f

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/main/java/com/neuronrobotics/bowlerstudio/scripting/DownloadManager.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -993,21 +993,26 @@ public void process(double percent) {
993993
}
994994
return exe;
995995
}
996-
private static void rawFileDownload(ProcessInputStream pis, File folder, File exe)
996+
private static void rawFileDownload(ProcessInputStream pis, File folder, File output)
997997
throws IOException, FileNotFoundException {
998998
folder.mkdirs();
999-
exe.createNewFile();
1000-
byte dataBuffer[] = new byte[1024*1000];
999+
output.createNewFile();
1000+
byte dataBuffer[] = new byte[1024 * 1000];
10011001
int bytesRead;
1002-
FileOutputStream fileOutputStream = new FileOutputStream(exe.getAbsoluteFile());
1003-
int chunks =0;
1004-
while ((bytesRead = pis.read(dataBuffer, 0, dataBuffer.length)) != -1) {
1005-
fileOutputStream.write(dataBuffer, 0, bytesRead);
1006-
//psudoSplash.onUpdate((int) (chunks++)+" Kb " +filename , null);
1002+
File exe = File.createTempFile("tmp", output.getName());
1003+
try {
1004+
FileOutputStream fileOutputStream = new FileOutputStream(exe.getAbsoluteFile());
10071005

1006+
while ((bytesRead = pis.read(dataBuffer, 0, dataBuffer.length)) != -1) {
1007+
fileOutputStream.write(dataBuffer, 0, bytesRead);
1008+
}
1009+
fileOutputStream.close();
1010+
pis.close();
1011+
Files.copy(exe.toPath(), new FileOutputStream(output.getAbsoluteFile()));
1012+
} catch (Exception ex) {
1013+
ex.printStackTrace();
10081014
}
1009-
fileOutputStream.close();
1010-
pis.close();
1015+
exe.delete();
10111016
}
10121017

10131018
/**

0 commit comments

Comments
 (0)