List of usage examples for java.io File toURL
@Deprecated public URL toURL() throws MalformedURLException
file:
URL. From source file:at.newsagg.parser.FeedParser.java
public ChannelIF parse(ChannelIF cBuilder, File aFile) throws IOException, ParseException { URL aURL = null;//w w w . ja v a 2 s. c o m try { aURL = aFile.toURL(); } catch (java.net.MalformedURLException e) { throw new IOException("File " + aFile + " had invalid URL " + "representation."); } return parse(cBuilder, new InputSource(aURL.toExternalForm()), aURL); }
From source file:org.eclipse.orion.server.tests.servlets.git.GitUtilsTest.java
@Test public void testGitDirPathNoGit() throws Exception { URI workspaceLocation = createWorkspace(getMethodName()); JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null); String location = project.getString(ProtocolConstants.KEY_CONTENT_LOCATION); URI uri = URI.create(location); File dir = GitUtils.getGitDir(new Path(uri.getPath())); assertNull(dir == null ? "N/A" : dir.toURL().toString(), dir); }
From source file:org.eclipse.orion.server.tests.servlets.git.GitUtilsTest.java
@Test public void testGitDirEmptyPath() throws Exception { File emptyPathFile = GitUtils.getGitDir(new Path("")); assertNull(emptyPathFile == null ? "N/A" : emptyPathFile.toURL().toString(), emptyPathFile); }
From source file:org.codice.opendj.embedded.server.LDAPManagerTest.java
private BundleContext createMockContext(final File dataFolderPath) { Bundle mockBundle = Mockito.mock(Bundle.class); Mockito.when(mockBundle.findEntries(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())) .then(new Answer<Enumeration<URL>>() { @Override/*from w w w . j av a 2 s . co m*/ public Enumeration<URL> answer(InvocationOnMock invocation) throws Throwable { Object[] arguments = invocation.getArguments(); String path = arguments[0].toString(); String filePattern = arguments[1].toString(); boolean recurse = (Boolean) arguments[2]; final URL url = this.getClass().getResource(path); File pathFile = null; try { pathFile = new File(url.toURI()); } catch (URISyntaxException e) { throw new RuntimeException("Unable to resolve file path", e); } final File[] files = pathFile.listFiles((FileFilter) new WildcardFileFilter(filePattern)); Enumeration<URL> enumer = new Enumeration<URL>() { int place = 0; List<File> urlList = Arrays.asList(files); @Override public boolean hasMoreElements() { return place < urlList.size(); } @Override public URL nextElement() { File file = urlList.get(place++); try { return file.toURL(); } catch (MalformedURLException e) { throw new RuntimeException("Unable to convert to URL", e); } } }; return enumer; } }); Mockito.when(mockBundle.getResource(Mockito.anyString())).then(new Answer<URL>() { @Override public URL answer(InvocationOnMock invocation) throws Throwable { return this.getClass().getResource((String) invocation.getArguments()[0]); } }); BundleContext mockContext = Mockito.mock(BundleContext.class); Mockito.when(mockContext.getDataFile(Mockito.anyString())).then(new Answer<File>() { @Override public File answer(InvocationOnMock invocation) throws Throwable { String filename = invocation.getArguments()[0].toString(); if (dataFolderPath != null) { return new File(dataFolderPath + "/" + filename); } else { return null; } } }); Mockito.when(mockContext.getBundle()).thenReturn(mockBundle); return mockContext; }
From source file:ddf.ldap.embedded.server.LDAPManagerTest.java
private BundleContext createMockContext(final File dataFolderPath) { Bundle mockBundle = Mockito.mock(Bundle.class); Mockito.when(mockBundle.findEntries(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())) .then(new Answer<Enumeration<URL>>() { @Override/*from w ww .jav a 2 s . com*/ public Enumeration<URL> answer(InvocationOnMock invocation) throws Throwable { Object[] arguments = invocation.getArguments(); String path = arguments[0].toString(); String filePattern = arguments[1].toString(); boolean recurse = (Boolean) arguments[2]; final URL url = this.getClass().getResource(path); File pathFile = null; try { pathFile = new File(url.toURI()); } catch (URISyntaxException e) { throw new RuntimeException("Unable to resolve file path", e); } final File[] files = pathFile.listFiles((FileFilter) new WildcardFileFilter(filePattern)); Enumeration<URL> enumer = new Enumeration<URL>() { int place = 0; List<File> urlList = Arrays.asList(files); @Override public boolean hasMoreElements() { return place < urlList.size(); } @Override public URL nextElement() { File file = urlList.get(place++); try { return file.toURL(); } catch (MalformedURLException e) { throw new RuntimeException("Unable to convert to URL", e); } } }; return enumer; } }); Mockito.when(mockBundle.getResource(Mockito.anyString())).then(new Answer<URL>() { @Override public URL answer(InvocationOnMock invocation) throws Throwable { return this.getClass().getResource((String) invocation.getArguments()[0]); } }); BundleContext mockContext = Mockito.mock(BundleContext.class); Mockito.when(mockContext.getDataFile(Mockito.anyString())).then(new Answer<File>() { @Override public File answer(InvocationOnMock invocation) throws Throwable { String filename = invocation.getArguments()[0].toString(); if (dataFolderPath != null) { return new File(dataFolderPath + "/" + filename); } else { return null; } } }); Mockito.when(mockContext.getBundle()).thenReturn(mockBundle); return mockContext; }
From source file:org.apache.axis2.scripting.ScriptDeploymentEngine.java
/** * Reads the complete script source code into a String *///from ww w. j a v a 2 s .c om protected String readScriptSource(File scriptFile) throws AxisFault { InputStream is; try { is = scriptFile.toURL().openStream(); } catch (IOException e) { throw new AxisFault("IOException opening script: " + scriptFile, e); } try { Reader reader = new InputStreamReader(is, "UTF-8"); char[] buffer = new char[1024]; StringBuffer source = new StringBuffer(); int count; while ((count = reader.read(buffer)) > 0) { source.append(buffer, 0, count); } return source.toString(); } catch (IOException e) { throw new AxisFault("IOException reading script: " + scriptFile, e); } finally { try { is.close(); } catch (IOException e) { throw new AxisFault("IOException closing script: " + scriptFile, e); } } }
From source file:com.gele.tools.wow.wdbearmanager.WDBearManager.java
protected static ImageIcon createImageIcon(String path) { ImageIcon retVal = null;//from w ww .j a v a 2 s. c o m java.net.URL imgURL = WDBearManager.class.getResource(path); if (imgURL != null) { retVal = new ImageIcon(imgURL); if (retVal != null) { return retVal; } else { System.err.println("createImageIcon: Couldn't find file: " + path); return null; } } File imgFile = new File(path); try { imgURL = imgFile.toURL(); retVal = new ImageIcon(imgURL); return retVal; } catch (Exception ex) { System.err.println("createImageIcon: Couldn't create IMG URL for file: " + path); return null; } }
From source file:org.jactr.entry.Main.java
public ACTRRuntime createRuntime(CommandLine cmd) throws Exception { ACTRRuntime runtime = null;//from w ww. ja v a 2 s. c o m if (cmd.hasOption('e')) { String envFile = cmd.getOptionValue('e'); File fp = new File(envFile); runtime = createRuntime(fp.toURL()); } return runtime; }
From source file:javax.faces.webapp.ConfigFileTestCase.java
protected URL relativeURL(String relativePath) throws Exception { File file = new File(System.getProperty("base.dir"), relativePath); return (file.toURL()); }
From source file:org.jboss.web.tomcat.tc5.WebCtxLoader.java
public void setWarURL(URL warURL) throws MalformedURLException { this.warURL = warURL; String path = warURL.getFile(); File classesDir = new File(path, "WEB-INF/classes"); if (classesDir.exists()) { delegate.addURL(classesDir.toURL()); ctxLoader.addURLInternal(classesDir.toURL()); }/* w w w. j av a2s. c o m*/ File libDir = new File(path, "WEB-INF/lib"); if (libDir.exists()) { File[] jars = libDir.listFiles(); int length = jars != null ? jars.length : 0; for (int j = 0; j < length; j++) { File jar = jars[j]; if (jar.getAbsolutePath().endsWith(".jar")) { delegate.addURL(jar.toURL()); ctxLoader.addURLInternal(jar.toURL()); } } } }