List of usage examples for org.apache.commons.io FileUtils toFile
public static File toFile(URL url)
URL
to a File
. From source file:fr.inria.maestro.lga.examples.SSLMExample2.java
public static void main(String[] args) throws IOException { //load graph/*w w w . j a v a2 s . com*/ int numberOfSeeds = 1; double alpha = 0.85; double sigma = 0.0; String shortLink = "/graph/bvg/"; URL url = SSLMExample2.class.getResource(shortLink); String dir = url.getPath(); String name = "LesMisrablesWeighted"; String namer = "LesMisrablesNames.txt"; String expertName = "LesMiserablesExpert.txt"; final File expertFile = FileUtils.toFile(SSLMExample.class.getResource(shortLink + expertName)); IClustering expert = Data.loadClustering(expertFile); IGraph graph = Data.loadGraphBVG(dir, name, namer); System.out.println("nodes=" + graph.numNodes() + " edges=" + graph.numArcs()); System.out.println("WeightedGraph:" + (graph instanceof IArcWeightedGraph)); IClustering seeds = SeedChooser.getMaxPRSeeds(graph, numberOfSeeds, expert); System.out.println("\n***Estimations for weighted graph:"); IClustering algoCl = doClassificationWeightedGraph(graph, seeds, sigma, alpha); SSLMExample.doEsteem(graph, expert, algoCl); System.out.println("\n***Estimations for unweighted graph:"); IClustering algoCl2 = SSLMExample.doClassification(graph, seeds, sigma, alpha); SSLMExample.doEsteem(graph, expert, algoCl2); }
From source file:fr.inria.maestro.lga.examples.SSLMExample.java
public static void main(String[] args) { final File graphFile = FileUtils.toFile(SSLMExample.class.getResource("/graph/matlab/graph.txt")); final File expertFile = FileUtils.toFile(SSLMExample.class.getResource("/graph/matlab/clusters.txt")); //System.out.println(graphFile.getAbsolutePath()); double sigma = 0.5; double alpha = 0.85; int numberOfSeeds = 5; IGraph graph = Data.loadGraphMatlab(graphFile); System.out.println("nodes:" + graph.numNodes() + " arcs:" + graph.numArcs()); graph.getProperties().setValue(IGraph.NODE_NAMER, new IdenticalIdNodeNamer()); IClustering expert = Data.loadClustering(expertFile); IClustering seeds = SeedChooser.getMaxDegreeSeeds(graph, numberOfSeeds, expert); IClustering algoCl = doClassification(graph, seeds, sigma, alpha); doEsteem(graph, expert, algoCl);/* ww w.ja v a 2s . com*/ }
From source file:by.heap.remark.util.TestUtils.java
/** * Reads a resource into a string./* w ww . j ava 2 s .c o m*/ * @param path Path to resource * @return String contents of resource */ public static String readResourceToString(String path) { String result; try { URL u = StringUtils.class.getResource(path); if (u == null) { throw new Exception("Resource not found"); } File f = FileUtils.toFile(u); if (!f.isFile()) { throw new Exception("Resource file does not exist or is not a file."); } result = FileUtils.readFileToString(f, "UTF-8"); if (result == null) { throw new Exception("Error reading resource file."); } } catch (Exception e) { e.printStackTrace(); result = "UNABLE TO LOAD RESOURCE " + path + ": " + e.getMessage(); } return result; }
From source file:fr.inria.maestro.lga.TestUtils.java
public static IGraph loadMatLabGraph(final String path) throws IOException { final File graphFile = FileUtils.toFile(TestUtils.class.getResource(path)); return new MatLabLoader().load(graphFile); }
From source file:com.sonar.sslr.test.minic.MiniCParser.java
public static AstNode parseFile(String filePath) { File file = FileUtils.toFile(MiniCParser.class.getResource(filePath)); if (file == null || !file.exists()) { throw new AssertionError("The file \"" + filePath + "\" does not exist."); }/*from w w w.ja v a 2 s .c o m*/ return P.parse(file); }
From source file:fr.inria.maestro.lga.TestUtils.java
public static IClustering loadClustering(final String path) throws IOException { final File clusteringFile = FileUtils.toFile(TestUtils.class.getResource(path)); return ClusteringUtils.loadFromFile(clusteringFile); }
From source file:cmg.org.monitor.ext.util.IOUtil.java
/** * Read resource./*from www .j av a2 s . com*/ * * @param path the path * @return the string * @throws IOException Signals that an I/O exception has occurred. */ public static String readResource(String path) throws IOException { try { return FileUtils.readFileToString(FileUtils.toFile(IOUtil.class.getResource(path))); } catch (IOException e) { throw e; } }
From source file:com.dhenton9000.excel.POITest.java
@Test public void testGeneralExcelRead() throws Exception { final File file = new File(FileUtils.toFile(getClass().getResource(GOOD_FILE_LOCATION)).getAbsolutePath()); ExcelParser eP = new ExcelParser(); SheetResults results = eP.parse(new FileInputStream(file)); assertEquals(3, results.getHeaders().size()); assertEquals(3, results.getRows().size()); String[] test = { "alpha", "beta", "gamma" }; List<String> testList = Arrays.asList(test); for (String t : testList) { assertTrue(results.getHeaders().contains(t)); }//from w w w.j ava 2 s. c o m assertEquals(results.getRows().get(1).get("beta"), "B"); }
From source file:cz.incad.vdkcommon.VDKJobData.java
public void load() throws Exception { File fdef = FileUtils.toFile(Options.class.getResource("/cz/incad/vdkcommon/job.json")); String json = FileUtils.readFileToString(fdef, "UTF-8"); opts = new JSONObject(json); File f = new File(this.configFile); this.configDir = f.getParent(); this.configSimpleName = f.getName().split("\\.")[0]; this.statusFile = this.configDir + File.separator + "status" + File.separator + this.configSimpleName + ".status"; if (f.exists() && f.canRead()) { json = FileUtils.readFileToString(f, "UTF-8"); JSONObject confCustom = new JSONObject(json); Iterator keys = confCustom.keys(); while (keys.hasNext()) { String key = (String) keys.next(); opts.put(key, confCustom.get(key)); }/*from w ww .j a v a 2 s .c o m*/ } Iterator keys = runtimeOptions.keys(); while (keys.hasNext()) { String key = (String) keys.next(); opts.put(key, runtimeOptions.get(key)); } logger.info("VDKJobData loaded"); }
From source file:net.bpelunit.test.util.TestTestRunner.java
@Override public void configureInit() throws ConfigurationException { setHomeDirectory(FileUtils.toFile(BPELUnitBaseRunner.class.getClass().getResource("/")).getAbsolutePath()); }