Problem
In my Java application I have the code
Paths.get(v_DirBufferdata).resolve(Paths.get(v_DirIndata).relativize(Paths.get(c_FileIndataLocation))).toString();
with
v_DirBufferdata being "file://workflow/../buffer/"
v_DirIndata being "/tmp/C4243/indata"
c_FileIndataLocation being "/tmp/C4243/indata/one_doc/pv.pdf"
and I would like to get
"file://workflow/../buffer/one_doc/pv.pdf".
however I am getting
"file:/workflow/../buffer/one_doc/pv.pdf".
Regex-Solution?
One simple idea to get the protocol-slash back is with regular expressions. However I want to make sure that only the protocol error is dealt with - not a folder called "file:" by any chance.
Specifically "file:/" should be replaced with "file://", but if "file://" is already there, I do not want to get "file:///". Also, "file:/" should only be replaced if it is at the beginning of the string. So far I've got:
"file:/".replaceFirst("^file:/[^/]", "file://")
Obviously this does not work yet. How do I do that?
Alternative solution
If there is a different solution, which does not require regex-hacking, I am all open for it too.
replaceFirst("^file:/(?!/)", "file://")will work.