code: public String canonizeString(String file) {
          int i = 0;
          int lim = file.length();
  
          // Remove embedded /../
          while ((i = file.indexOf("/../")) >= 0) {
              if ((lim = file.lastIndexOf('/', i - 1)) >= 0) {
                  file = file.substring(0, lim) + file.substring(i + 3);
              } else {
                  file = file.substring(i + 3);
              }
          }
          // Remove embedded /./
          while ((i = file.indexOf("/./")) >= 0) {
              file = file.substring(0, i) + file.substring(i + 2);
          }
          // Remove trailing ..
          while (file.endsWith("/..")) {
              i = file.indexOf("/..");
              if ((lim = file.lastIndexOf('/', i - 1)) >= 0) {
                  file = file.substring(0, lim+1);
              } else {
                  file = file.substring(0, i);
              }
          }
          // Remove trailing .
          if (file.endsWith("/."))
              file = file.substring(0, file.length() -1);
  
          return file;
      }
docs: Returns a canonical version of the specified string.