/** * Write an File to an OutputStream * Note: this will not close the outputStream; */ public static void write(File f, OutputStream outputStream) throws IOException { write(f, outputStream, DEFAULT_BUFFER_SIZE); }
/** * Copy a file. Overwrites the destination file if it exists. * @param fromFileName * @param toFileName * @throws Exception * @since 4.3 */ public static void copy(String fromFileName, String toFileName) throws IOException { copy(fromFileName, toFileName, true); }
/** * Obtains the file extension of the specified <code>File</code>. The extension is considered to be all the * characters after the last occurrence of {@link Constants#FILE_EXTENSION_SEPARATOR_CHAR} in the pathname * of the input. * @param theFile the file whose extension is being requested * @return the extension or <code>null</code> if not found * @since 4.2 */ public static String getExtension(File theFile) { return getExtension(theFile.getPath()); }
String ext = FileUtils.getExtension(file); if (ext == null) { System.err.println(fullName + " is not a vdb or xml file."); //$NON-NLS-1$ int manifestBegin = manifestStr.indexOf("<xmi"); configStr = configStr.substring(0, index) + manifestStr.substring(manifestBegin) + "</VDB>"; FileUtils.write(configStr.getBytes(), config); manifest.delete(); zos.close(); } finally { FileUtils.removeDirectoryAndChildren(dir);
/** * Tests FileUtils.remove() * @since 4.3 */ public void testRemove() throws Exception { FileUtils.copy(FILE_NAME, TEMP_FILE_NAME, true); //positive case FileUtils.remove(TEMP_FILE_NAME); assertFalse("Expected File to not exist", new File(TEMP_FILE_NAME).exists()); //$NON-NLS-1$ //call again - this should not throw an exception FileUtils.remove(TEMP_FILE_NAME); }
private void writeDirectoryEntry(ZipOutputStream out, String name) throws IOException { ZipFile zipFile = getZipFile(name); Enumeration<?> en = zipFile.entries(); while(en.hasMoreElements()) { ZipEntry entry = (ZipEntry) en.nextElement(); if(!entry.isDirectory()) { writeEntry(entry.getName(), out, IOUtils.toByteArray(zipFile.getInputStream(entry))); } } FileUtils.remove(new File(zipFile.getName())); }
if (srcFile.isDirectory()) { File childTargetDir = new File(targetDir.getAbsolutePath()); copyRecursively(srcFile, childTargetDir, true); } else { copy(srcFile.getAbsolutePath(), targetDir.getAbsolutePath() + File.separatorChar + srcFile.getName());
FileUtils.copy(FILE_NAME, TEMP_FILE_NAME, true); FileUtils.rename(TEMP_FILE_NAME, TEMP_FILE_NAME2, false); String contents2 = ObjectConverterUtil.convertFileToString(new File(TEMP_FILE_NAME2)); assertEquals("Expected file contents to be the same", contents1, contents2); //$NON-NLS-1$ FileUtils.copy(FILE_NAME, TEMP_FILE_NAME, true); FileUtils.copy(FILE_NAME, TEMP_FILE_NAME2, true); try { FileUtils.rename(FILE_NAME, TEMP_FILE_NAME2, false); fail("Expected MetaMatrixException"); //$NON-NLS-1$ } catch (IOException e) { FileUtils.copy(FILE_NAME, TEMP_FILE_NAME, true); FileUtils.copy(FILE_NAME, TEMP_FILE_NAME2, true); FileUtils.rename(TEMP_FILE_NAME, TEMP_FILE_NAME2, true); contents2 = ObjectConverterUtil.convertFileToString(new File(TEMP_FILE_NAME2)); assertEquals("Expected file contents to be the same", contents1, contents2); //$NON-NLS-1$
/** * Clean the file storage directory on startup * @param dir * @since 4.3 */ void cleanDirectory(File file) { FileUtils.removeChildrenRecursively(file); }
public static void removeChildrenRecursively(File directory) { File[] files = directory.listFiles(); if(files != null) { for(int i=0; i < files.length; i++) { File file = files[i]; if (file.isDirectory()) { removeDirectoryAndChildren(file); } else { if(!file.delete()) { file.deleteOnExit(); } } } } }
private void writeDirectoryEntry(ZipOutputStream out, String name) throws IOException { ZipFile zipFile = getZipFile(name); Enumeration<?> en = zipFile.entries(); while(en.hasMoreElements()) { ZipEntry entry = (ZipEntry) en.nextElement(); if(!entry.isDirectory()) { writeEntry(entry.getName(), out, IOUtils.toByteArray(zipFile.getInputStream(entry))); } } FileUtils.remove(new File(zipFile.getName())); }
if (srcFile.isDirectory()) { File childTargetDir = new File(targetDir.getAbsolutePath()); copyRecursively(srcFile, childTargetDir, true); } else { copy(srcFile.getAbsolutePath(), targetDir.getAbsolutePath() + File.separatorChar + srcFile.getName());
public static void removeDirectoryAndChildren(File directory) { removeChildrenRecursively(directory); if(!directory.delete()) { directory.deleteOnExit(); } }
public static void removeChildrenRecursively(File directory) { File[] files = directory.listFiles(); if(files != null) { for(int i=0; i < files.length; i++) { File file = files[i]; if (file.isDirectory()) { removeDirectoryAndChildren(file); } else { if(!file.delete()) { file.deleteOnExit(); } } } } }
/** * Write an File to an OutputStream * Note: this will not close the outputStream; */ public static void write(File f, OutputStream outputStream) throws IOException { write(f, outputStream, DEFAULT_BUFFER_SIZE); }
/** * Copy a file. Overwrites the destination file if it exists. * @param fromFileName * @param toFileName * @throws Exception * @since 4.3 */ public static void copy(String fromFileName, String toFileName) throws IOException { copy(fromFileName, toFileName, true); }
public static void removeDirectoryAndChildren(File directory) { removeChildrenRecursively(directory); if(!directory.delete()) { directory.deleteOnExit(); } }
/** * Obtains the file extension of the specified <code>File</code>. The extension is considered to be all the * characters after the last occurrence of {@link Constants#FILE_EXTENSION_SEPARATOR_CHAR} in the pathname * of the input. * @param theFile the file whose extension is being requested * @return the extension or <code>null</code> if not found * @since 4.2 */ public static String getExtension(File theFile) { return getExtension(theFile.getPath()); }
/** * Write an InputStream to a file. */ public static void write(InputStream is, File f) throws IOException { write(is, f, DEFAULT_BUFFER_SIZE); }
/** * Copy file from orginating directory to the destination directory. * * @param orginDirectory * @param orginFileName * @param destDirectory * @param destFileName * @throws Exception * @since 4.4 */ public static void copyFile(String orginDirectory, String orginFileName, String destDirectory, String destFileName) throws Exception { FileUtils.copy(orginDirectory + File.separator + orginFileName, destDirectory + File.separator + destFileName); }