/** * Main method. * * @param args should contain the name of an input file. */ public static void main(String[] args) { runFileLoader(new JSONLoader(), args); } }
/** * Resets the Loader ready to read a new data set. * * @throws IOException if something goes wrong */ public void reset() throws IOException { m_structure = null; m_JSON = null; setRetrieval(NONE); if (m_File != null) { setFile(new File(m_File)); } else if ((m_URL != null) && !m_URL.equals("http://")) { setURL(m_URL); } }
/** * Resets the Loader object and sets the source of the data set to be * the supplied url. * * @param url the source url. * @throws IOException if an error occurs */ public void setSource(URL url) throws IOException { m_structure = null; m_JSON = null; setRetrieval(NONE); setSource(url.openStream()); m_URL = url.toString(); }
/** * Return the full data set. If the structure hasn't yet been determined * by a call to getStructure then method should do so before processing * the rest of the data set. * * @return the structure of the data set as an empty * set of Instances * @throws IOException if there is no source or parsing fails */ public Instances getDataSet() throws IOException { if (m_sourceReader == null) throw new IOException("No source has been specified"); if (getRetrieval() == INCREMENTAL) throw new IOException("Cannot mix getting Instances in both incremental and batch modes"); setRetrieval(BATCH); if (m_structure == null) getStructure(); try { // close the stream m_sourceReader.close(); } catch (Exception ex) { } return JSONInstances.toInstances(m_JSON); }
/** * returns the loader used in the tests. * * @return the configured loader */ public AbstractLoader getLoader() { return new JSONLoader(); }
/** * Set the url to load from. * * @param url the url to load from * @throws IOException if the url can't be set. */ public void setURL(String url) throws IOException { m_URL = url; setSource(new URL(url)); }
/** * Return the full data set. If the structure hasn't yet been determined * by a call to getStructure then method should do so before processing * the rest of the data set. * * @return the structure of the data set as an empty * set of Instances * @throws IOException if there is no source or parsing fails */ public Instances getDataSet() throws IOException { if (m_sourceReader == null) throw new IOException("No source has been specified"); if (getRetrieval() == INCREMENTAL) throw new IOException("Cannot mix getting Instances in both incremental and batch modes"); setRetrieval(BATCH); if (m_structure == null) getStructure(); try { // close the stream m_sourceReader.close(); } catch (Exception ex) { } return JSONInstances.toInstances(m_JSON); }
/** * returns the loader used in the tests. * * @return the configured loader */ public AbstractLoader getLoader() { return new JSONLoader(); }
/** * Set the url to load from. * * @param url the url to load from * @throws IOException if the url can't be set. */ public void setURL(String url) throws IOException { m_URL = url; setSource(new URL(url)); }
/** * Main method. * * @param args should contain the name of an input file. */ public static void main(String[] args) { runFileLoader(new JSONLoader(), args); } }
/** * Resets the Loader ready to read a new data set. * * @throws IOException if something goes wrong */ public void reset() throws IOException { m_structure = null; m_JSON = null; setRetrieval(NONE); if (m_File != null) { setFile(new File(m_File)); } else if ((m_URL != null) && !m_URL.equals("http://")) { setURL(m_URL); } }
/** * Resets the Loader object and sets the source of the data set to be * the supplied url. * * @param url the source url. * @throws IOException if an error occurs */ public void setSource(URL url) throws IOException { m_structure = null; m_JSON = null; setRetrieval(NONE); setSource(url.openStream()); m_URL = url.toString(); }
/** * Resets the Loader object and sets the source of the data set to be * the supplied File object. * * @param file the source file. * @throws IOException if an error occurs */ public void setSource(File file) throws IOException { m_structure = null; m_JSON = null; setRetrieval(NONE); if (file == null) throw new IOException("Source file object is null!"); try { if (file.getName().endsWith(FILE_EXTENSION_COMPRESSED)) setSource(new GZIPInputStream(new FileInputStream(file))); else setSource(new FileInputStream(file)); } catch (FileNotFoundException ex) { throw new IOException("File not found"); } m_sourceFile = file; m_File = file.getAbsolutePath(); }
/** * Resets the Loader object and sets the source of the data set to be * the supplied File object. * * @param file the source file. * @throws IOException if an error occurs */ public void setSource(File file) throws IOException { m_structure = null; m_JSON = null; setRetrieval(NONE); if (file == null) throw new IOException("Source file object is null!"); try { if (file.getName().endsWith(FILE_EXTENSION_COMPRESSED)) setSource(new GZIPInputStream(new FileInputStream(file))); else setSource(new FileInputStream(file)); } catch (FileNotFoundException ex) { throw new IOException("File not found"); } m_sourceFile = file; m_File = file.getAbsolutePath(); }