uniqueidentifier - Creating a unique filename from a list of alphanumeric strings -
i apologize creating similar thread many out there now, wanted insight on methods.
i have list of strings (could 1 or on 1000) format = xxx-xxxxx-xx each 1 alphanumeric
i trying generate unique string (currently 18 in length longer ensuring not maximize file length or path length) reproduce if have same list. order doesn't matter; although may interested if easier restrict order well.
my current java code follows (which failed today, hence why here):
public string createoutputfilename(arraylist alinput, enumfpfunction efpf, boolean pheaders) { /* create file name based on input list */ string sfilename = ""; long partnum = 0; (string sgpn : alinput) { sgpn = sgpn.replaceall("-", ""); //remove dashes partnum += long.parselong(sgpn, 36); //(base 36) } sfilename = long.tostring(partnum); if (sfilename.length() > 19) { sfilename.substring(0, 18); //max length of 19 } return alinput; }
so adding them did not work out found out (also think should take last 18 digits , not first 18)
are there methods out there (possibly crc related) work?
to assist key creation: first 3 characters numeric , have many duplicate (out of 100, there may 10 different starting numbers) these characters not allowed - i,o there never character number in last 2 alphachar subset.
i use system time. here's how might in java:
public string createoutputfilename() { long mills = system.currenttimemillis(); long nanos = system.nanotime(); return mills + " " + nanos; }
if want add information items , part numbers, can, of course!
======== edit: "what mean batch object" =========
class batch { arraylist<item> itemstoprocess; string inputfilename; // input external process boolean processingfinished; public batch(arraylist<item> itemstoprocess) { this.itemstoprocess = itemstoprocess; inputfilename = null; processingfinished = false; } public void processwithexternal() { if(inputfilename != null || processingfinished) { throw new illegalstateexception("cannot initiate process more once!"); } string base = system.currenttimemillis() + " " + system.nanotime(); this.inputfilename = base + "_input"; writeitemstofile(); // build process, here process p = new processbuilder("myprocess","myargs", inputfilename); p.start(); p.waitfor(); processingfinished = true; } private void writeitemstofile() { printwriter out = new printwriter(new bufferedwriter(new filewriter(inputfilename))); int flushcount = 0; for(item item : itemstoprocess) { string output = item.getfilerepresentation(); out.println(output); if(++flushcount % 10 == 0) out.flush(); } out.flush(); out.close(); } }
Comments
Post a Comment