public static String convertFileName(String name,int maxBytes){
  try {
    return convertFileName(name,maxBytes,Charset.defaultCharset());
  }
 catch (  CharacterCodingException cce) {
    try {
      return convertFileName(name,maxBytes,Charset.forName("UTF-8"));
    }
 catch (    CharacterCodingException e) {
      throw new RuntimeException("UTF-8 should have encoded: " + name,e);
    }
  }
}

public static String convertFileName ( String name , int maxBytes ) { try { return convertFileName ( name , maxBytes , Charset . defaultCharset ( ) ) ; } catch ( CharacterCodingException cce ) { try { return convertFileName ( name , maxBytes , Charset . forName ( "UTF-8" ) ) ; } catch ( CharacterCodingException e ) { throw new RuntimeException ( "UTF-8 should have encoded: " + name , e ) ; } } }
cleans up the filename from illegal characters and truncates it to the length of bytes specified .
