code: private String translateWildcards(String input)
     {
        StringBuilder translated = new StringBuilder(input.length());
        boolean escaped = false;
        for (int i = 0; i < input.length(); i++)
        {
           if (input.charAt(i) == '\\')
           {
              if (escaped)
              {
                 translated.append("\\\\");
                 escaped = false;
              }
              else
              {
                 escaped = true;
              }
           }
           else if (input.charAt(i) == '*')
           {
              if (escaped)
              {
                 translated.append('*');
                 escaped = false;
              }
              else
              {
                 translated.append('%');
              }
           }
           else if (input.charAt(i) == '?')
           {
              if (escaped)
              {
                 translated.append('?');
                 escaped = false;
              }
              else
              {
                 translated.append('_');
              }
           }
           else if (input.charAt(i) == '%' || input.charAt(i) == '_')
           {
              // escape every occurrence of '%' and '_'
              escaped = false;
              translated.append('\\').append(input.charAt(i));
           }
           else
           {
              if (escaped)
              {
                 translated.append('\\');
                 escaped = false;
              }
              translated.append(input.charAt(i));
           }
        }
        return translated.toString();
     }
docs: Translates unescaped wildcards '*' and '?' into '%' and '_'.
  
  @param input the input String.
  @return the translated String.