List of usage examples for java.net URL getFile
public String getFile()
From source file:hudson.plugins.testlink.result.parser.tap.TestTapParser.java
public void parseInvalidTapFile() { ClassLoader cl = TestTapParser.class.getClassLoader(); URL url = cl.getResource("hudson/plugins/testlink/result/parser/tap/invalid.tap"); File file = new File(url.getFile()); try {//w ww . j a v a2s . c o m this.parser.parse(file); } catch (ParserException p) { assertNotNull(p); } }
From source file:de.tudarmstadt.ukp.dkpro.c4corpus.language.CharsetDetectorTest.java
@Test public void testDetectCharset() throws Exception { // resources/charset-detector contains *.txt files URL url = getClass().getClassLoader().getResource("charset-detector"); assertNotNull(url);//from w w w.java 2s . c o m File dir = new File(url.getFile()); File[] files = dir.listFiles(); assertNotNull(files); for (File file : files) { // file names are: charset_lang.txt (_lang is optional!) String charsetName = file.getName().replaceAll("\\.txt$", "").split("_")[0]; Charset goldCharset = Charset.forName(charsetName); byte[] bytes = IOUtils.toByteArray(new FileInputStream(file)); // distracting the method by wrong declared charset String distract = "utf-16LE"; Charset detectedCharset = detector.detectCharset(bytes, distract); // System.out.println(detectedCharset); assertEquals(goldCharset, detectedCharset); } }
From source file:pl.softech.learning.gwtp.simple.server.spring.RemoteLoggingHandler.java
@Override public void setServletContext(final ServletContext servletContext) { this.servletContext = servletContext; final String path = servletContext.getInitParameter("symbolMapsPath"); if (path != null) { URL url = RemoteLoggingHandler.class.getResource("/"); LOGGER.debug("Current path is {}", url.getFile()); String rootPath = "/../../"; URL rootPathUrl = RemoteLoggingHandler.class.getResource(rootPath); if (rootPathUrl != null) { LOGGER.debug("Root app path is {}", rootPathUrl.getFile()); }/*from ww w .j a va 2s. c om*/ URL symbolMapsUrl = RemoteLoggingHandler.class.getResource(String.format("%s%s", rootPath, path)); if (symbolMapsUrl != null) { String symbolMapsDir = symbolMapsUrl.getPath(); LOGGER.debug("SymbolMaps absolute path is {}", symbolMapsDir); deobfuscator = new StackTraceDeobfuscator(symbolMapsDir); LOGGER.debug("Created deobfuscator with symbolMaps located {}", path); } } }
From source file:net.opentsdb.tsd.GraphHandler.java
/** * Iterate through the class path and look for the Gnuplot helper script. * @return The path to the wrapper script. *///from w ww. j a va2 s . com private static String findGnuplotHelperScript() { final URL url = GraphHandler.class.getClassLoader().getResource(WRAPPER); if (url == null) { throw new RuntimeException("Couldn't find " + WRAPPER + " on the" + " CLASSPATH: " + System.getProperty("java.class.path")); } final String path = url.getFile(); LOG.debug("Using Gnuplot wrapper at {}", path); final File file = new File(path); final String error; if (!file.exists()) { error = "non-existent"; } else if (!file.canExecute()) { error = "non-executable"; } else if (!file.canRead()) { error = "unreadable"; } else { return path; } throw new RuntimeException("The " + WRAPPER + " found on the" + " CLASSPATH (" + path + ") is a " + error + " file... WTF?" + " CLASSPATH=" + System.getProperty("java.class.path")); }
From source file:org.joinfaces.tomcat.JsfTomcatApplicationListener.java
private String base(URL url) { String result;/*w w w. j a va 2 s . c o m*/ if (url.getProtocol().equals("jar")) { result = url.getFile(); result = result.substring("file:".length()); result = result.substring(0, result.indexOf("!/")); } else { result = url.getFile(); } return result; }
From source file:com.liferay.ide.alloy.core.webresources_src.PortalResourcesProvider.java
private File[] _createLayoutHelperFiles(String path) throws IOException { AlloyCore plugin = AlloyCore.getDefault(); Bundle bundle = plugin.getBundle();/* ww w . j a v a 2s . c o m*/ URL url = FileLocator.toFileURL(bundle.getEntry(path)); return new File[] { new File(url.getFile()) }; }
From source file:com.gettingagile.tisugly.analyzer.ASMAnalyzer.java
private ASMAnalyzer() { URL[] urls = ((URLClassLoader) Thread.currentThread().getContextClassLoader()).getURLs(); for (URL url : urls) { loadClassesFromClasspath(new File(url.getFile())); }// w ww. ja v a2 s . c om globals = dependencyVisitor.getGlobals(); Set<String> classPackages = dependencyVisitor.getPackages(); packageNames = classPackages.toArray(new String[classPackages.size()]); Arrays.sort(packageNames); }
From source file:core.test.server.mock.util.PersonNameUtil.java
/** * read last names from file and populate array * @throws IOException /* w ww . j a v a 2s .c om*/ */ private void initializeLastNames() throws IOException { URL url = getClass().getClassLoader().getResource("people-names/last-names.txt"); File file = new File(url.getFile()); lastNames = FileUtils.readLines(file, "UTF-8"); }
From source file:core.test.server.mock.util.PersonNameUtil.java
/** * initialize mail names from file//from w w w .j a va 2 s . c om * @throws IOException * */ private void initializeMaleNames() throws IOException { URL url = getClass().getClassLoader().getResource("people-names/male-names.txt"); File file = new File(url.getFile()); maleNames = FileUtils.readLines(file, "UTF-8"); }
From source file:core.test.server.mock.util.PersonNameUtil.java
/** * initialize femail names from file//from w w w. j a v a 2 s . co m * @throws IOException * */ private void initializeFemaleNames() throws IOException { URL url = getClass().getClassLoader().getResource("people-names/female-names.txt"); File file = new File(url.getFile()); femaleNames = FileUtils.readLines(file, "UTF-8"); }