Refine search
java.nio.file.Path parent = target.getParentFile().toPath(); java.nio.file.Path targetPath = target.toPath(); Files.createFile(target.toPath()); try (FileWriter fw = new FileWriter(target)) { fw.write(json); Files.delete(new File(webOverviewDir, jobID + JSON_FILE_ENDING).toPath()); } catch (IOException ioe) { LOG.debug("Could not delete file from overview directory.", ioe);
/** * Deletes file in the storage directory that match the given predicate. */ private void deleteFiles(Predicate<File> predicate) { directory.mkdirs(); // Iterate through all files in the storage directory. for (File file : directory.listFiles(f -> f.isFile() && predicate.test(f))) { try { Files.delete(file.toPath()); } catch (IOException e) { // Ignore the exception. } } }
/** * Cleanup checkpoint directory from all temporary files. */ @Override public void cleanupTempCheckpointDirectory() throws IgniteCheckedException { try { try (DirectoryStream<Path> files = Files.newDirectoryStream(cpDir.toPath(), TMP_FILE_MATCHER::matches)) { for (Path path : files) Files.delete(path); } } catch (IOException e) { throw new IgniteCheckedException("Failed to cleanup checkpoint directory from temporary files: " + cpDir, e); } }
/** * Removes the specified directory. * * @param path Path to the directory. */ public static void deleteDirectory(Path path) { File file = path.toFile(); if (file.isDirectory()) { File[] children = file.listFiles(); if (children != null) { for (File child : children) deleteDirectory(child.toPath()); } } try { Files.delete(path); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Deletes a file, never throwing an exception. If file is a directory, delete it and all sub-directories. * <p> * The difference between File.delete() and this method are: * <ul> * <li>A directory to be deleted does not have to be empty.</li> * <li>No exceptions are thrown when a file or directory cannot be deleted.</li> * </ul> * * @param file file or directory to delete, can be {@code null} * @return {@code true} if the file or directory was deleted, otherwise {@code false} */ public static boolean deleteQuietly(@Nullable File file) { if (file == null) { return false; } try { if (file.isDirectory()) { deleteDirectory(file); } else { Files.delete(file.toPath()); } return true; } catch (IOException | SecurityException ignored) { return false; } }
/** * Removes checkpoint start/end files belongs to given {@code cpEntry}. * * @param cpEntry Checkpoint entry. * * @throws IgniteCheckedException If failed to delete. */ private void removeCheckpointFiles(CheckpointEntry cpEntry) throws IgniteCheckedException { Path startFile = new File(cpDir.getAbsolutePath(), checkpointFileName(cpEntry, CheckpointEntryType.START)).toPath(); Path endFile = new File(cpDir.getAbsolutePath(), checkpointFileName(cpEntry, CheckpointEntryType.END)).toPath(); try { if (Files.exists(startFile)) Files.delete(startFile); if (Files.exists(endFile)) Files.delete(endFile); } catch (IOException e) { throw new StorageException("Failed to delete stale checkpoint files: " + cpEntry, e); } }
/** {@inheritDoc} */ @Override public void cleanupPersistentSpace(CacheConfiguration cacheConfiguration) throws IgniteCheckedException { try { File cacheWorkDir = cacheWorkDir(cacheConfiguration); if(!cacheWorkDir.exists()) return; try (DirectoryStream<Path> files = newDirectoryStream(cacheWorkDir.toPath(), new DirectoryStream.Filter<Path>() { @Override public boolean accept(Path entry) throws IOException { return entry.toFile().getName().endsWith(FILE_SUFFIX); } })) { for (Path path : files) delete(path); } } catch (IOException e) { throw new IgniteCheckedException("Failed to cleanup persistent directory: ", e); } }