java - Which is better way to create multiple directories in Azure file storage? -
i creating application need create 1 directory inside another. : directory1/directory2/directory3/directory4/directory5
here , directory5 in directory4 ,directory4 in directory 3 , on..
so, have 2 available options : 1) call rest api related 'create directory' in loop explained here :https://docs.microsoft.com/en-us/rest/api/storageservices/create-directory (i haven't code yet logic)
2) code in java applying loop create multiple directories required. code :
public jsonobject createdirectory(jsonobject jsoninput) throws ioexception, invalidkeyexception, urisyntaxexception { cloudfileclient fileclient = null; string storageconnectionstring = "defaultendpointsprotocol=https;accountname=" + jsoninput.get("accountname") + ";" + "accountkey=" + jsoninput.get("accountkey"); system.out.println(storageconnectionstring); cloudstorageaccount storageaccount = cloudstorageaccount.parse(storageconnectionstring); jsonobject jsonoutput = new jsonobject(); try { fileclient = storageaccount.createcloudfileclient(); string directoryname = jsoninput.get("directorystructure").tostring(); string[] directorynamearray = directoryname.split("\\s*/\\s*"); system.out.println(directorynamearray.length); cloudfileshare share = fileclient.getsharereference(directorynamearray[0].tolowercase() .replaceall("[-+.^:,!@#$%&*()_~`]", "").replaceall("\\s+", "")); if (share.createifnotexists()) { system.out.println("new container created named " + directorynamearray[0].tolowercase() .replaceall("[-+.^:,!@#$%&*()_~`]", "").replaceall("\\s+", "")); } cloudfiledirectory rootdir = share.getrootdirectoryreference(); (int = 0; < directorynamearray.length; i++) { string directorytocreate = directorynamearray[i]; cloudfiledirectory directory = rootdir.getdirectoryreference(directorytocreate); if (directory.createifnotexists()) { string token = testdirectorysas(share, rootdir); system.out.println("new directory created named " + directoryname); jsonoutput.put("token", token); jsonoutput.put("status", "successful"); } rootdir = directory; } if (jsonoutput.containskey("token")) { return jsonoutput; } else { jsonoutput.put("note", "same directory structure exist"); } } catch (exception e) { system.out.println("exception " + e.tostring()); jsonoutput.put("status", "unsuccessful"); jsonoutput.put("exception", e.tostring()); } return jsonoutput; }
which 1 more preferable way think , reason? should call rest api in loop or java code wrote ok? there time difference between execution of 2 methods?
Comments
Post a Comment