private int completeZNode()

in kyuubi-relocated-zookeeper-parent/kyuubi-relocated-zookeeper-34/src/main/java/org/apache/zookeeper/JLineZNodeCompleter.java [58:77]


  private int completeZNode(String buffer, String token, List<String> candidates) {
    String path = token;
    int idx = path.lastIndexOf("/") + 1;
    String prefix = path.substring(idx);
    try {
      // Only the root path can end in a /, so strip it off every other prefix
      String dir = idx == 1 ? "/" : path.substring(0, idx - 1);
      List<String> children = zk.getChildren(dir, false);
      for (String child : children) {
        if (child.startsWith(prefix)) {
          candidates.add(child);
        }
      }
    } catch (InterruptedException e) {
      return 0;
    } catch (KeeperException e) {
      return 0;
    }
    return candidates.size() == 0 ? buffer.length() : buffer.lastIndexOf("/") + 1;
  }