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

32
LINES

< > BotCompany Repo | #1001067 // appendToFile

JavaX fragment (include)

static Lock appendToFile_lock = lock();
sbool appendToFile_keepOpen;
static new HashMap<S, Writer> appendToFile_writers;

static void appendToFile(S path, S s) ctex {
  lock appendToFile_lock; // Let's just generally synchronize this to be safe.
  mkdirsForFile(new File(path));
  path = getCanonicalPath(path);
  Writer writer = appendToFile_writers.get(path);
  if (writer == null) {
    //print("[Logging to " + path + "]");
    writer = new BufferedWriter(new OutputStreamWriter(
      newFileOutputStream(path, true), "UTF-8"));
    if (appendToFile_keepOpen)
      appendToFile_writers.put(path, writer);
  }
  writer.write(s);
  if (!appendToFile_keepOpen)
    writer.close();
}
  
static void appendToFile(File path, String s) {
  if (path != null)
    appendToFile(path.getPath(), s);
}

svoid cleanMeUp_appendToFile {
  temp tempCleaningUp();
  lock appendToFile_lock;
  closeAllWriters(values(appendToFile_writers));
  appendToFile_writers.clear();
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1001067
Snippet name: appendToFile
Eternal ID of this version: #1001067/9
Text MD5: 5d5ef0e1745eacaa9e13a6ba191eceb5
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-12-02 16:51:24
Source code size: 992 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 814 / 2516
Version history: 8 change(s)
Referenced in: [show references]