question: public void test_vmstat_header_and_data_parse ( ) { final Pattern pattern = VMStatCollector . pattern ; final String header = "  r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st" ; final String data = "  1  0     96 178580 206520 1170604   56   12     0     7    1    0  1  0 99  3  0" ; { final String [ ] fields = pattern . split ( header . trim ( ) , 0 ) ; for ( int i = 0 ; i < fields . length ; i ++ ) { if ( log . isInfoEnabled ( ) ) log . info ( "fields[" + i + "]=[" + fields [ i ] + "]" ) ; } assertField ( header , fields , 2 , "swpd" ) ; assertField ( header , fields , 3 , "free" ) ; assertField ( header , fields , 6 , "si" ) ; assertField ( header , fields , 7 , "so" ) ; assertField ( header , fields , 12 , "us" ) ; assertField ( header , fields , 13 , "sy" ) ; assertField ( header , fields , 14 , "id" ) ; assertField ( header , fields , 15 , "wa" ) ; } { final String [ ] fields = pattern . split ( data . trim ( ) , 0 ) ; assertField ( data , fields , 2 , "96" ) ; assertField ( data , fields , 3 , "178580" ) ; assertField ( data , fields , 6 , "56" ) ; assertField ( data , fields , 7 , "12" ) ; assertField ( data , fields , 12 , "1" ) ; assertField ( data , fields , 13 , "0" ) ; assertField ( data , fields , 14 , "99" ) ; assertField ( data , fields , 15 , "3" ) ; } }
target:  Test based on some sample data.