* @param categoryCode
* @return Category records in form Array List.
* @throws AppException
*/
public Category readData(String categoryCode) throws AppException {
Category 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("Record not found.", "[CategoryDA::readData]", null);
} else {
if (lines.length < 1) {
throw new AppException("Record not found.", "[CategoryDA::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) {
throw new AppException("Unable to read record no " + (String.valueOf(i + 1)), "[CategoryDA::readData]", null);
} else {
if (fields.length != 2) {
Logger.getLogger(CategoryDA.class.getName()).log(Level.SEVERE, "[CategoryDA::readData]Record no " + (String.valueOf(i + 1)) + " is corrupted");
} else {
String catCode = fields[0];
String catName = fields[1];
if (catCode == null) {
catCode = "";
}
if (catName == null) {
catName = "";
}
if (categoryCode.equalsIgnoreCase(catCode)) {
dataObject = new Category();
dataObject.setCategoryCode(catCode);
dataObject.setCategoryName(catName);
i = lines.length;
}
}
}
}