/** * Computes the empirical distribution using data read from a URL. * * @param url url of the input file * @throws IOException if an IO error occurs */ public void load(URL url) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); try { DataAdapter da = new StreamDataAdapter(in); try { da.computeStats(); } catch (IOException ioe) { // don't wrap exceptions which are already IOException throw ioe; } catch (RuntimeException rte) { // don't wrap RuntimeExceptions throw rte; } catch (Exception e) { throw MathRuntimeException.createIOException(e); } if (sampleStats.getN() == 0) { throw MathRuntimeException.createEOFException("URL {0} contains no data", url); } in = new BufferedReader(new InputStreamReader(url.openStream())); fillBinStats(in); loaded = true; } finally { try { in.close(); } catch (IOException ex) { // ignore } } }
/** * Computes the empirical distribution from the input file. * * @param file the input file * @throws IOException if an IO error occurs */ public void load(File file) throws IOException { BufferedReader in = new BufferedReader(new FileReader(file)); try { DataAdapter da = new StreamDataAdapter(in); try { da.computeStats(); } catch (IOException ioe) { // don't wrap exceptions which are already IOException throw ioe; } catch (RuntimeException rte) { // don't wrap RuntimeExceptions throw rte; } catch (Exception e) { throw MathRuntimeException.createIOException(e); } in = new BufferedReader(new FileReader(file)); fillBinStats(in); loaded = true; } finally { try { in.close(); } catch (IOException ex) { // ignore } } }
/** * Computes the empirical distribution from the provided array of numbers. * * @param in the input data array */ public void load(double[] in) { DataAdapter da = new ArrayDataAdapter(in); try { da.computeStats(); fillBinStats(in); } catch (Exception e) { throw new MathRuntimeException(e); } loaded = true; }