src/main/java/org/jboss/util/file/Files.java
/**
    * See encodeFileName(String) above.
    * 
    * @param name the filename to encode
    * @param escape the escape character to use
    * @return a filesystem-friendly filename
    */


@param name the filename to encode
@param escape the escape character to use
@return a filesystem-friendly filename
@param name the filename to encode @param escape the escape character to use @return a filesystem - friendly filename
public static String encodeFileName(String name, char escape)
   {
      StringBuffer rc = new StringBuffer();
      for (int i = 0; i < name.length(); i++ )
      {
         switch (name.charAt(i))
         {
            case 'a': case 'A': case 'b': case 'B': case 'c': case 'C':
            case 'd': case 'D': case 'e': case 'E': case 'f': case 'F':
            case 'g': case 'G': case 'h': case 'H': case 'i': case 'I':
            case 'j': case 'J': case 'k': case 'K': case 'l': case 'L':
            case 'm': case 'M': case 'n': case 'N': case 'o': case 'O':
            case 'p': case 'P': case 'q': case 'Q': case 'r': case 'R':
            case 's': case 'S': case 't': case 'T': case 'u': case 'U':
            case 'v': case 'V': case 'w': case 'W': case 'x': case 'X':
            case 'y': case 'Y': case 'z': case 'Z':
            case '1': case '2': case '3': case '4': case '5': 
            case '6': case '7': case '8': case '9': case '0': 
            case '-': case '_': case '.':
               rc.append(name.charAt(i));
               break;
            default:
               try
               {
                  byte data[] = ("" + name.charAt(i)).getBytes("UTF8");
                  for (int j = 0; j < data.length; j++)
                  {
                     rc.append(escape);
                     rc.append(hexDigits[ (data[j] >> 4) & 0xF ]); 
                     rc.append(hexDigits[ (data[j]     ) & 0xF ]); 
                  }
               }
               catch (UnsupportedEncodingException wonthappen)
               {
               }
         }
      }
      return rc.toString();
   }
public static String encodeFileName ( String name , char escape ) { StringBuffer rc = new StringBuffer ( ) ; for ( int i = 0 ; i < name . length ( ) ; i ++ ) { switch ( name . charAt ( i ) ) { case 'a' : case 'A' : case 'b' : case 'B' : case 'c' : case 'C' : case 'd' : case 'D' : case 'e' : case 'E' : case 'f' : case 'F' : case 'g' : case 'G' : case 'h' : case 'H' : case 'i' : case 'I' : case 'j' : case 'J' : case 'k' : case 'K' : case 'l' : case 'L' : case 'm' : case 'M' : case 'n' : case 'N' : case 'o' : case 'O' : case 'p' : case 'P' : case 'q' : case 'Q' : case 'r' : case 'R' : case 's' : case 'S' : case 't' : case 'T' : case 'u' : case 'U' : case 'v' : case 'V' : case 'w' : case 'W' : case 'x' : case 'X' : case 'y' : case 'Y' : case 'z' : case 'Z' : case '1' : case '2' : case '3' : case '4' : case '5' : case '6' : case '7' : case '8' : case '9' : case '0' : case '-' : case '_' : case '.' : rc . append ( name . charAt ( i ) ) ; break ; default : try { byte data [ ] = ( "" + name . charAt ( i ) ) . getBytes ( "UTF8" ) ; for ( int j = 0 ; j < data . length ; j ++ ) { rc . append ( escape ) ; rc . append ( hexDigits [ ( data [ j ] >> 4 ) & 0xF ] ) ; rc . append ( hexDigits [ ( data [ j ] ) & 0xF ] ) ; } } catch ( UnsupportedEncodingException wonthappen ) { } } } return rc . toString ( ) ; }
See encodeFileName(String) above.
See encodeFileName ( String ) above .
// These are the safe characters... // Any other character needs to be encoded. // We encode the characters as <esc>hh, // where <esc> is the passed escape character and // hh is the hex value of the UTF8 byte of the character. // You might get <esc>hh<esc>hh since UTF8 can produce multiple // bytes for a single character. // high order digit // low order digit                      // nada