List of usage examples for java.io File toURL
@Deprecated public URL toURL() throws MalformedURLException
file:
URL. From source file:org.apache.axis2.jaxws.util.CatalogWSDLLocator.java
/** * Return the wsdlLocation in URL form. WsdlLocation could be URL, relative * module path, full absolute path.// www. j a va2 s . c o m * * @param wsdlLocation * the location of a WSDL document in the form of a URL string, a * relative pathname (relative to the root of a module, or a * full-qualified absolute pathname * @return the location of the WSDL document in the form of a URL */ public URL getWsdlUrl(String wsdlLocation) { URL streamURL = null; InputStream is = null; URI pathURI = null; // If the WSDL is present in the catalog, use the location specified // in the catalog. If this attempt results in failure, use the original // location // TODO: Provide Allowance for Catalog // Note: This method is not called. try { streamURL = new URL(wsdlLocation); is = streamURL.openStream(); is.close(); } catch (Throwable t) { // No FFDC required } if (is == null) { try { pathURI = new URI(wsdlLocation); streamURL = pathURI.toURL(); is = streamURL.openStream(); is.close(); } catch (Throwable t) { // No FFDC required } } if (is == null) { try { File file = new File(wsdlLocation); streamURL = file.toURL(); is = streamURL.openStream(); is.close(); } catch (Throwable t) { // No FFDC required } } if (log.isDebugEnabled() && streamURL == null) { log.debug("Absolute wsdlLocation could not be determined: " + wsdlLocation); } return streamURL; }
From source file:org.mule.module.wsdlproc.WSDLProcModule.java
public URL createUrl() throws MalformedURLException { URL wsdlURL;/*from ww w .j a v a 2 s.c o m*/ File wsdlFile = new File(wsdlLocation); if (wsdlFile.exists()) { wsdlURL = wsdlFile.toURL(); } else { wsdlURL = new URL(wsdlLocation); } return wsdlURL; }
From source file:io.smartspaces.workbench.project.test.IsolatedClassloaderJavaTestRunner.java
/** * Detect and run any JUnit test classes. * * @param testCompilationFolder// ww w .j ava 2 s . c o m * folder where the test classes were compiled * @param jarDestinationFile * the jar that was built * @param extension * the Java project extension for the project (can be {@code null}) * @param context * the build context * * @throws SmartSpacesException * the tests failed */ private void runJavaUnitTests(File testCompilationFolder, File jarDestinationFile, JvmProjectExtension extension, ProjectTaskContext context) throws SmartSpacesException { List<File> classpath = getClasspath(context, extension, jarDestinationFile, testCompilationFolder); List<URL> urls = new ArrayList<>(); for (File classpathElement : classpath) { try { urls.add(classpathElement.toURL()); } catch (MalformedURLException e) { context.getWorkbenchTaskContext().getWorkbench().getLog().error(String.format( "Error while adding %s to the unit test classpath", classpathElement.getAbsolutePath()), e); } } URLClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), context.getWorkbenchTaskContext().getWorkbench().getBaseClassLoader()); runTestsInIsolation(testCompilationFolder, classLoader, context); }
From source file:org.sonar.application.EnvTest.java
@Test public void files() throws Exception { File home = temp.newFolder(); File confFile = new File(home, "conf/sonar.properties"); File logFile = new File(home, "logs/sonar.log"); FileUtils.touch(confFile);/* ww w . j a va2s . c o m*/ FileUtils.touch(logFile); Env env = new Env(confFile.toURL()); assertThat(env.rootDir()).isDirectory().exists().isEqualTo(home); assertThat(env.file("conf/sonar.properties")).isFile().exists().isEqualTo(confFile); assertThat(env.file("logs/sonar.log")).isFile().exists().isEqualTo(logFile); assertThat(env.file("xxx/unknown.log")).doesNotExist(); }
From source file:org.xz.qstruts.config.QStrutsXmlConfigurationProvider.java
/** * Look for the configuration file on the classpath and in the file system * * @param fileName The file name to retrieve * @see com.opensymphony.xwork2.config.providers.XmlConfigurationProvider#getConfigurationUrls */// w w w . j av a2s. c o m @Override protected Iterator<URL> getConfigurationUrls(String fileName) throws IOException { List<URL> list = new ArrayList<URL>(); if (baseDir != null) { File[] files = baseDir.listFiles(); for (int i = 0; i < files.length; i++) { File module = new File(files[i], filename); if (module.exists()) { list.add(module.toURL()); } } } return list.iterator(); }
From source file:org.sonar.application.EnvTest.java
@Test public void fresh_dir() throws Exception { File home = temp.newFolder(); File confFile = new File(home, "conf/sonar.properties"); File logFile = new File(home, "logs/sonar.log"); FileUtils.touch(confFile);/* w w w. ja v a 2 s .com*/ FileUtils.touch(logFile); Env env = new Env(confFile.toURL()); File data = env.freshDir("data/h2"); assertThat(data).isDirectory().exists(); assertThat(data.getParentFile().getName()).isEqualTo("data"); assertThat(data.getParentFile().getParentFile()).isEqualTo(home); // clean directory File logs = env.freshDir("logs"); assertThat(logs).isDirectory().exists(); assertThat(logs.listFiles()).isEmpty(); }
From source file:com.openmeap.http.FileHandlingHttpRequestExecuterImpl.java
@Override public HttpResponse postData(String url, Hashtable getParams, Hashtable postParams) throws HttpRequestException { // test to determine whether this is a file upload or not. Boolean isFileUpload = false; for (Object o : postParams.values()) { if (o instanceof File) { isFileUpload = true;//from w ww .ja v a 2 s . c o m break; } } if (isFileUpload) { try { HttpPost httpPost = new HttpPost(createUrl(url, getParams)); httpPost.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); for (Object o : postParams.entrySet()) { Map.Entry<String, Object> entry = (Map.Entry<String, Object>) o; if (entry.getValue() instanceof File) { // For File parameters File file = (File) entry.getValue(); FileNameMap fileNameMap = URLConnection.getFileNameMap(); String type = fileNameMap.getContentTypeFor(file.toURL().toString()); entity.addPart(entry.getKey(), new FileBody(((File) entry.getValue()), type)); } else { // For usual String parameters entity.addPart(entry.getKey(), new StringBody(entry.getValue().toString(), "text/plain", Charset.forName(FormConstants.CHAR_ENC_DEFAULT))); } } httpPost.setEntity(entity); return execute(httpPost); } catch (Exception e) { throw new HttpRequestException(e); } } else { return super.postData(url, getParams, postParams); } }
From source file:de.nava.informa.utils.TestChannelRegistry.java
public void testParseProblem() throws Exception { ChannelRegistry reg = new ChannelRegistry(new ChannelBuilder()); reg.setAcceptNrOfErrors(1);/*from w ww . j a v a 2 s.c om*/ // first channel File inpFile = new File(getDataDir(), "xmlhack-0.91.xml"); File chFile = new File(getOutputDir(), "xmlhack-0.91.xml"); synchronized (chFile) { FileUtils.copyFile(inpFile, chFile); } ChannelIF chA = reg.addChannel(chFile.toURL(), 2 /* secs */, true); // be sure channel is read in try { Thread.sleep(2500); } catch (InterruptedException e) { logger.warn("Interrupted waiting thread"); } // some basic assertions assertEquals("channel exists", 1, reg.getChannels().size()); assertTrue("channel A", reg.getChannels().contains(chA)); UpdateChannelInfo info = reg.getUpdateInfo(chA); assertTrue("channel A active", reg.isActiveChannel(chA)); assertNull("no exception", info.getLastException()); assertEquals("NrProblems", 0, info.getNrProblemsOccurred()); logger.info("deleting channel file"); // simulate defect by deleting channel file synchronized (chFile) { chFile.delete(); } logger.info("starting to sleep ..."); try { // while we are sleep a new update should detect the lack of the file Thread.sleep(2500); } catch (InterruptedException e) { logger.warn("Interrupted waiting thread"); } logger.info("... stopped sleeping"); // check that it's not any longer active info = reg.getUpdateInfo(chA); assertTrue("channel A should be deactive", !reg.isActiveChannel(chA)); logger.debug("exception: " + info.getLastException()); assertNotNull("Exception", info.getLastException()); assertEquals("NrProblems", 1, info.getNrProblemsOccurred()); }
From source file:com.opensymphony.xwork2.util.finder.ResourceFinder.java
private static void readDirectoryEntries(URL location, Map<String, URL> resources) throws MalformedURLException { File dir = new File(URLDecoder.decode(location.getPath())); if (dir.isDirectory()) { File[] files = dir.listFiles(); for (File file : files) { if (!file.isDirectory()) { String name = file.getName(); URL url = file.toURL(); resources.put(name, url); }//from w w w . j a va 2s . co m } } }
From source file:org.xchain.tools.executeplugin.ExecuteMojo.java
private ClassLoader createClassLoader(ClassLoader parent, Collection<String> classPathElementFilePaths) { IsolatedClassLoader isolatedClassLoader = new IsolatedClassLoader(parent); if (classPathElementFilePaths != null && classPathElementFilePaths.size() > 0) { for (String classElementString : classPathElementFilePaths) { File classElementFile = new File(classElementString); try { URL url = classElementFile.toURL(); isolatedClassLoader.addURL(url); } catch (MalformedURLException e) { e.printStackTrace();/*from w w w . ja v a 2 s . c om*/ } } } return isolatedClassLoader; }