public void close() {
int size=template.size();
for(int i=size-1;i>=chunkNumber;i--){
template.remove(i);//in case we did not fill all chunks, we remove the ones which were not filled with APDU data
}
IntelHexFileWriter writer=new IntelHexFileWriter();
writer.writeHexFile(ps, template);
ps.flush();
ps.close();
}