List of usage examples for org.apache.commons.io FileUtils toFile
public static File toFile(URL url)
URL
to a File
. From source file:com.qperior.GSAOneBoxProvider.implementations.jive.rest.QPJiveJsonObjectTest.java
private String getJSONString(String fileName) { String jsonString = ""; try {/*from w w w . j a v a2s .c o m*/ URL url = ConfigurationUtils.locate(null, fileName); File file = FileUtils.toFile(url); jsonString = FileUtils.readFileToString(file); } catch (IOException exc) { //nothing } return jsonString; }
From source file:com.itemanalysis.jmetrik.data.JmetrikFileReaderTest.java
@Test public void headerTest() { System.out.println("JmetrikFileReader: header test"); File f = FileUtils.toFile(this.getClass().getResource("/data/example-import-file.jmetrik")); HashMap<VariableName, VariableAttributes> variableAttributeMap = null; try (JmetrikFileReader reader = new JmetrikFileReader(f)) { reader.openConnection();/*from w w w .j a va2s .com*/ variableAttributeMap = reader.getVariableAttributes(); for (VariableName v : variableAttributeMap.keySet()) { System.out.println(variableAttributeMap.get(v).toString()); } } catch (IOException ex) { ex.printStackTrace(); } }
From source file:com.jaeksoft.searchlib.test.legacy.IndexTest.java
@Test public void testIndexDocument() throws ClientProtocolException, IOException { File documents = FileUtils.toFile(this.getClass().getResource("documents.xml")); int status = commomTestCase.postFile(documents, "text/xml", CommonTestCase.INDEX_API); assertEquals(200, status);/*from www.j a v a 2 s . co m*/ }
From source file:ch.silviowangler.dox.HashGeneratorTest.java
private static File loadFile(String fileName) { URL resource = HashGenerator.class.getClassLoader().getResource(fileName); assertNotNull("Resource '" + fileName + "' could not be found", resource); return FileUtils.toFile(resource); }
From source file:com.jaeksoft.searchlib.test.legacy.PatternTest.java
@Test public void testInsertPattern() throws ClientProtocolException, IOException { File patterns = FileUtils.toFile(this.getClass().getResource("patterns.txt")); int status = commomTestCase.postFile(patterns, "text/plain", CommonTestCase.PATTERN_API); assertEquals(200, status);/* www.ja v a 2 s .c o m*/ }
From source file:com.dhenton9000.json.JacksonFromStringDemo.java
public File convertClassPathToFileRef(String path) throws FileNotFoundException { if (this.getClass().getResource(path) != null) return new File(FileUtils.toFile(getClass().getResource(path)).getAbsolutePath()); else {// ww w .j a v a2s .com String info = String.format("unable to find file at '%s'", path); throw new FileNotFoundException(info); } }
From source file:net.sf.taverna.t2.renderers.RendererUtils.java
public static long getSizeInBytes(Path path) throws IOException { if (isValue(path)) return Files.size(path); if (!isReference(path)) throw new IllegalArgumentException("Path is not a value or reference"); URL url = getReference(path).toURL(); switch (url.getProtocol().toLowerCase()) { case "http": case "https": HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("HEAD"); conn.connect();/*from w ww .ja v a 2 s . co m*/ String contentLength = conn.getHeaderField("Content-Length"); conn.disconnect(); if (contentLength != null && !contentLength.isEmpty()) return Long.parseLong(contentLength); return -1; case "file": return FileUtils.toFile(url).length(); default: return -1; } }
From source file:integration.AbstractCompileIT.java
protected File toFile(String filename) { URL url = CompatibilityIT.class.getClassLoader().getResource(filename); File file = FileUtils.toFile(url); return file;/*from www. j a v a 2 s. co m*/ }
From source file:com.mgmtp.perfload.agent.Agent.java
private static File getAgentDir() { URL location = Agent.class.getProtectionDomain().getCodeSource().getLocation(); File jarFile = FileUtils.toFile(location); return jarFile.getParentFile(); }
From source file:com.greenpepper.agent.server.AgentConfigurationTest.java
public void testReadingDefaultConfigurationFile() throws Exception { // keep the current directory String origCWD = System.getProperty("user.dir"); URL resource = getClass().getResource("/remoteagent.properties"); System.setProperty("user.dir", FileUtils.toFile(resource).getParent()); AgentConfiguration configuration = new AgentConfiguration(); System.setProperty("user.dir", origCWD); assertEquals(7777, configuration.getPort()); assertFalse(configuration.isSecured()); assertNull(configuration.getKeyStore()); assertNull(configuration.getKeyStorePassword()); }