List of usage examples for java.io File toURI
public URI toURI()
From source file:org.codehaus.groovy.grails.plugins.springsecurity.AuthorizeTools.java
/** * Parse and load the security configuration. * @return the configuration/*from w w w .j a v a2s .c o m*/ * @throws ClassNotFoundException if DefaultSecurityConfig.groovy isn't found * @throws MalformedURLException */ public static ConfigObject getSecurityConfig() throws ClassNotFoundException, MalformedURLException { GroovyClassLoader classLoader = new GroovyClassLoader(AuthorizeTools.class.getClassLoader()); ConfigSlurper slurper = new ConfigSlurper(GrailsUtil.getEnvironment()); List<ConfigObject> configs = new ArrayList<ConfigObject>(); ConfigObject userConfig = null; try { userConfig = slurper.parse(classLoader.loadClass("SecurityConfig")); configs.add(userConfig); } catch (Exception e) { // ignored, use defaults } String extSecurityConfig = System.getProperty("securityconfig.path"); if (extSecurityConfig != null) { File file = new File(extSecurityConfig); if (file.exists()) { configs.add(slurper.parse(file.toURI().toURL())); } else { LOG.warn("specified security config '" + extSecurityConfig + "' not found"); } } ConfigObject config = slurper.parse(classLoader.loadClass("DefaultSecurityConfig")); loadExternalConfigs(configs, config); for (ConfigObject c : configs) { config = mergeConfig(config, c); } return config; }
From source file:com.puppycrawl.tools.checkstyle.utils.CommonUtils.java
/** * Resolve the specified filename to a URI. * @param filename name os the file/*from w w w . j av a 2 s . co m*/ * @return resolved header file URI * @throws CheckstyleException on failure */ public static URI getUriByFilename(String filename) throws CheckstyleException { // figure out if this is a File or a URL URI uri; try { final URL url = new URL(filename); uri = url.toURI(); } catch (final URISyntaxException | MalformedURLException ignored) { uri = null; } if (uri == null) { final File file = new File(filename); if (file.exists()) { uri = file.toURI(); } else { // check to see if the file is in the classpath try { final URL configUrl = CommonUtils.class.getResource(filename); if (configUrl == null) { throw new CheckstyleException(UNABLE_TO_FIND_EXCEPTION_PREFIX + filename); } uri = configUrl.toURI(); } catch (final URISyntaxException e) { throw new CheckstyleException(UNABLE_TO_FIND_EXCEPTION_PREFIX + filename, e); } } } return uri; }
From source file:com.asakusafw.compiler.bootstrap.AllBatchCompilerDriver.java
private static List<URL> extractPluginPath(String path) { if (path == null) { return Collections.emptyList(); }//from w w w . j a v a 2 s . c o m List<URL> results = new ArrayList<>(); for (String s : path.split(File.pathSeparator)) { if (s.trim().isEmpty()) { continue; } try { File file = new File(s); if (file.exists() == false) { throw new FileNotFoundException(file.getAbsolutePath()); } URL url = file.toURI().toURL(); results.add(url); } catch (IOException e) { LOG.warn(MessageFormat.format(Messages.getString("AllBatchCompilerDriver.warnFailedToLoadPlugin"), //$NON-NLS-1$ s), e); } } return results; }
From source file:com.jalios.ejpt.sync.utils.IOUtil.java
public static String getRelativePath(File dir, File file) { if (dir == null || file == null) { throw new IllegalArgumentException("dir and file arguments must not be null"); }/*from ww w .j a va2s .co m*/ String dirname = dir.toURI().normalize().toString(); String filename = file.toURI().normalize().toString(); // file is not under dir if (filename.length() < dirname.length() || !filename.startsWith(dirname)) { return null; } // file == dir if (filename.length() == dirname.length()) { return ""; } // file is under dir return filename.substring(dirname.length()); }
From source file:ClasspathUtils.java
public static void addJarToPath(final File jar, String loaderName) throws Exception { addJarToPath(jar.toURI().toURL(), loaderName); }
From source file:com.asakusafw.testdriver.DirectIoUtil.java
static <T> DataModelSinkFactory dump(Configuration configuration, DataModelDefinition<T> definition, Class<? extends DataFormat<?>> formatClass, File destination) throws IOException { DataFormat<? super T> format = newDataFormat(configuration, formatClass); checkDataType(definition, format);/*from w ww . ja v a 2s . co m*/ org.apache.hadoop.fs.Path path = new org.apache.hadoop.fs.Path(destination.toURI()); HadoopFileFormat<? super T> hFormat = HadoopDataSourceUtil.toHadoopFileFormat(configuration, format); return new DataModelSinkFactory() { @Override public <S> DataModelSink createSink(DataModelDefinition<S> def, TestContext context) throws IOException { try { return new DirectOutputSink<>(definition, hFormat, path); } catch (InterruptedException e) { throw (IOException) new InterruptedIOException().initCause(e); } } }; }
From source file:net.gazeplay.commons.utils.games.Utils.java
public static void playSound(String ressource) { log.debug("Try to play " + ressource); URL url = ClassLoader.getSystemResource(ressource); String path = null;/*from www . j a va2 s .c om*/ if (url == null) { final File file = new File(ressource); log.debug("using file"); if (!file.exists()) { log.warn("file doesn't exist : {}", ressource); } path = file.toURI().toString(); } else { log.debug("using url"); path = url.toString(); } log.debug("path " + path); if (sxmp != null) sxmp.stop(); try { Media media = new Media(path); sxmp = new MediaPlayer(media); final Configuration configuration = Configuration.getInstance(); sxmp.setVolume(configuration.getEffectsVolume()); sxmp.volumeProperty().bind(configuration.getEffectsVolumeProperty()); sxmp.play(); } catch (Exception e) { log.error("Exception", e); } }
From source file:at.ac.ait.ubicity.fileloader.FileLoader.java
/** * Perform a load, and either write to cache or not, according to settings. * /*from w w w . j a va 2 s .c o m*/ * @param _f The file we must ingest * @param _cache The cache we are to use for keeping file usage information up to date * @param _keySpace Cassandra key space into which to ingest * @param _host Cassandra host / server * @param _batchSize MutationBatch size * @throws Exception if actual loading of the file causes a problem */ private final static void doLoad(File _f, FileCache _cache, String _keySpace, String _host, int _batchSize) throws Exception { if (!(_cache == null)) { FileInformation _fileInfo = _cache.getFileInformationFor(_f.toURI()); if (_fileInfo == null) { _fileInfo = new FileInformation(_f.toURI(), System.currentTimeMillis(), 1, 0); _cache.updateCacheFor(_f.toURI(), _fileInfo); } logger.info("[FILELOADER] " + _fileInfo.toString()); load(_fileInfo, _keySpace, _host, _batchSize); _cache.saveCache(); } else { load(new FileInformation(_f.toURI(), System.currentTimeMillis(), 0, 0), _keySpace, _host, _batchSize); } }
From source file:org.jboss.seam.forge.shell.util.PluginUtil.java
public static void loadPluginJar(File file) throws Exception { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl == null) { cl = PluginUtil.class.getClassLoader(); }/* w ww . java2 s . c o m*/ URLClassLoader classLoader = new URLClassLoader(new URL[] { file.toURI().toURL() }, cl); Thread.currentThread().setContextClassLoader(classLoader); }
From source file:Main.java
/** A helper to make a URL from a filespec. */ private static URL makeURLFromFilespec(final String filespec, final String relativePrefix) throws IOException { // make sure the file is absolute & canonical file url File file = new File(decode(filespec)); // if we have a prefix and the file is not abs then prepend if (relativePrefix != null && !file.isAbsolute()) { file = new File(relativePrefix, filespec); }/*from ww w . j a v a 2s .c om*/ // make sure it is canonical (no ../ and such) file = file.getCanonicalFile(); return file.toURI().toURL(); }