code: public static Path sanitizePath(Path path, String substitute) {
      return new Path(sanitizePath(path.toString(), substitute));
    }
docs: Remove illegal HDFS path characters from the given path. Illegal characters will be replaced
  with the given substitute.