List of usage examples for java.io File toURI
public URI toURI()
From source file:io.fluo.stress.TrieMapRedIT.java
static void generate(int numMappers, int numPerMapper, int max, File out1) throws Exception { int ret = ToolRunner.run(new Generate(), new String[] { "-D", "mapred.job.tracker=local", "-D", "fs.defaultFS=file:///", "" + numMappers, numPerMapper + "", max + "", out1.toURI().toString() }); Assert.assertEquals(0, ret);/* www . j a v a 2 s . c o m*/ }
From source file:com.isomorphic.maven.util.ArchiveUtils.java
/** * Steps common to archiving both zip and jar files, which include reading files from disk and using * their contents to create {@link ZipEntry ZipEntries} and writing them to a ZipOutputStream. * //from ww w.jav a 2 s. co m * @param root * @param source * @param target * @throws IOException */ private static void zip(File root, File source, ZipOutputStream target) throws IOException { String relativePath = root.toURI().relativize(source.toURI()).getPath().replace("\\", "/"); BufferedInputStream in = null; try { if (source.isDirectory()) { if (!relativePath.endsWith("/")) { relativePath += "/"; } ZipEntry entry = ZipEntryFactory.get(target, relativePath); entry.setTime(source.lastModified()); target.putNextEntry(entry); target.closeEntry(); for (File nestedFile : source.listFiles()) { zip(root, nestedFile, target); } return; } ZipEntry entry = ZipEntryFactory.get(target, relativePath); entry.setTime(source.lastModified()); target.putNextEntry(entry); in = new BufferedInputStream(FileUtils.openInputStream(source)); IOUtils.copy(in, target); target.closeEntry(); } finally { IOUtils.closeQuietly(in); } }
From source file:net.jselby.pc.bukkit.BukkitLoader.java
public static void addToClasspath(File file) throws Exception { Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[] { URL.class }); method.setAccessible(true);//from w ww . j av a 2 s . c o m method.invoke(ClassLoader.getSystemClassLoader(), new Object[] { file.toURI().toURL() }); }
From source file:com.robin.uielements.TranslationMap.java
/** * Parse all translation xmls and store their data in memory. * @param config Configuration.//from www. jav a 2 s. c om */ public static void parse(final Configuration config) { synchronized (ELEMENTMAP) { if (ELEMENTMAP.isEmpty()) { File baseFolder = new File(config.getValue(ConfigParams.TLXMLSDIR)); @SuppressWarnings("unchecked") Collection<File> fileList = FileUtils.listFiles(baseFolder, new String[] { "xml" }, true); for (File file : fileList) { ELEMENTMAP.put(baseFolder.toURI().relativize(file.toURI()).getPath(), getTranslationsFromFile(baseFolder, file)); } } } }
From source file:ArchiveUtil.java
/** * Reads the contents of the file into a byte array. *//*w ww . j av a 2 s . c o m*/ public static byte[] readBytes(File file) throws IOException { return readBytes(file.toURI()); }
From source file:com.expedia.tesla.compiler.Util.java
/** * Parse a Java {@code classpath} string to URLs. The {@code classpath} is represented with the same format of the * {@code CLASSPATH} variable or {@code -cp} java option. It supports the {@code *} wildcard. * /*from w w w . ja va2s . co m*/ * @param classpath * the classpath string. * @return * URLs. * * @throws IOException * on IO errors. */ public static URL[] parseClassPath(String classpath) throws IOException { final String splitPattern = Character.toString(File.pathSeparatorChar); final String wildcardPattern = ".+\\*"; String[] paths = classpath.split(splitPattern); List<URL> urls = new ArrayList<URL>(); for (String path : paths) { path = path.trim(); if (path.matches(wildcardPattern)) { File folder = new File(path.replace("\\*", "")); if (folder.exists()) { File[] files = folder.listFiles(); for (File f : files) { urls.add(f.toURI().toURL()); } } } else { urls.add(new File(path).toURI().toURL()); } } URL[] result = new URL[urls.size()]; return urls.toArray(result); }
From source file:io.fluo.stress.TrieMapRedIT.java
static void init(int nodeSize, File fluoPropsFile, File input, File tmp) throws Exception { int ret = ToolRunner.run(new Init(), new String[] { "-D", "mapred.job.tracker=local", "-D", "fs.defaultFS=file:///", fluoPropsFile.getAbsolutePath(), input.toURI().toString(), tmp.toURI().toString() }); Assert.assertEquals(0, ret);// ww w. j a v a 2 s .c o m }
From source file:com.frostwire.gui.library.M3UPlaylist.java
/** * Call this when you want to save the contents of the playlist. * NOTE: only local files can be saved in M3U format, filters out URLs * that are not part of the local filesystem * @exception IOException Throw when save failed. * @exception IOException Throw when save failed. *///from ww w .j a va 2s .c o m public static void save(String fileName, List<File> files) throws IOException { File playListFile = new File(fileName); // if all songs are new, just get rid of the old file. this may // happen if a delete was done.... if (files.size() == 0) { // if (playListFile.exists()) { // playListFile.delete(); // } return; } PrintWriter m3uFile = null; try { m3uFile = new PrintWriter(new FileWriter(playListFile.getCanonicalPath(), false)); m3uFile.write(M3U_HEADER); m3uFile.println(); for (File currFile : files) { // only save files that are local to the file system if (currFile.isFile()) { File locFile; locFile = new File(currFile.toURI()); // first line of song description... m3uFile.write(SONG_DELIM); m3uFile.write(SEC_DELIM); // try to write out seconds info.... //if( currFile.getProperty(PlayListItem.LENGTH) != null ) // m3uFile.write("" + currFile.getProperty(PlayListItem.LENGTH) + ","); //else m3uFile.write("" + -1 + ","); m3uFile.write(currFile.getName()); m3uFile.println(); // canonical path follows... m3uFile.write(locFile.getCanonicalPath()); m3uFile.println(); } } } finally { IOUtils.closeQuietly(m3uFile); } }
From source file:com.github.srec.util.ResourceFactory.java
/** * Gets a generic resource, searching first from the file system then in the classpath if not found. * * @param resource The resource name/*ww w . j a va2s. c om*/ * @return The resource */ public static Resource getGenericResource(String resource) { log.trace("retrieving resource -> " + resource); try { final File file = normFile(resource); if (file.exists()) { return new ResourceImpl(file.toURI().toURL()); } if (resource.startsWith("/")) { throw new IllegalArgumentException("Classpath resource cannot start with '/': " + resource); } if (resource.indexOf('\\') != -1) { throw new IllegalArgumentException("Classpath resource cannot contain '\\': " + resource); } URL url = getLoader().getResource(resource); if (url == null) { return null; } return new ResourceImpl(url); } catch (Exception e) { log.error("Could not retrieve resource: " + e.getMessage(), e); return null; } }
From source file:com.hangum.tadpole.engine.initialize.JDBCDriverLoader.java
/** * add JAR Loader of dir/*from ww w. j a v a2 s . c o m*/ * * @param strDir * @throws Exception */ public static void addJARDir(String strDir) throws Exception { // if(logger.isDebugEnabled()) logger.debug("--> JAR path : " + strDir); File fileDir = new File(strDir); if (fileDir.isDirectory()) { File[] files = fileDir.listFiles(); for (File file : files) { if (file.isDirectory()) { addJARDir(file.getAbsolutePath()); } else { if (StringUtils.endsWithIgnoreCase(file.getName(), ".jar")) { addJARLoader(new Object[] { file.toURI().toURL() }); } } } } else { if (StringUtils.endsWithIgnoreCase(fileDir.getName(), ".jar")) { addJARLoader(new Object[] { fileDir.toURI().toURL() }); } } }