@Override public void delete() { base.delete(); }
/** * Delete a file or directory if it exists. * Directories may only be deleted if they are empty. * This method is similar to Java 7 * <code>java.nio.file.Path.deleteIfExists</code>. * * @param path the file or directory name */ public static void delete(String path) { FilePath.get(path).delete(); }
/** * Try to delete a file (ignore errors). * * @param fileName the file name * @return true if it worked */ public static boolean tryDelete(String fileName) { try { FilePath.get(fileName).delete(); return true; } catch (Exception e) { return false; } }
@Override public void delete() { for (int i = 0;; i++) { FilePath f = getBase(i); if (f.exists()) { f.delete(); } else { break; } } }
@Override public FileChannel truncate(long newLength) throws IOException { if (newLength >= length) { return this; } filePointer = Math.min(filePointer, newLength); int newFileCount = 1 + (int) (newLength / maxLength); if (newFileCount < list.length) { // delete some of the files FileChannel[] newList = new FileChannel[newFileCount]; // delete backwards, so that truncating is somewhat transactional for (int i = list.length - 1; i >= newFileCount; i--) { // verify the file is writable list[i].truncate(0); list[i].close(); try { file.getBase(i).delete(); } catch (DbException e) { throw DbException.convertToIOException(e); } } System.arraycopy(list, 0, newList, 0, newList.length); list = newList; } long size = newLength - maxLength * (newFileCount - 1); list[list.length - 1].truncate(size); this.length = newLength; return this; }
AOStorage(Map<String, Object> config) { super(config); this.db = (IDatabase) config.get("db"); String storagePath = getStoragePath(); DataUtils.checkArgument(storagePath != null, "The storage path may not be null"); if (!FileUtils.exists(storagePath)) FileUtils.createDirectories(storagePath); FilePath dir = FilePath.get(storagePath); for (FilePath fp : dir.newDirectoryStream()) { String mapFullName = fp.getName(); if (mapFullName.startsWith(TEMP_NAME_PREFIX)) { fp.delete(); } } }