1 | static void saveStreamToGZFile(InputStream in, File file) ctex { |
2 | File parentFile = file.getParentFile(); |
3 | if (parentFile != null) |
4 | parentFile.mkdirs(); |
5 | String tempFileName = file.getPath() + "_temp"; |
6 | File tempFile = new File(tempFileName); |
7 | if (tempFile.exists()) try { |
8 | S saveName = tempFileName + ".saved." + now(); |
9 | copyFile(tempFile, new File(saveName)); |
10 | } catch (Throwable e) { printStackTrace(e); } |
11 | |
12 | FileOutputStream fileOutputStream = newFileOutputStream(tempFile.getPath()); |
13 | GZIPOutputStream gos = new GZIPOutputStream(fileOutputStream); |
14 | copyStreamAndCloseAll(in, gos); |
15 | |
16 | if (file.exists() && !file.delete()) |
17 | fail("Can't delete " + file.getPath()); |
18 | |
19 | if (!tempFile.renameTo(file)) |
20 | fail("Can't rename " + tempFile + " to " + file); |
21 | } |
Began life as a copy of #1005539
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1011611 |
Snippet name: | saveStreamToGZFile - with temp file & renaming |
Eternal ID of this version: | #1011611/6 |
Text MD5: | 2fd9c6f3d4533507d5373db9802f81ba |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-11-01 01:54:14 |
Source code size: | 797 bytes / 21 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 434 / 460 |
Version history: | 5 change(s) |
Referenced in: | [show references] |