int writeMode = getWriteMode();
Instances structure = getInstances();
PrintWriter outW = null;
if(getRetrieval() == BATCH || getRetrieval() == NONE)
throw new IOException("Batch and incremental saving cannot be mixed.");
if(getWriter() != null)
outW = new PrintWriter(getWriter());
if(writeMode == WAIT){
if(structure == null){
setWriteMode(CANCEL);
if(inst != null)
System.err.println("Structure(Header Information) has to be set in advance");
}
else
setWriteMode(STRUCTURE_READY);
writeMode = getWriteMode();
}
if(writeMode == CANCEL){
if(outW != null)
outW.close();
cancel();
}
if(writeMode == STRUCTURE_READY){
setWriteMode(WRITE);
//write header
if(retrieveFile() == null || outW == null){
// print out attribute names as first row
for (int i = 0; i < structure.numAttributes(); i++) {
System.out.print(structure.attribute(i).name());
if (i < structure.numAttributes()-1) {
System.out.print(m_FieldSeparator);
} else {
System.out.println();
}
}
}
else{
for (int i = 0; i < structure.numAttributes(); i++) {
outW.print(structure.attribute(i).name());
if (i < structure.numAttributes()-1) {
outW.print(m_FieldSeparator);
} else {
outW.println();
}
}
outW.flush();
}
writeMode = getWriteMode();
}
if(writeMode == WRITE){
if(structure == null)
throw new IOException("No instances information available.");
if(inst != null){
//write instance
if(retrieveFile() == null || outW == null)
System.out.println(inst);
else{