private static void loadMIMETypesFile ( String path ) { try { File f = new File ( path ) ; logger . debug ( "Attempting to load MIME types file \"" + path + "\"" ) ; if ( ! ( f . exists ( ) && f . isFile ( ) ) ) logger . debug ( "Regular file \"" + path + "\" does not exist." ) ; else { LineNumberReader r = new LineNumberReader ( new FileReader ( f ) ) ; String line ; while ( ( line = r . readLine ( ) ) != null ) { line = line . trim ( ) ; if ( ( line . length ( ) == 0 ) || ( line . startsWith ( "#" ) ) ) continue ; String [ ] fields = line . split ( " " ) ; // Skip lines without at least two tokens. if ( fields . length < 2 ) continue ; // Special case: Scan the extensions, and make sure we // have at least one valid extension. Some .mime.types // files have entries like this: // // mime/type desc="xxx" exts="jnlp" // // We don't handle those. List < String > extensions = new ArrayList < String > ( ) ; for ( int i = 1 ; i < fields . length ; i ++ ) { if ( fields [ i ] . indexOf ( ' ' ) != - 1 ) continue ; if ( fields [ i ] . indexOf ( ' ' ) != - 1 ) continue ; // Treat as valid. Remove any leading "." if ( fields [ i ] . startsWith ( "." ) ) { if ( fields [ i ] . length ( ) == 1 ) continue ; fields [ i ] = fields [ i ] . substring ( 1 ) ; } extensions . add ( fields [ i ] ) ; } if ( extensions . size ( ) == 0 ) continue ; // If the MIME type doesn't have a "/", skip it String mimeType = fields [ 0 ] ; String extension ; if ( mimeType . indexOf ( ' ' ) == - 1 ) continue ; // The first field is the preferred extension. Keep any // existing mapping for the MIME type. if ( mimeTypeToExtensionMap . get ( mimeType ) == null ) { extension = extensions . get ( 0 ) ; logger . debug ( "File \"" + path + "\": " + mimeType + " -> \"" + extension + "\"" ) ; mimeTypeToExtensionMap . put ( mimeType , extension ) ; } } r . close ( ) ; } } catch ( IOException ex ) { logger . debug ( "Error reading \"" + path + "\"" , ex ) ; } }
Attempt to load a MIME types file . Throws no exceptions .