Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

21
LINES

< > BotCompany Repo | #1011611 // saveStreamToGZFile - with temp file & renaming

JavaX fragment (include)

static void saveStreamToGZFile(InputStream in, File file) ctex {
  File parentFile = file.getParentFile();
  if (parentFile != null)
    parentFile.mkdirs();
  String tempFileName = file.getPath() + "_temp";
  File tempFile = new File(tempFileName);
  if (tempFile.exists()) try {
    S saveName = tempFileName + ".saved." + now();
    copyFile(tempFile, new File(saveName));
  } catch (Throwable e) { printStackTrace(e); }
  
  FileOutputStream fileOutputStream = newFileOutputStream(tempFile.getPath());
  GZIPOutputStream gos = new GZIPOutputStream(fileOutputStream);
  copyStreamAndCloseAll(in, gos);

  if (file.exists() && !file.delete())
    fail("Can't delete " + file.getPath());

  if (!tempFile.renameTo(file))
    fail("Can't rename " + tempFile + " to " + file);
}

Author comment

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: 433 / 459
Version history: 5 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)