/** * Copy an InputStream to an OutputStream. * While this method will automatically close the destination OutputStream, * the caller is responsible for closing the source InputStream. * * @param source * @param destination * @return <code>true</code> if the operation was successful; * <code>false</code> otherwise (which includes a null input). * @see "http://java.sun.com/docs/books/performance/1st_edition/html/JPIOPerformance.fm.html#22980" */ public static boolean copy(InputStream source, OutputStream destination) { return copy(source, destination, new byte[4096]); }
/** * Move a file or directory. Initally attempts to move the File using * java.io.File.renameTo(). However, should this operation fail (e.g. when * source and destination are across different filesystems), will attempt to * copy and then delete the source. * * @param source * @param destination * @return <code>true</code> if the operation was successful; * <code>false</code> otherwise (which includes a null input). */ public static boolean move(File source, File destination) { if (source == null || destination == null) { return false; } if (source.renameTo(destination)) { return true; } else { return copy(source, destination) && delete(source); } }
/** * Make scripts (ending with .sh) executable on *nix systems. */ public static void setScriptsExecutable(File dir) { String os = System.getProperty("os.name"); if (os != null && !os.startsWith("Windows")) { FileFilter filter = FileUtils.getSuffixFileFilter(".sh"); setExecutable(dir, filter); } }
if (m_format.equals(ATOM_ZIP1_1)) { try { tempDir = FileUtils.createTempDir("atomzip", null); ZipInputStream zin = new ZipInputStream(new BufferedInputStream(in)); ZipEntry entry; FileUtils.copy(zin, new FileOutputStream(new File(tempDir, entry.getName())), buf); FileUtils.delete(tempDir);
/** * Delete the specified file or directory. * * @param file * File or directory to delete * @return <code>true</code> if the operation was successful; * <code>false</code> otherwise (which includes a null input). */ public static boolean delete(String file) { return delete(new File(file)); }
@Override protected void installTomcat() throws InstallationFailedException { System.out.println("Installing Tomcat..."); try { Zip.unzip(getDist().get(Distribution.TOMCAT), System .getProperty("java.io.tmpdir")); } catch (IOException e) { throw new InstallationFailedException(e.getMessage(), e); } File f = new File(System.getProperty("java.io.tmpdir"), Distribution.TOMCAT_BASENAME); if (!FileUtils.move(f, getTomcatHome())) { throw new InstallationFailedException("Move to " + getTomcatHome().getAbsolutePath() + " failed."); } FedoraHome.setScriptsExecutable(new File(getTomcatHome(), "bin")); }
private final void generateBackendPolicies() throws Exception { logger.info("Generating backend policies..."); FileUtils.deleteContents(new File(m_repositoryBackendPolicyDirectoryPath)); BackendPolicies backendPolicies = new BackendPolicies(m_serverHome + File.separator
if (m_format.equals(ATOM_ZIP1_1)) { try { tempDir = FileUtils.createTempDir("atomzip", null); ZipInputStream zin = new ZipInputStream(new BufferedInputStream(in)); ZipEntry entry; FileUtils.copy(zin, new FileOutputStream(new File(tempDir, entry.getName())), buf); FileUtils.delete(tempDir);
/** * Delete the specified file or directory. * * @param file * File or directory to delete * @return <code>true</code> if the operation was successful; * <code>false</code> otherwise (which includes a null input). */ public static boolean delete(String file) { return delete(new File(file)); }
if (f.getParentFile().equals(tempDir)) { File temp = File.createTempFile("binary-datastream", null); FileUtils.move(f, temp); temp.deleteOnExit(); return temp;
private final void generateBackendPolicies() throws Exception { logger.info("Generating backend policies..."); FileUtils.deleteContents(new File(m_repositoryBackendPolicyDirectoryPath)); BackendPolicies backendPolicies = new BackendPolicies(m_serverHome + File.separator
/** * Copy an InputStream to an OutputStream. * While this method will automatically close the destination OutputStream, * the caller is responsible for closing the source InputStream. * * @param source * @param destination * @return <code>true</code> if the operation was successful; * <code>false</code> otherwise (which includes a null input). * @see "http://java.sun.com/docs/books/performance/1st_edition/html/JPIOPerformance.fm.html#22980" */ public static boolean copy(InputStream source, OutputStream destination) { return copy(source, destination, new byte[4096]); }
/** * Move a file or directory. Initally attempts to move the File using * java.io.File.renameTo(). However, should this operation fail (e.g. when * source and destination are across different filesystems), will attempt to * copy and then delete the source. * * @param source * @param destination * @return <code>true</code> if the operation was successful; * <code>false</code> otherwise (which includes a null input). */ public static boolean move(File source, File destination) { if (source == null || destination == null) { return false; } if (source.renameTo(destination)) { return true; } else { return copy(source, destination) && delete(source); } }
private File repackage(File stagingDir, File outputFile) throws IOException { Zip.zip(outputFile, stagingDir.listFiles()); FileUtils.delete(stagingDir); return outputFile; } private void addLibrary(File stagingDir, String libraryPath,
if (f.getParentFile().equals(tempDir)) { File temp = File.createTempFile("binary-datastream", null); FileUtils.move(f, temp); temp.deleteOnExit(); return temp;
private void addLibrary(File stagingDir, String libraryPath, File outputFile) throws IOException { // unzip, add file, re-zip, and remove staging dir File sourceFile = new File(libraryPath); File destFile = new File(stagingDir, "WEB-INF/lib/" + sourceFile.getName()); FileUtils.copy(sourceFile, destFile); } private void addContext(File stagingDir) throws IOException {
/** * Delete a File. * * @param file * the File to delete. * @return <code>true</code> if the operation was successful; * <code>false</code> otherwise (which includes a null input). */ public static boolean delete(File file) { boolean result = true; if (file == null) { return false; } if (file.exists()) { if (file.isDirectory()) { // 1. delete content of directory: File[] children = file.listFiles(); for (File child : children) { //for each file: result = result && delete(child); }//next file } result = result && file.delete(); } //else: input directory does not exist or is not a directory return result; }
private File streamtoFile(InputStream objectAsStream) throws IOException { File objectAsFile = null; try { objectAsFile = File.createTempFile("validation", "tmp", m_tempDir); FileOutputStream fos = new FileOutputStream(objectAsFile); FileUtils.copy(objectAsStream, fos); return objectAsFile; } catch (IOException e) { if (objectAsFile != null && objectAsFile.exists()) { objectAsFile.delete(); } throw e; } }
/** * Delete a File. * * @param file * the File to delete. * @return <code>true</code> if the operation was successful; * <code>false</code> otherwise (which includes a null input). */ public static boolean delete(File file) { boolean result = true; if (file == null) { return false; } if (file.exists()) { if (file.isDirectory()) { // 1. delete content of directory: File[] children = file.listFiles(); for (File child : children) { //for each file: result = result && delete(child); }//next file } result = result && file.delete(); } //else: input directory does not exist or is not a directory return result; }
@Override public void deploy(File war) throws InstallationFailedException { System.out.println("Deploying " + war.getName() + "..."); File dest = new File(webapps, war.getName()); if (!FileUtils.copy(war, dest)) { throw new InstallationFailedException("Deploy failed: unable to copy " + war.getAbsolutePath() + " to " + dest.getAbsolutePath()); } }