private URL[] getUrlsFrom(String root, List paths) throws MalformedURLException { URL[] urls = new URL[paths.size()]; for (int i = 0; i < urls.length; i++) { String cpElement = (String)paths.get(i); urls[i] = FileUtils.newFile(root, cpElement).toURL(); } return urls; }
public static synchronized File stringToFile(String filename, String data, boolean append, boolean newLine) throws IOException { File f = createFile(filename); BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter(f, append)); writer.write(data); if (newLine) { writer.newLine(); } } finally { if (writer != null) { writer.close(); } } return f; }
/** * Delete a file tree recursively. * @param dir dir to wipe out * @return false when the first unsuccessful attempt encountered */ public static boolean deleteTree(File dir) { return deleteTree(dir, null); }
/** * Exception tolerant roll back method * * @throws Throwable */ protected void rollbackFileMove(File sourceFile, String destinationFilePath) throws IOException { try { FileUtils.moveFile(sourceFile, FileUtils.newFile(destinationFilePath)); } catch (IOException t) { logger.debug("rollback of file move failed: " + t.getMessage()); throw t; } }
File file = FileUtils.newFile(path); if (!file.exists()) outputDir = FileUtils.newFile(outputDir.getPath() + File.separator + resourceName); if (!outputDir.exists()) outputDir = FileUtils.newFile(outputDir.getPath()); copyDirectory(file, outputDir); outputDir = FileUtils.newFile(outputDir.getPath() + File.separator + resourceName); outputDir = FileUtils.newFile(outputDir.getPath() + File.separator + file.getName()); copyFile(file, outputDir);
public synchronized String undeploy() throws RegistryException { if (!getCurrentState().equals(SHUTDOWN) && !getCurrentState().equals(UNKNOWN)) { throw new RegistryException("Illegal status: " + getCurrentState()); } Unit[] units = getUnits(); for (int i = 0; i < units.length; i++) { units[i].undeploy(); // TODO: read output from undeploy() to analyse result } FileUtils.deleteTree(FileUtils.newFile(getInstallRoot())); getRegistry().removeAssembly(this); setCurrentState(UNKNOWN); // TODO: return info return null; }
FileUtils.unzip(source, artifactDir); if ("file".equals(artifactUrl.getProtocol())) FileUtils.deleteQuietly(source); FileUtils.deleteTree(artifactDir);
public static Collection<File> findFiles(File folder, IOFileFilter filter, boolean recursive) { return listFiles(folder, filter, recursive ? TrueFileFilter.INSTANCE : FalseFileFilter.INSTANCE); }
public void setReadFromDirectory(String dir) throws IOException { this.readFromDirectoryName = dir; if (readFromDirectoryName != null) { // check if the directory exists/can be read FileUtils.openDirectory((readFromDirectoryName)); } }
public static String getResourcePath(String resourceName, Class callingClass) throws IOException { return getResourcePath(resourceName, callingClass, DEFAULT_ENCODING); }
public static boolean renameFile(String srcFilePath, String destFilePath) { if (StringUtils.isNotBlank(srcFilePath) && StringUtils.isNotBlank(destFilePath)) { return renameFile(new File(srcFilePath), new File(destFilePath)); } else { return false; } }
public void delete() { FileUtils.deleteQuietly(file); }
/** * Returns a file timestamp. * * @param url the file URL. * @return the file's timestamp if the URL has the file protocol, otherwise. * returns -1. */ public static long getFileTimeStamp(URL url) { long timeStamp = -1; if (isFile(url)) { try { String file = URLDecoder.decode(url.getFile(), "UTF-8"); timeStamp = new File(file).lastModified(); } catch (UnsupportedEncodingException e) { // Ignore } } return timeStamp; }
private File copyNativeLibrary(String name, String libraryPath) { final String nativeLibName = System.mapLibraryName(name); final File tempLibrary = new File(perAppNativeLibs, nativeLibName + System.currentTimeMillis()); try { final File library = new File(libraryPath); FileUtils.copyFile(library, tempLibrary); return tempLibrary; } catch (IOException e) { throw new IllegalStateException(String.format("Unable to generate copy for native library '%s' at '%s'", nativeLibName, tempLibrary.getAbsolutePath()), e); } } }
public synchronized void uninstall() throws RegistryException { if (!getCurrentState().equals(SHUTDOWN)) { throw new RegistryException("Illegal status: " + getCurrentState()); } try { doUninstall(); } catch (Exception e) { throw new RegistryException(e); } FileUtils.deleteTree(FileUtils.newFile(getInstallRoot())); getRegistry().removeLibrary(this); setCurrentState(UNKNOWN); }
private URL[] findSharedPluginLibs(String appName) throws MalformedURLException { Set<URL> urls = new HashSet<>(); final File sharedPluginLibs = MuleFoldersUtil.getAppSharedPluginLibsFolder(appName); if (sharedPluginLibs.exists()) { Collection<File> jars = FileUtils.listFiles(sharedPluginLibs, new String[] {"jar"}, false); for (File jar : jars) { urls.add(jar.toURI().toURL()); } } return urls.toArray(new URL[0]); }
public void setWorkDirectory(String workDirectoryName) throws IOException { this.workDirectoryName = workDirectoryName; if (workDirectoryName != null) { File workDirectory = FileUtils.openDirectory(workDirectoryName); if (!workDirectory.canWrite()) { throw new IOException( "Error on initialization, Work Directory '" + workDirectory +"' is not writeable"); } } }
@Override public void setClientKeyStore(String name) throws IOException { clientKeyStoreName = name; if (null != clientKeyStoreName) { clientKeyStoreName = FileUtils.getResourcePath(clientKeyStoreName, getClass()); if (logger.isDebugEnabled()) { logger.debug("Normalised clientKeyStore path to: " + clientKeyStoreName); } } }
public static void appendJarFileEntries(File jarFile, LinkedHashMap entries) throws Exception { if (entries != null) { LinkedHashMap combinedEntries = readJarFileEntries(jarFile); combinedEntries.putAll(entries); File tmpJarFile = File.createTempFile(jarFile.getName(), null); createJarFileEntries(tmpJarFile, combinedEntries); jarFile.delete(); FileUtils.renameFile(tmpJarFile, jarFile); } }
private void removeUnhealthyFiles() throws ObjectStoreException { List<Serializable> keys = allKeys(); for (Serializable key : keys) { QueueKey qkey = (QueueKey) key; String fileName = storeDirectory + File.separator + qkey.queueName + File.separator + qkey.id + FILE_EXTENSION; File file = new File(fileName); if (file.length() == 0) { FileUtils.deleteQuietly(file); logger.info("Removing zero size file: " + file.getAbsolutePath()); } } } }