private static String guessMimeTypeFromUri ( final String uri ) { final int questionmark = uri . indexOf ( ' ' , 1 ) ; // 1 => skip the initial / final int end = ( questionmark > 0 ? questionmark : uri . length ( ) ) - 1 ; if ( end < 5 ) { // Need at least: "/a.js" return null ; } final char a = uri . charAt ( end - 3 ) ; final char b = uri . charAt ( end - 2 ) ; final char c = uri . charAt ( end - 1 ) ; switch ( uri . charAt ( end ) ) { case ' ' : return a == ' ' && b == ' ' && c == ' ' ? "image/png" : null ; case ' ' : return a == ' ' && b == ' ' && c == ' ' ? HTML_CONTENT_TYPE : null ; case ' ' : if ( a == ' ' && b == ' ' && c == ' ' ) { return "text/css" ; } else if ( b == ' ' && c == ' ' ) { return "text/javascript" ; } else { break ; } case ' ' : return a == ' ' && b == ' ' && c == ' ' ? "image/gif" : null ; case ' ' : return a == ' ' && b == ' ' && c == ' ' ? "image/x-icon" : null ; } return null ; }
Attempts to guess the MIME type by looking at the URI requested .