Libraryless. Click here for Pure Java version (12572L/71K).
1 | static long saveGZStructureToFile(S file, O o) {
|
2 | ret saveGZStructureToFile(getProgramFile(file), o); |
3 | } |
4 | |
5 | // returns number of uncompressed bytes written |
6 | static long saveGZStructureToFile(File file, O o, structure_Data data default new) ctex {
|
7 | File parentFile = file.getParentFile(); |
8 | if (parentFile != null) |
9 | parentFile.mkdirs(); |
10 | File tempFile = tempFileFor(file); |
11 | if (tempFile.exists()) try {
|
12 | S saveName = tempFile.getPath() + ".saved." + now(); |
13 | copyFile(tempFile, new File(saveName)); |
14 | } catch (Throwable e) { printStackTrace(e); }
|
15 | |
16 | FileOutputStream fileOutputStream = newFileOutputStream(tempFile.getPath()); |
17 | CountingOutputStream cos; |
18 | try {
|
19 | GZIPOutputStream gos = new GZIPOutputStream(fileOutputStream); |
20 | cos = new CountingOutputStream(gos); |
21 | OutputStreamWriter outputStreamWriter = new OutputStreamWriter(cos, "UTF-8"); |
22 | PrintWriter printWriter = new PrintWriter(outputStreamWriter); |
23 | structureToPrintWriter(o, printWriter, data); |
24 | printWriter.close(); |
25 | gos.close(); |
26 | fileOutputStream.close(); |
27 | } catch e {
|
28 | fileOutputStream.close(); |
29 | tempFile.delete(); |
30 | throw rethrow(e); |
31 | } |
32 | |
33 | try {
|
34 | java.nio.file.Files.move(tempFile.toPath(), file.toPath(), |
35 | java.nio.file.StandardCopyOption.REPLACE_EXISTING, |
36 | java.nio.file.StandardCopyOption.ATOMIC_MOVE); |
37 | } catch (java.nio.file.AtomicMoveNotSupportedException e) {
|
38 | java.nio.file.Files.move(tempFile.toPath(), file.toPath(), |
39 | java.nio.file.StandardCopyOption.REPLACE_EXISTING); |
40 | } |
41 | |
42 | ret cos.getFilePointer(); |
43 | } |
Began life as a copy of #1005539
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
| Snippet ID: | #1005970 |
| Snippet name: | saveGZStructureToFile |
| Eternal ID of this version: | #1005970/9 |
| Text MD5: | 7d94a32a03b001af262652e63a84e994 |
| Transpilation MD5: | df74a35947534442b093c232e0d04b86 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2026-08-10 01:20:22 |
| Source code size: | 1593 bytes / 43 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 1156 / 1382 |
| Version history: | 8 change(s) |
| Referenced in: | [show references] |