pekko-connectors-sample-ftp-to-file/src/main/java/playground/filesystem/impl/JimfsView.java [153:250]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    private String getPhysicalName(final String file) {

        // get the starting directory
        String normalizedRootDir = normalizeSeparateChar(rootDir);
        if (normalizedRootDir.charAt(normalizedRootDir.length() - 1) != '/') {
            normalizedRootDir += '/';
        }

        String normalizedFileName = normalizeSeparateChar(file);
        String resArg;
        String normalizedCurrDir = currDir;
        if (normalizedFileName.charAt(0) != '/') {
            if (normalizedCurrDir == null || normalizedCurrDir.length() == 0) {
                normalizedCurrDir = "/";
            }

            normalizedCurrDir = normalizeSeparateChar(normalizedCurrDir);

            if (normalizedCurrDir.charAt(0) != '/') {
                normalizedCurrDir = '/' + normalizedCurrDir;
            }
            if (normalizedCurrDir.charAt(normalizedCurrDir.length() - 1) != '/') {
                normalizedCurrDir += '/';
            }

            resArg = normalizedRootDir + normalizedCurrDir.substring(1);
        } else {
            resArg = normalizedRootDir;
        }

        // strip last '/'
        if (resArg.charAt(resArg.length() - 1) == '/') {
            resArg = resArg.substring(0, resArg.length() - 1);
        }

        // replace ., ~ and ..
        // in this loop resArg will never end with '/'
        StringTokenizer st = new StringTokenizer(normalizedFileName, "/");
        while (st.hasMoreTokens()) {
            String tok = st.nextToken();

            // . => current directory
            if (tok.equals(".")) {
                continue;
            }

            // .. => parent directory (if not root)
            if (tok.equals("src/main")) {
                if (resArg.startsWith(normalizedRootDir)) {
                    int slashIndex = resArg.lastIndexOf("/");
                    if (slashIndex != -1) {
                        resArg = resArg.substring(0, slashIndex);
                    }
                }
                continue;
            }

            // ~ => home directory (in this case is the root directory)
            if (tok.equals("~")) {
                resArg = normalizedRootDir.substring(0, normalizedRootDir.length() - 1);
                continue;
            }

            if (caseInsensitive) {
                Path dir = fileSystem.getPath(resArg);
                DirectoryStream<Path> dirStream = null;
                try {
                    dirStream = Files.newDirectoryStream(dir, new NameEqualsPathFilter(tok, true));
                } catch (IOException t) {
                    // ignore
                }
                List<Path> matches = new ArrayList<>(0);
                if (dirStream != null) {
                    for (Path match : dirStream) {
                        matches.add(match);
                    }
                }
                if (matches.size() > 0) {
                    tok = matches.get(0).getFileName().toString();
                }
            }

            resArg = resArg + '/' + tok;
        }

        // add last slash if necessary
        if ((resArg.length()) + 1 == normalizedRootDir.length()) {
            resArg += '/';
        }

        // final check
        if (!resArg.regionMatches(0, normalizedRootDir, 0, normalizedRootDir
                .length())) {
            resArg = normalizedRootDir;
        }

        return resArg;
    }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



pekko-connectors-sample-rotate-logs-to-ftp/src/main/java/playground/filesystem/impl/JimfsView.java [151:248]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  private String getPhysicalName(final String file) {

    // get the starting directory
    String normalizedRootDir = normalizeSeparateChar(rootDir);
    if (normalizedRootDir.charAt(normalizedRootDir.length() - 1) != '/') {
      normalizedRootDir += '/';
    }

    String normalizedFileName = normalizeSeparateChar(file);
    String resArg;
    String normalizedCurrDir = currDir;
    if (normalizedFileName.charAt(0) != '/') {
      if (normalizedCurrDir == null || normalizedCurrDir.length() == 0) {
        normalizedCurrDir = "/";
      }

      normalizedCurrDir = normalizeSeparateChar(normalizedCurrDir);

      if (normalizedCurrDir.charAt(0) != '/') {
        normalizedCurrDir = '/' + normalizedCurrDir;
      }
      if (normalizedCurrDir.charAt(normalizedCurrDir.length() - 1) != '/') {
        normalizedCurrDir += '/';
      }

      resArg = normalizedRootDir + normalizedCurrDir.substring(1);
    } else {
      resArg = normalizedRootDir;
    }

    // strip last '/'
    if (resArg.charAt(resArg.length() - 1) == '/') {
      resArg = resArg.substring(0, resArg.length() - 1);
    }

    // replace ., ~ and ..
    // in this loop resArg will never end with '/'
    StringTokenizer st = new StringTokenizer(normalizedFileName, "/");
    while (st.hasMoreTokens()) {
      String tok = st.nextToken();

      // . => current directory
      if (tok.equals(".")) {
        continue;
      }

      // .. => parent directory (if not root)
      if (tok.equals("src/main")) {
        if (resArg.startsWith(normalizedRootDir)) {
          int slashIndex = resArg.lastIndexOf("/");
          if (slashIndex != -1) {
            resArg = resArg.substring(0, slashIndex);
          }
        }
        continue;
      }

      // ~ => home directory (in this case is the root directory)
      if (tok.equals("~")) {
        resArg = normalizedRootDir.substring(0, normalizedRootDir.length() - 1);
        continue;
      }

      if (caseInsensitive) {
        Path dir = fileSystem.getPath(resArg);
        DirectoryStream<Path> dirStream = null;
        try {
          dirStream = Files.newDirectoryStream(dir, new NameEqualsPathFilter(tok, true));
        } catch (IOException t) {
          // ignore
        }
        List<Path> matches = new ArrayList<>(0);
        if (dirStream != null) {
          for (Path match : dirStream) {
            matches.add(match);
          }
        }
        if (matches.size() > 0) {
          tok = matches.get(0).getFileName().toString();
        }
      }

      resArg = resArg + '/' + tok;
    }

    // add last slash if necessary
    if ((resArg.length()) + 1 == normalizedRootDir.length()) {
      resArg += '/';
    }

    // final check
    if (!resArg.regionMatches(0, normalizedRootDir, 0, normalizedRootDir
        .length())) {
      resArg = normalizedRootDir;
    }

    return resArg;
  }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



