* @param memberID
* @return Member records in form Array List.
* @throws AppException
*/
public Member readData(String memberID) throws AppException {
Member dataObject = null;
BufferedReader br = null;
try {
br = FileUtil.getBufferedReader(fileName);
if (br != null) {
String contents = FileUtil.getContents(br);
if (contents == null) {
return null;
}
String[] lines = StringUtil.parse(contents, format.getEndOfLineSymbols());
if (lines == null) {
throw new AppException("[MemberDA::readData]Record not found.", "[MemberDA::readData]", null);
} else {
if (lines.length < 1) {
throw new AppException("[MemberDA::readData]Record not found.", "[MemberDA::readData]", null);
}
for (int i = 0; i < lines.length; i++) {
String record = lines[i];
String[] fields = StringUtil.parse(record, String.valueOf((char) format.getDelimiterChar()));
if (fields == null) {
Logger.getLogger(MemberDA.class.getName()).log(Level.SEVERE, "[MemberDA::readData]Unable to read record no " + (String.valueOf(i + 1)));
throw new AppException("[MemberDA::readData]Unable to read record no " + (String.valueOf(i + 1)), "[MemberDA::writeData]", null);
} else {
if (fields.length != 3) {
Logger.getLogger(MemberDA.class.getName()).log(Level.SEVERE, "[MemberDA::readData]Record no " + (String.valueOf(i + 1)) + " is corrupted");
} else {
boolean recordValid = true;
//get all member value
String name = fields[0];
String code = fields[1];
int point = -1;
try {
point = Integer.parseInt(fields[2]);
} catch (NumberFormatException nfx) {
//cannot read point --> assume new member, point = -1
point = -1;
recordValid = false;
Logger.getLogger(MemberDA.class.getName()).log(Level.SEVERE, "" +
"[MemberDA::readData]Record no " + (String.valueOf(i + 1)) + "is corrupted.\n" +
"Field: MemberPoint\n" +
"Value: " + String.valueOf(point),
nfx);
//throw new AppException(nfx.getMessage(), nfx);
}
if (!recordValid) {
Logger.getLogger(MemberDA.class.getName()).log(Level.WARNING, "Some records are found invalid. Default value are assigned.");
}
//match
if (memberID.equalsIgnoreCase(code)) {
dataObject = new Member();
dataObject.setMemberID(code);
dataObject.setMemberName(name);
dataObject.setMemberPoint(point);
i = lines.length;
}
}
}
}