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

60
LINES

< > BotCompany Repo | #1001043 // readLocally / readLocally2

JavaX fragment (include)

static void readLocally(S progID, S varNames) {
  readLocally2(mc(), progID, varNames);
}

static void readLocally(S varNames) {
  readLocally2(mc(), programID(), varNames);
}

static void readLocally2(O obj, S varNames) {
  readLocally2(obj, programID(), varNames);
}

static int readLocally_stringLength;

static new ThreadLocal<Bool> readLocally2_allDynamic;
static new ThreadLocal readLocally2_classFinder;

// read a string variable from standard storage
// does not overwrite variable contents if there is no file
static void readLocally2(O obj, S progID, S varNames) ctex {
  bool allDynamic = isTrue(getAndClearThreadLocal(readLocally2_allDynamic));
  for (S variableName : javaTokC(varNames)) {
    File textFile = new File(programDir(progID), variableName + ".text");
    
    S value = loadTextFile(textFile);
    if (value != null)
      set(main.class, variableName, value);
    else {
      File structureFile = new File(programDir(progID), variableName + ".structure");
      value = loadTextFile(structureFile);
      
      if (value == null) {
        File structureGZFile = new File(programDir(progID), variableName + ".structure.gz");
        if (!structureGZFile.isFile()) ret;
        //value = loadGZTextFile(structureGZFile);
        temp InputStream fis = new FileInputStream(structureGZFile);
        GZIPInputStream gis = newGZIPInputStream(fis);
        InputStreamReader reader = new InputStreamReader(gis, "UTF-8");
        BufferedReader bufferedReader = new BufferedReader(reader);
        //O o = unstructure_reader(bufferedReader);
        O o = unstructure_tok(javaTokC_noMLS_onReader(bufferedReader), allDynamic, readLocally2_classFinder!);
        readLocally_set(obj, variableName, o);
        ret;
      }
      
      readLocally_stringLength = l(value);
      if (nempty(value))
        readLocally_set(obj, variableName, unstructure(value, allDynamic, readLocally2_classFinder!));
    }
  }
}

static void readLocally_set(O c, S varName, O value) {
  O oldValue = get(c, varName);
  if (oldValue instanceof List && !(oldValue instanceof ArrayList) && value != null) {
    // Assume it's a synchroList.
    value = synchroList((L) value);
  }
  set(c, varName, value);
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1001043
Snippet name: readLocally / readLocally2
Eternal ID of this version: #1001043/6
Text MD5: d2ad8621336fa25777fe33ab29f44ba3
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-07-13 22:34:40
Source code size: 2272 bytes / 60 lines
Pitched / IR pitched: No / No
Views / Downloads: 827 / 2540
Version history: 5 change(s)
Referenced in: [show references]