List of usage examples for org.apache.commons.io FileUtils cleanDirectory
public static void cleanDirectory(File directory) throws IOException
From source file:org.finra.herd.tools.common.databridge.AbstractDataBridgeTest.java
/** * Uploads and registers a version if of the test business object data that will be used as a parent. * * @param s3KeyPrefix the destination S3 key prefix that must comply with the S3 naming conventions including the expected data version value * @param dataBridgeWebClient the databridge web client instance *//*from w ww .ja va2 s . com*/ protected void uploadAndRegisterTestDataParent(String s3KeyPrefix, DataBridgeWebClient dataBridgeWebClient) throws Exception { uploadTestDataFilesToS3(s3KeyPrefix, testManifestFiles, new ArrayList<String>()); UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto( TEST_PARENT_PARTITION_VALUE, TEST_SUB_PARTITION_VALUES, false); S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = getTestS3FileTransferRequestParamsDto(); s3FileTransferRequestParamsDto.setS3KeyPrefix(s3KeyPrefix + "/"); BusinessObjectData businessObjectData = dataBridgeWebClient .preRegisterBusinessObjectData(uploaderInputManifestDto, StorageEntity.MANAGED_STORAGE, true); BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper .getBusinessObjectDataKey(businessObjectData); dataBridgeWebClient.addStorageFiles(businessObjectDataKey, uploaderInputManifestDto, s3FileTransferRequestParamsDto, StorageEntity.MANAGED_STORAGE); dataBridgeWebClient.updateBusinessObjectDataStatus(businessObjectDataKey, BusinessObjectDataStatusEntity.VALID); // Clean up the local input directory used for the test data files upload. FileUtils.cleanDirectory(LOCAL_TEMP_PATH_INPUT.toFile()); }
From source file:org.finra.herd.tools.downloader.AbstractDownloaderTest.java
/** * Uploads and registers a version if of the test business object data with the specified data files. * * @param s3KeyPrefix the destination S3 key prefix that must comply with the S3 naming conventions including the expected data version value * @param manifestFiles the test data files to be uploaded to S3 and registered * @param directoryPaths the list of directory paths to be created in S3 relative to the S3 key prefix *///w w w. j av a2s . co m protected void uploadAndRegisterTestData(String s3KeyPrefix, List<ManifestFile> manifestFiles, List<String> directoryPaths) throws Exception { uploadTestDataFilesToS3(s3KeyPrefix, manifestFiles, directoryPaths); UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto(); uploaderInputManifestDto.setManifestFiles(manifestFiles); S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = getTestS3FileTransferRequestParamsDto(); s3FileTransferRequestParamsDto.setS3KeyPrefix(s3KeyPrefix + "/"); BusinessObjectData businessObjectData = downloaderWebClient .preRegisterBusinessObjectData(uploaderInputManifestDto, StorageEntity.MANAGED_STORAGE, false); BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper .getBusinessObjectDataKey(businessObjectData); downloaderWebClient.addStorageFiles(businessObjectDataKey, uploaderInputManifestDto, s3FileTransferRequestParamsDto, StorageEntity.MANAGED_STORAGE); downloaderWebClient.updateBusinessObjectDataStatus(businessObjectDataKey, BusinessObjectDataStatusEntity.VALID); // Clean up the local input directory used for the test data files upload. FileUtils.cleanDirectory(LOCAL_TEMP_PATH_INPUT.toFile()); }
From source file:org.gatherdata.alert.dao.neo4j.NeoAlertServiceDaoTest.java
@After public void shutdownNeo() { String neoStoreDir = ((EmbeddedNeo) neo.neo()).getStoreDir(); neo.manualShutdown();/*from w w w.j a va 2 s . co m*/ try { FileUtils.cleanDirectory(new File(neoStoreDir)); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.geoserver.rest.util.RESTUtils.java
/** * Reads content from the body of a request and writes it to a file. * //ww w. j a va 2 s. c om * @param fileName The name of the file to write out. * @param directory The directory to write the file to. * @param deleteDirectoryContent Delete directory content if the file already exists. * @param request The request. * * @return The file object representing the newly written file. * * @throws IOException Any I/O errors that occur. * * TODO: move this to IOUtils. */ public static File handleBinUpload(String fileName, File directory, boolean deleteDirectoryContent, Request request) throws IOException { final File newFile = new File(directory, fileName); if (newFile.exists()) { if (deleteDirectoryContent) { FileUtils.cleanDirectory(directory); } else { // delete the file, otherwise replacing it with a smaller one will leave bytes at the end newFile.delete(); } } final ReadableByteChannel source = request.getEntity().getChannel(); RandomAccessFile raf = null; FileChannel outputChannel = null; try { raf = new RandomAccessFile(newFile, "rw"); outputChannel = raf.getChannel(); IOUtils.copyChannel(1024 * 1024, source, outputChannel); } finally { try { if (raf != null) { raf.close(); } } finally { IOUtils.closeQuietly(source); IOUtils.closeQuietly(outputChannel); } } return newFile; }
From source file:org.gradle.api.internal.tasks.cache.OutputPreparingTaskOutputPacker.java
@Override public void unpack(TaskOutputsInternal taskOutputs, InputStream input) throws IOException { for (TaskOutputFilePropertySpec propertySpec : taskOutputs.getFileProperties()) { CacheableTaskOutputFilePropertySpec property = (CacheableTaskOutputFilePropertySpec) propertySpec; File output = property.getOutputFile(); if (output == null) { continue; }//w w w . jav a 2 s . c o m switch (property.getOutputType()) { case DIRECTORY: makeDirectory(output); FileUtils.cleanDirectory(output); break; case FILE: if (!makeDirectory(output.getParentFile())) { if (output.exists()) { FileUtils.forceDelete(output); } } break; default: throw new AssertionError(); } } delegate.unpack(taskOutputs, input); }
From source file:org.gradle.caching.internal.packaging.impl.PackerDirectoryUtil.java
public static void ensureDirectoryForTree(TreeType type, File root) throws IOException { switch (type) { case DIRECTORY: if (!makeDirectory(root)) { FileUtils.cleanDirectory(root); }//from ww w.j a v a 2s. c o m break; case FILE: if (!makeDirectory(root.getParentFile())) { if (root.exists()) { FileUtils.forceDelete(root); } } break; default: throw new AssertionError(); } }
From source file:org.gradle.caching.internal.tasks.OutputPreparingTaskOutputPacker.java
@Override public void unpack(TaskOutputsInternal taskOutputs, InputStream input, TaskOutputOriginReader readOrigin) { for (TaskOutputFilePropertySpec propertySpec : taskOutputs.getFileProperties()) { CacheableTaskOutputFilePropertySpec property = (CacheableTaskOutputFilePropertySpec) propertySpec; File output = property.getOutputFile(); if (output == null) { continue; }/*from www. jav a 2 s . c om*/ try { switch (property.getOutputType()) { case DIRECTORY: makeDirectory(output); FileUtils.cleanDirectory(output); break; case FILE: if (!makeDirectory(output.getParentFile())) { if (output.exists()) { FileUtils.forceDelete(output); } } break; default: throw new AssertionError(); } } catch (IOException e) { throw new UncheckedIOException(e); } } delegate.unpack(taskOutputs, input, readOrigin); }
From source file:org.gradle.caching.internal.tasks.TaskOutputPackerUtils.java
public static void ensureDirectoryForProperty(OutputType outputType, File specRoot) throws IOException { switch (outputType) { case DIRECTORY: if (!makeDirectory(specRoot)) { FileUtils.cleanDirectory(specRoot); }/* w w w . jav a 2 s . com*/ break; case FILE: if (!makeDirectory(specRoot.getParentFile())) { if (specRoot.exists()) { FileUtils.forceDelete(specRoot); } } break; default: throw new AssertionError(); } }
From source file:org.gradle.plugin.devel.tasks.GeneratePluginDescriptors.java
private void clearOutputDirectory() { try {//from w w w .j ava 2 s .c om FileUtils.cleanDirectory(getOutputDirectory()); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:org.gradle.util.GFileUtils.java
public static void cleanDirectory(File directory) { try {//from w ww . j a v a 2s . com FileUtils.cleanDirectory(directory); } catch (IOException e) { throw new UncheckedIOException(e); } }