/** * Determines and returns (if possible) the structure (internally the * header) of the data set as an empty set of instances. * * @return the structure of the data set as an empty set * of Instances * @throws IOException if an error occurs */ public Instances getStructure() throws IOException { if (m_sourceReader == null) throw new IOException("No source has been specified"); if (m_structure == null) { try { m_JSON = JSONNode.read(m_sourceReader); m_structure = new Instances(JSONInstances.toHeader(m_JSON), 0); } catch (IOException ioe) { // just re-throw it throw ioe; } catch (Exception e) { throw new RuntimeException(e); } } return new Instances(m_structure, 0); }
/** * Writes a Batch of instances. * * @throws IOException throws IOException if saving in batch mode is not * possible */ @Override public void writeBatch() throws IOException { if (getInstances() == null) { throw new IOException("No instances to save"); } if (getRetrieval() == INCREMENTAL) { throw new IOException("Batch and incremental saving cannot be mixed."); } setRetrieval(BATCH); setWriteMode(WRITE); PrintWriter outW; if ((retrieveFile() == null) && (getWriter() == null)) { outW = new PrintWriter(System.out); } else { outW = new PrintWriter(getWriter()); } JSONNode json = JSONInstances.toJSON(getInstances()); StringBuffer buffer = new StringBuffer(); json.toString(buffer); outW.println(buffer.toString()); outW.flush(); if (getWriter() != null) { outW.close(); } setWriteMode(WAIT); outW = null; resetWriter(); setWriteMode(CANCEL); }
/** * Writes a Batch of instances. * * @throws IOException throws IOException if saving in batch mode * is not possible */ public void writeBatch() throws IOException { if (getInstances() == null) throw new IOException("No instances to save"); if (getRetrieval() == INCREMENTAL) throw new IOException("Batch and incremental saving cannot be mixed."); setRetrieval(BATCH); setWriteMode(WRITE); PrintWriter outW; if ((retrieveFile() == null) && (getWriter() == null)) outW = new PrintWriter(System.out); else outW = new PrintWriter(getWriter()); JSONNode json = JSONInstances.toJSON(getInstances()); StringBuffer buffer = new StringBuffer(); json.toString(buffer); outW.println(buffer.toString()); outW.flush(); if (getWriter() != null) outW.close(); setWriteMode(WAIT); outW = null; resetWriter(); setWriteMode(CANCEL); }