public int scanBufrFile ( String filename , Counter total ) throws Exception { int count = 0 ; try ( RandomAccessFile raf = new RandomAccessFile ( filename , "r" ) ) { MessageScanner scan = new MessageScanner ( raf ) ; while ( scan . hasNext ( ) ) { Message m = scan . next ( ) ; if ( m == null ) continue ; try { if ( showMess ) out . format ( "%sMessage %d header=%s%n" , indent , count , m . getHeader ( ) ) ; count ++ ; Counter counter = new Counter ( ) ; processBufrMessageAsDataset ( scan , m , counter ) ; if ( showMess ) out . format ( "%scount=%d miss=%d%n" , indent , counter . nvals , counter . nmiss ) ; total . add ( counter ) ; } catch ( Exception e ) { System . out . printf ( " BARF:%s on %s%n" , e . getMessage ( ) , m . getHeader ( ) ) ; indent . setIndentLevel ( 0 ) ; } } } return count ; }
open the file and extract BUFR messages