Integer transactionId = 0;
if ( lastLine != null & !lastLine.equals(""))
{
String[] chunks = lastLine.split(",");
if (chunks.length != 5) {
throw new DataAccessException(
new IOException("Line is invalid : " + lastLine));
}
transactionId = new Integer(chunks[0]);
}
// String[] chunks = lastLine.split(",");
transactionId = transactionId + 1;
String lineEnd = System.getProperty("line.separator");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
for (Tuple4<String, String, Integer, Date> purchasedProduct : purchases) {
BufferedWriter bw;
bw = new BufferedWriter(new FileWriter(datFile, true));
bw.write(String.format("%d,%s,%s,%d,%s%s",
transactionId,
purchasedProduct.getItem1(),
purchasedProduct.getItem2(),
purchasedProduct.getItem3(),
formatter.format(purchasedProduct.getItem4()), lineEnd));
bw.close();
}
} catch (IOException e) {
throw new DataAccessException(e);
} catch (Exception e) {
throw new DataAccessException(e);
}
}