public static boolean deleteFile(File fileToDelete) { if (fileToDelete == null || !fileToDelete.exists()) { return true; } boolean result = deleteChildren(fileToDelete); result &= fileToDelete.delete(); return result; }
public File getDataDirectoryFile() { if (dataDirectoryFile == null) { dataDirectoryFile = new File(IOHelper.getDefaultDataDirectory()); } return dataDirectoryFile; }
public static void copyFile(File src, File dest, FilenameFilter filter) throws IOException { if (src.getCanonicalPath().equals(dest.getCanonicalPath()) == false) { if (src.isDirectory()) { mkdirs(dest); List<File> list = getFiles(src, filter); for (File f : list) { if (f.isFile()) { File target = new File(getCopyParent(src, dest, f), f.getName()); copySingleFile(f, target); } } } else if (dest.isDirectory()) { mkdirs(dest); File target = new File(dest, src.getName()); copySingleFile(src, target); } else { copySingleFile(src, dest); } } }
public static void moveFiles(File srcDirectory, File targetDirectory, FilenameFilter filter) throws IOException { if (!srcDirectory.isDirectory()) { throw new IOException("source is not a directory"); } if (targetDirectory.exists() && !targetDirectory.isDirectory()) { throw new IOException("target exists and is not a directory"); } else { mkdirs(targetDirectory); } List<File> filesToMove = new ArrayList<File>(); getFiles(srcDirectory, filesToMove, filter); for (File file : filesToMove) { if (!file.isDirectory()) { moveFile(file, targetDirectory); } } }
public static String nameFromDestinationFilter(ActiveMQDestination destination) { if (destination.getQualifiedName().length() > IOHelper.getMaxFileNameLength()) { LOG.warn("Destination name is longer than 'MaximumFileNameLength' system property, " + "potential problem with recovery can result from name truncation."); } return IOHelper.toFileSystemSafeName(destination.getQualifiedName()); }
File directory = store.getDirectory(); store.stop(); IOHelper.mkdirs(directory); IOHelper.deleteChildren(directory); store = createConcurrentAddRemovePListStore(); store.setDirectory(directory);
@Test public void testDeleteOnUnlockIfLocked() throws Exception { File lockFile = new File(IOHelper.getDefaultDataDirectory(), "lockToTest2"); IOHelper.mkdirs(lockFile.getParentFile()); lockFile.createNewFile(); LockFile underTest = new LockFile(lockFile, true); underTest.lock(); assertTrue("valid", underTest.keepAlive()); underTest.unlock(); assertFalse("file deleted on unlock", lockFile.exists()); } }
private void initialize() { if (!initialized) { initialized = true; if (this.directory == null) { File file = new File(IOHelper.getDefaultDataDirectory()); file = new File(file, IOHelper.toFileSystemSafeName(brokerName) + "-kahastore"); setDirectory(file); } try { IOHelper.mkdirs(this.directory); } catch (IOException e) { throw new RuntimeException(e); } wireFormat.setCacheEnabled(false); wireFormat.setTightEncodingEnabled(true); } }
/** * Converts any string into a string that is safe to use as a file name. The * result will only include ascii characters and numbers, and the "-","_", * and "." characters. * * @param name * @return safe name of the directory */ public static String toFileSystemDirectorySafeName(String name) { return toFileSystemSafeName(name, true, MAX_DIR_NAME_LENGTH); }
IOHelper.mkdirs(file.getParentFile()); synchronized (LockFile.class) { lockSystemPropertyName = getVmLockKey();
protected void openIndexFile() throws IOException { if (indexFile == null) { file = new File(directory, NAME_PREFIX + IOHelper.toFileSystemSafeName(name)); IOHelper.mkdirs(file.getParentFile()); indexFile = new RandomAccessFile(file, "rw"); } }
/** * @return the dataDirectory */ public File getDataDirectory() { if (this.dataDirectory == null) { this.dataDirectory = new File(IOHelper.getDefaultDataDirectory(), IOHelper.toFileSystemSafeName(brokerName)); } return this.dataDirectory; }
public static boolean deleteChildren(File parent) { if (parent == null || !parent.exists()) { return false; } boolean result = true; if (parent.isDirectory()) { File[] files = parent.listFiles(); if (files == null) { result = false; } else { for (int i = 0; i < files.length; i++) { File file = files[i]; if (file.getName().equals(".") || file.getName().equals("..")) { continue; } if (file.isDirectory()) { result &= deleteFile(file); } else { result &= file.delete(); } } } } return result; }
IOHelper.deleteFile(file); IOHelper.copyFile(backFile, file); IOHelper.deleteFile(backFile); openIndexFile(); doLoad();
public synchronized void move(File targetDirectory) throws IOException{ IOHelper.moveFile(file, targetDirectory); }
public static void copySingleFile(File src, File dest) throws IOException { FileInputStream fileSrc = new FileInputStream(src); FileOutputStream fileDest = new FileOutputStream(dest); copyInputStream(fileSrc, fileDest); }
public static void copyFile(File src, File dest) throws IOException { copyFile(src, dest, null); }
public void do_testConcurrentAddIterateRemove(boolean enablePageCache) throws Exception { File directory = store.getDirectory(); store.stop(); IOHelper.mkdirs(directory); IOHelper.deleteChildren(directory); store = createConcurrentAddIterateRemovePListStore(enablePageCache); store.setDirectory(directory);
public static void moveFiles(File srcDirectory, File targetDirectory, FilenameFilter filter) throws IOException { if (!srcDirectory.isDirectory()) { throw new IOException("source is not a directory"); } if (targetDirectory.exists() && !targetDirectory.isDirectory()) { throw new IOException("target exists and is not a directory"); } else { mkdirs(targetDirectory); } List<File> filesToMove = new ArrayList<File>(); getFiles(srcDirectory, filesToMove, filter); for (File file : filesToMove) { if (!file.isDirectory()) { moveFile(file, targetDirectory); } } }
@Test public void testNoDeleteOnUnlockIfNotLocked() throws Exception { File lockFile = new File(IOHelper.getDefaultDataDirectory(), "lockToTest1"); IOHelper.mkdirs(lockFile.getParentFile()); lockFile.createNewFile(); LockFile underTest = new LockFile(lockFile, true); underTest.lock(); // will fail on windows b/c the file is open if ( lockFile.delete() ) { assertFalse("no longer valid", underTest.keepAlive()); // a slave gets in lockFile.createNewFile(); underTest.unlock(); assertTrue("file still exists after unlock when not locked", lockFile.exists()); } }