public static String escapePathName(String path, String defaultPath) {

    // __HIVE_DEFAULT_NULL__ is the system default value for null and empty string.
    // TODO: we should allow user to specify default partition or HDFS file location.
    if (path == null || path.length() == 0) {
      if (defaultPath == null) {
        //previously, when path is empty or null and no default path is specified,
        // __HIVE_DEFAULT_PARTITION__ was the return value for escapePathName
        return "__HIVE_DEFAULT_PARTITION__";
      } else {
        return defaultPath;
      }
    }

    //  Fast-path detection, no escaping and therefore no copying necessary
    int firstEscapeIndex = -1;
    for (int i = 0; i < path.length(); i++) {
      if (needsEscaping(path.charAt(i))) {
        firstEscapeIndex = i;
        break;
      }
    }
    if (firstEscapeIndex == -1) {
      return path;
    }

    // slow path, escape beyond the first required escape character into a new string
    StringBuilder sb = new StringBuilder();
    if (firstEscapeIndex > 0) {
      sb.append(path, 0, firstEscapeIndex);
    }

    for (int i = firstEscapeIndex; i < path.length(); i++) {
      char c = path.charAt(i);
      if (needsEscaping(c)) {
        sb.append('%').append(HEX_UPPER_CHARS[(0xF0 & c) >>> 4]).append(HEX_UPPER_CHARS[(0x0F & c)]);
      } else {
        sb.append(c);
      }
    }
    return sb.toString();
  }
Escapes a path name.
@param path The path to escape.
@param defaultPath
         The default name for the path, if the given path is empty or null.
@return An escaped path name.
common/src/java/org/apache/hadoop/hive/common/FileUtils.java