public void readEntries ( BufferedReader lineReader , ErrorCallBack errorCallBack ) throws IOException { final MagicEntry [ ] levelParents = new MagicEntry [ MAX_LEVELS ] ; MagicEntry previousEntry = null ; while ( true ) { String line = lineReader . readLine ( ) ; if ( line == null ) { break ; } // skip blanks and comments if ( line . length ( ) == 0 || line . charAt ( 0 ) == ' ' ) { continue ; } MagicEntry entry ; try { // we need the previous entry because of mime-type, etc. which augment the previous line entry = MagicEntryParser . parseLine ( previousEntry , line , errorCallBack ) ; if ( entry == null ) { continue ; } } catch ( IllegalArgumentException e ) { if ( errorCallBack != null ) { errorCallBack . error ( line , e . getMessage ( ) , e ) ; } continue ; } int level = entry . getLevel ( ) ; if ( previousEntry == null && level != 0 ) { if ( errorCallBack != null ) { errorCallBack . error ( line , "first entry of the file but the level " + level + " should be 0" , null ) ; } continue ; } if ( level == 0 ) { // top level entry entryList . add ( entry ) ; } else if ( levelParents [ level - 1 ] == null ) { if ( errorCallBack != null ) { errorCallBack . error ( line , "entry has level " + level + " but no parent entry with level " + ( level - 1 ) , null ) ; } continue ; } else { // we are a child of the one above us levelParents [ level - 1 ] . addChild ( entry ) ; } levelParents [ level ] = entry ; previousEntry = entry ; } }
Read the entries so later we can find matches with them .