* @param memberID
* @return
* @throws sg.edu.nus.iss.se07.common.exceptions.AppException
*/
public MemberSet readDataSet(String memberID) throws AppException {
MemberSet dataObjectSet = 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) {
Logger.getLogger(MemberDA.class.getName()).log(Level.SEVERE, "[MemberDA::readDataSet]Record not found.");
throw new IOException("[MemberDA::readDataSet]Record not found.");
} else {
if (lines.length < 1) {
Logger.getLogger(MemberDA.class.getName()).log(Level.SEVERE, "[MemberDA::readDataSet]Record not found.");
throw new IOException("[MemberDA::readDataSet]Record not found.");
}
dataObjectSet = new MemberSet();
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::readDataSet]Unable to read record no " + (String.valueOf(i + 1)));
throw new IOException("[MemberDA::readDataSet]Unable to read record no " + (String.valueOf(i + 1)));
} else {
if (fields.length != 3) {
Logger.getLogger(MemberDA.class.getName()).log(Level.SEVERE, "[MemberDA::readDataSet]Record no " + (String.valueOf(i + 1)) + " is corrupted");
//throw new IOException("[MemberDA::readDataSet]Record no " + (String.valueOf(i + 1)) + " is corrupted");
} else {
String code = fields[0];
String name = fields[1];
if (memberID.equalsIgnoreCase(code)) {
Member member = new Member();
member.setMemberID(fields[0]);
member.setMemberName(fields[1]);
member.setMemberPoint(Integer.parseInt(fields[2]));
dataObjectSet.add(member);
member = null;
i = lines.length;
}
}
}