private void loadFile ( String resourcePath ) { InputStream stream = getClass ( ) . getResourceAsStream ( resourcePath ) ; if ( stream == null ) { throw new IllegalArgumentException ( resourcePath + " is missing" ) ; } BufferedReader lineReader = null ; try { lineReader = new BufferedReader ( new InputStreamReader ( new GZIPInputStream ( stream ) ) ) ; stream = null ; // skip the first line header lineReader . readLine ( ) ; while ( true ) { String line = lineReader . readLine ( ) ; if ( line == null ) { break ; } // parse the CSV file. The CSV file contains three elements per row String [ ] parsed = line . split ( "," ) ; if ( parsed . length < 3 ) { // ignore invalid entries continue ; } String name = parsed [ 0 ] ; String mimeType = parsed [ 1 ] ; if ( mimeType . isEmpty ( ) ) { continue ; } String reference = parsed [ 2 ] ; // fix problem in the CSV file provided by IANA such as G719,audio/G719,"[RFC5404][RFC Errata 3245]" if ( reference . startsWith ( "\"" ) ) { String nextLine = lineReader . readLine ( ) ; nextLine = nextLine . replaceAll ( "\\s+" , "" ) ; reference += nextLine ; } IanaEntry ianaEntry = new IanaEntry ( name , mimeType , parseReference ( reference ) ) ; entryMap . put ( mimeType , ianaEntry ) ; } } catch ( IOException ioe ) { throw new RuntimeException ( "Error when loading " + resourcePath , ioe ) ; } finally { closeQuietly ( lineReader ) ; closeQuietly ( stream ) ; } }
Loads the IANA database from the specified file .