*
* @param memberID
* @return Member records in form Array List.
*/
public Member readData(String memberID) throws DataAccessException {
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 DataAccessException("[MemberDA::readData]Record not found.");
} else {
if (lines.length < 1) {
throw new DataAccessException("[MemberDA::readData]Record not found.");
}
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 DataAccessException("[MemberDA::readData]Unable to read record no " + (String.valueOf(i + 1)));
} else {
if (fields.length != 3) {
Logger.getLogger(MemberDA.class.getName()).log(Level.SEVERE, "[MemberDA::readData]Record no " + (String.valueOf(i + 1)) + " is corrupted");
} else {
//get all member value
String code = fields[0];
String name = fields[1];
int point = -1;
try {
point = Integer.parseInt(fields[2]);
} catch (NumberFormatException nfx) {
throw new DataAccessException(nfx.getMessage(), nfx);
}
//match
if (memberID.equalsIgnoreCase(code)) {
dataObject = new Member();
dataObject.setMemberID(code);
dataObject.setMemberName(name);
dataObject.setMemberPoint(point);
i = lines.length;
}
}
}
}