List of usage examples for java.net URI toURL
public URL toURL() throws MalformedURLException
From source file:org.wrml.runtime.EngineConfiguration.java
public final static EngineConfiguration load(final URI configLocation) throws IOException { return EngineConfiguration.load(configLocation.toURL()); }
From source file:org.dataconservancy.dcs.util.UriUtility.java
/** * Determine if a URI is resolvable. Currently this means the URI is a valid URL * @param toCheck the URI to check//from w w w . j a v a 2 s . c om * @return true if resolvable, false if not */ public static boolean isResolvable(URI toCheck) { try { toCheck.toURL(); } catch (MalformedURLException e) { return false; } return true; }
From source file:AIR.Common.Web.FileFtpHandler.java
public static boolean exists(URI requestUri) { try {//from w w w. jav a 2s . com requestUri.toURL().openConnection(); } catch (MalformedURLException e) { throw new FtpResourceException(e); } catch (IOException e) { final String NON_EXISTENT_MESSAGE = "The system cannot find the file specified"; if (StringUtils.contains(e.getMessage(), NON_EXISTENT_MESSAGE)) { // TODO Shiva this part is highly specific to the ftp server AIR uses on // its webservices. return false; } throw new FtpResourceException(e); } return true; }
From source file:org.dataconservancy.packaging.impl.UriUtility.java
/** * Determine if a URI is resolvable. Currently this means the URI is a valid URL * * @param toCheck the URI to check/*from w w w .j a v a 2s.c om*/ * @return true if resolvable, false if not */ public static boolean isResolvable(final URI toCheck) { try { toCheck.toURL(); } catch (final MalformedURLException e) { return false; } return true; }
From source file:AIR.Common.Web.FileFtpHandler.java
public static InputStream openStream(URI requestUri) throws FtpResourceException { try {//from w w w. j a va2s . co m URL url = requestUri.toURL(); URLConnection urlc = url.openConnection(); return urlc.getInputStream(); } catch (IOException exp) { throw new FtpResourceException(exp); } }
From source file:org.evosuite.junit.FooTestClassLoader.java
private static Class<?> loadClass(File javaBinDir) { URLClassLoader urlClassLoader = null; try {/*from ww w. java 2 s. c om*/ URI javaBinURI = javaBinDir.toURI(); URL javaBinURL = javaBinURI.toURL(); urlClassLoader = new URLClassLoader(new URL[] { javaBinURL }, Foo.class.getClassLoader()); Class<?> clazz = urlClassLoader.loadClass(FOO_TEST_CLASS_NAME); return clazz; } catch (ClassNotFoundException e) { return null; } catch (MalformedURLException e) { return null; } }
From source file:org.eclipselabs.dte.TextFileDetector.java
/** * Checks if a file is text or binary.//from w ww. j a v a2 s. c o m * * <p> * This method will first check if the file extension is known to be for a * binary or a text-based file. If the file extension is unknown then it * will try to analyze the file content. * </p> * * @param input * an editor input of the file * @return <code>true</code> if the file is more likely to be text file than * binary file, <code>false</code> otherwise. */ public static boolean isTextFile(IURIEditorInput input) { if (input == null) return false; String fileName = input.getName(); if (fileName == null) return false; String extension = FilenameUtils.getExtension(fileName).toUpperCase(); if (KnownTextBasedFileExtensions.set().contains(extension)) return true; if (KnownBinaryFileExtensions.set().contains(extension)) return false; URI uri = input.getURI(); if (uri != null) { InputStream is = null; try { is = uri.toURL().openStream(); return TextFileDetector.isTextFile(is); } catch (IOException e) { // Problem reading the editor input - avoid overriding } finally { // Make sure the input stream is closed close(is); } } return false; }
From source file:eu.eubrazilcc.lvl.core.util.UrlUtils.java
/** * Gets the path part of an URI.//w ww . j a va 2 s . com * @param uri - input URI * @return the path part of the specified URI or an empty string if one does not exist. * @throws IllegalArgumentException If a malformed URI occurs. */ public static String getPath(final URI uri) { checkArgument(uri != null, "Uninitialized URI"); try { final URI nUri = uri.normalize(); final URL url = nUri.isAbsolute() ? nUri.toURL() : new URL(new URL("http://example.org/"), nUri.getPath()); return url.getPath(); } catch (MalformedURLException e) { throw new IllegalArgumentException("Malformed URI", e); } }
From source file:Main.java
/** * * @param fileName/* w ww.ja va2s . c om*/ * @return */ // public static Document createDomDocument(String fileName) { public static Document createDomDocument(URI fileName) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document document = null; try { // File file = new File(fileName); java.io.InputStream is = fileName.toURL().openStream(); DocumentBuilder builder = factory.newDocumentBuilder(); // document = builder.parse(file); document = builder.parse(is); } catch (SAXParseException spe) { spe.printStackTrace(); } catch (SAXException se) { se.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return document; }
From source file:org.apache.ode.extension.e4x.TopLevelFunctions.java
/** * This methods is exposed to the JS environment and supports loading * JavaScript libraries from the deployment unit directory. *//*from ww w. ja v a 2 s. com*/ public static void load(Context cx, Scriptable thisObj, Object[] args, Function funObj) { TopLevelFunctions thiz = (TopLevelFunctions) getTopLevelScope(thisObj); for (int i = 0; i < args.length; i++) { // Assumes resource's path is given relative to the service archive URI uri = thiz._duDir.resolve(Context.toString(args[i])); try { InputStream is = uri.toURL().openStream(); cx.evaluateReader(thiz, new InputStreamReader(is), "<importJS>", 1, null); } catch (MalformedURLException e) { throw Context.throwAsScriptRuntimeEx(e); } catch (IOException e) { throw Context.throwAsScriptRuntimeEx(e); } } }