/** * This helper method reads and loads all the row data (records) from the .dbf into the mapTable * argument. Note that the dis argument must be ready to read at the start of the records section, * which is right after the fields section. * * @param dis Input stream reading from the .dbf file. * @param mapTable The dbf table being loaded. * @throws IOException Thrown when the stream fails. */ private void loadRecords(DataInputStream dis, DBFTable mapTable) throws IOException { // READ ALL ROW DATA for (int i = 0; i < mapTable.getNumberOfRecords(); i++) { // HERE'S THE RECORD WE ARE LOADING DBFRecord recordToAdd = new DBFRecord(mapTable.getNumFields()); // THERE IS A MYSTERY BYTE BEFORE EACH RECORD byte mystery = dis.readByte(); recordToAdd.setMystery(mystery); // LOAD DATA FOR EACH FIELD Iterator<DBFField> fieldsIt = mapTable.fieldsIterator(); int fieldsCounter = 0; while (fieldsIt.hasNext()) { // WHAT TYPE OF FIELD IS IT (character data, numbers, etc.)? DBFField field = fieldsIt.next(); // TEXT? if (field.getType() == DBFFieldType.C) { String text = ""; for (int counter = 0; counter < field.getLength(); counter++) { char c = (char) dis.readByte(); text += c; } text = text.trim(); recordToAdd.setData(text, fieldsCounter); } // IT MUST BE AN 'N' TYPE SINCE THOSE ARE THE ONLY TWO WE'RE USING else { String text = ""; for (int counter = 0; counter < field.getLength(); counter++) { char c = (char) dis.readByte(); text += c; } text = text.trim(); if (text.contains(".")) { double num = 0.0; num = Double.parseDouble(text); recordToAdd.setData(num, fieldsCounter); } else { long num = 0; if (text.length() > 0) num = Long.parseLong(text); recordToAdd.setData(num, fieldsCounter); } } fieldsCounter++; } // Comparable key = (Comparable)recordToAdd.getData(mapTable.getKeyIndex()); mapTable.addRecord(recordToAdd); } }