String fileName = getPlotFilename(townBlock);
int value;
if (isFile(fileName)) {
PlotBlockData plotBlockData = new PlotBlockData(townBlock);
List<Integer>IntArr = new ArrayList<Integer>();
try {
BufferedReader fin = new BufferedReader(new FileReader(fileName));
try {
//read the first 3 characters to test for version info
char[] key = new char[3];
fin.read(key,0,3);
String test = new String(key);
switch (elements.fromString(test)) {
case VER:
// Read the file version
int version = fin.read();
plotBlockData.setVersion(version);
// next entry is the plot height
plotBlockData.setHeight(fin.read());
break;
default:
/*
* no version field so set height
* and push rest to queue
*
*/
plotBlockData.setVersion(0);
// First entry is the plot height
plotBlockData.setHeight(key[0]);
IntArr.add((int) key[1]);
IntArr.add((int) key[2]);
}
// load remainder of file
while ((value = fin.read()) >= 0) {
IntArr.add(value);
}
} catch (IOException e) {
e.printStackTrace();
}
fin.close();
} catch (IOException e) {
e.printStackTrace();
}
plotBlockData.setBlockList(IntArr);
plotBlockData.resetBlockListRestored();
return plotBlockData;
}
return null;
}