// Choose between wbxml or zip (the smallest one) to be used; // adds 3 additional bytes with metadata and set binary data for the record // returns length for the application settings + 3 bytes public int setBlockApplicationsForOneRecord(Record record) throws Exception { String key = record.key; // String generalPath = Const.WORKING_DIR + Const.PATH_SEP + // key.replaceAll(":", "_"); String generalPath = Const.WORKING_DIR + Const.PATH_SEP + Util.generateFileNameFromKey(key); File w = new File(generalPath + ".wbxml"); if (!w.exists()) { throw new Exception("Error: The file " + generalPath + ".wbxml doesn't exist!"); } FileInputStream in; boolean usedZip; // Choose between wbxml or zip (the smallest one) to be used in case if USE_ZIP // has not been set to false in function main(). if (USE_ZIP) { // zip wbxml files File z = new File(generalPath + ".zip"); if (!z.exists()) { throw new Exception("Error: The file " + generalPath + ".zip doesn't exist!"); } FileInputStream inw = new FileInputStream(w); FileInputStream inz = new FileInputStream(z); usedZip = inz.available() < inw.available(); in = (usedZip) ? inz : inw; } else { // do not zip wbxml files usedZip = false; in = new FileInputStream(w); } byte[] appWbxmlSettings = new byte[in.available()]; in.read(appWbxmlSettings); in.close(); // get 3 bytes that provide info: for data length (23 bits) and compressed flag (1 bit) // and write it into metaInfo BlockTable metaInfo = new BlockTable((Const.APP_BLOCK_LENGTH + Const.APP_COMPRESSWD_FLAG) / 8); // 3 bytes int appBlockSettingsLength = metaInfo.data.length + appWbxmlSettings.length; int compressFlag = (usedZip) ? 1 : 0; Util.addBitsToTable(metaInfo, appBlockSettingsLength, Const.APP_BLOCK_LENGTH); Util.addBitsToTable(metaInfo, compressFlag, Const.APP_COMPRESSWD_FLAG); record.setBlockApplicationSettings(metaInfo.data, appWbxmlSettings); Validator.validateAppBlockSettingsLength(appBlockSettingsLength, generalPath); return appBlockSettingsLength; }
// ### ========== generate Header table ============ ########### public static void genenerateHeaderTable() throws Exception { int tableLengthBytes = (Const.HEAD_HEAD_SISE + Const.HEAD_OPERATOR_NAMES_TAB_SISE + Const.HEAD_CARRIER_INDEX_TAB_SISE + Const.HEAD_APP_SETTINGS_TAB_SIZE + Const.HEAD_DB_VERSION + 7) / 8; headerTable = new BlockTable(tableLengthBytes); // write header table Util.addBitsToTable(headerTable, tableLengthBytes, Const.HEAD_HEAD_SISE); Util.addBitsToTable( headerTable, operatorsNamesTable.length, Const.HEAD_OPERATOR_NAMES_TAB_SISE); Util.addBitsToTable(headerTable, carrierIndexTable.length, Const.HEAD_CARRIER_INDEX_TAB_SISE); Util.addBitsToTable( headerTable, applicationsSettingsTable.length, Const.HEAD_APP_SETTINGS_TAB_SIZE); Util.addBitsToTable(headerTable, Const.HEAD_DB_VERSION, Const.HEAD_DB_VERSION_TAB_SIZE); }
// generate carrier index table public static void genenerateCarrierIndexTable() throws Exception { // get size for all records and init carrierIndexTable int recordLengthBits = Const.MCC_BITS + Const.MNC_BITS + Const.OPERATOR_NAME_OFFSET_BITS + Const.ACC_TYPE_BITS + Const.APP_AVAIL_BITMAP_BITS + Const.APP_SETTINGS_OFFSET_BITS; int oneRecordLengthBytes = (recordLengthBits + 7) / 8; int tableLengthBytes = oneRecordLengthBytes * arraySortedRecords.length; carrierIndexTable = new BlockTable(tableLengthBytes); // write data from each record into arrier index table Record record; for (int i = 0; i < arraySortedRecords.length; i++) { record = arraySortedRecords[i]; int appAvailBitmap = 0; // set mask for available applications if (record.containsBrowser) { appAvailBitmap |= Const.BROWSER_MASK; } if (record.containsIM) { appAvailBitmap |= Const.IM_MASK; } if (record.containsJavaApp) { appAvailBitmap |= Const.JAVA_MASK; } if (record.containsMMS) { appAvailBitmap |= Const.MMS_MASK; } // find value for mnc length: if mns 3 digits it is 1, otherwise - it is 0 int mncLengthBitValue = (record.mncLen == 3) ? 1 : 0; Util.addBitsToTable(carrierIndexTable, record.mcc, Const.MCC_BITS); Util.addBitsToTable(carrierIndexTable, mncLengthBitValue, Const.MNC_LENGTH_BITS); Util.addBitsToTable(carrierIndexTable, record.mnc, Const.MNC_BITS); Util.addBitsToTable( carrierIndexTable, record.operator_name_offset, Const.OPERATOR_NAME_OFFSET_BITS); Util.addBitsToTable(carrierIndexTable, record.account_type, Const.ACC_TYPE_BITS); Util.addBitsToTable(carrierIndexTable, appAvailBitmap, Const.APP_AVAIL_BITMAP_BITS); Util.addBitsToTable( carrierIndexTable, record.application_settings_offset, Const.APP_SETTINGS_OFFSET_BITS); } }