private static Key str2Key_impl ( String s ) { String key = s ; byte [ ] kb = new byte [ ( key . length ( ) - 1 ) / 2 ] ; int i = 0 , j = 0 ; if ( ( key . length ( ) > 2 ) && ( key . charAt ( 0 ) == ' ' ) && ( key . charAt ( 1 ) >= ' ' ) && ( key . charAt ( 1 ) <= ' ' ) ) { // Dehexalate until '%' for ( i = 1 ; i < key . length ( ) ; i += 2 ) { if ( key . charAt ( i ) == ' ' ) break ; char b0 = ( char ) ( key . charAt ( i ) - ' ' ) ; if ( b0 > 9 ) b0 += ' ' + 10 - ' ' ; char b1 = ( char ) ( key . charAt ( i + 1 ) - ' ' ) ; if ( b1 > 9 ) b1 += ' ' + 10 - ' ' ; kb [ j ++ ] = ( byte ) ( ( b0 << 4 ) | b1 ) ; // De-hexelated byte } i ++ ; // Skip the trailing '%' } // a normal key - ASCII with special characters encoded after % sign for ( ; i < key . length ( ) ; ++ i ) { byte b = ( byte ) key . charAt ( i ) ; if ( b == ' ' ) { switch ( key . charAt ( ++ i ) ) { case ' ' : b = ' ' ; break ; case ' ' : b = ' ' ; break ; case ' ' : b = ' ' ; break ; case ' ' : b = ' ' ; break ; case ' ' : b = ' ' ; break ; case ' ' : b = ' ' ; break ; case ' ' : b = ' ' ; break ; case ' ' : b = ' ' ; break ; case ' ' : b = ' ' ; break ; default : Log . warn ( "Invalid format of filename " + s + " at index " + i ) ; } } if ( j >= kb . length ) kb = Arrays . copyOf ( kb , Math . max ( 2 , j * 2 ) ) ; kb [ j ++ ] = b ; } // now in kb we have the key name return Key . make ( Arrays . copyOf ( kb , j ) ) ; }
Convert a filename string to a Key