@@ -62,19 +62,24 @@ class DataAccess {
6262 final byte [] bytes = outputStream .toByteArray ();
6363 assert total == bytes .length ;
6464
65- // read 8-byte header: SIGNATURE "MC", VERSION, NR TERRITORIES, NR RECTRANGLE RECORD
66- assert total > 8 ;
65+ // read SIGNATURE "MC", VERSION
66+ assert total > 12 ;
6767 assert (char ) bytes [0 ] == 'M' ;
6868 assert (char ) bytes [1 ] == 'C' ;
6969 final int dataVersion = (bytes [2 ] & 255 ) + ((bytes [3 ] & 255 ) << 8 );
70+ assert (dataVersion >= 220 );
71+ final int HEADER_SIZE = 8 ;
72+
73+ // read header: NR TERRITORIES, NR RECTRANGLE RECORD
7074 nrTerritoryRecords = (bytes [4 ] & 255 ) + ((bytes [5 ] & 255 ) << 8 );
7175 nrTerritories = (bytes [6 ] & 255 ) + ((bytes [7 ] & 255 ) << 8 );
7276 LOG .info ("version={} nrTerritories={} nrTerritoryRecords={}" ,dataVersion ,nrTerritories ,nrTerritoryRecords );
73- assert (8 + ((nrTerritories + 1 ) * 2 ) + (nrTerritoryRecords * 20 ) == total );
77+ final int expectedsize = HEADER_SIZE + ((nrTerritories + 1 ) * 2 ) + (nrTerritoryRecords * 20 );
78+ assert (expectedsize == total );
7479
7580 // read DATA+START array (2 bytes per territory, plus closing record)
7681 DATA_START = new int [nrTerritories + 1 ];
77- int i = 8 ;
82+ int i = HEADER_SIZE ;
7883 for (int k =0 ; k <= nrTerritories ; k ++) {
7984 DATA_START [k ] = (bytes [i ] & 255 ) + ((bytes [i + 1 ] & 255 ) << 8 );
8085 i += 2 ;
0 commit comments