List of usage examples for org.apache.commons.io FileUtils cleanDirectory
public static void cleanDirectory(File directory) throws IOException
From source file:com.ecofactor.qa.automation.platform.util.FileUtil.java
/** * Delete all files and folder in Folder. The root directory will not be deleted. * @param path the path//from ww w . jav a 2s . co m */ public static void deleteAllFilesInFolder(final String path) { LogUtil.setLogString(new StringBuilder("Delete Files and folders in directory :").append(path).toString(), true); try { FileUtils.cleanDirectory(new File(path)); } catch (IOException e) { LOGGER.error("Error in delete all files in folder", e); } }
From source file:eu.planets_project.services.utils.ZipUtilsTest.java
/** * Test method for {@link eu.planets_project.services.utils.ZipUtils#insertFileInto(java.io.File, java.io.File, java.lang.String)}. * @throws IOException //from w ww .j a v a 2s. c o m */ @Test public void testInsertFile() throws IOException { FileUtils.cleanDirectory(outputFolder); File zip = ZipUtils.createZip(TEST_FILE_FOLDER, outputFolder, "zipUtilsTestInsert.zip", true); System.out.println("Zip created. Please find it here: " + zip.getAbsolutePath()); File toInsert = new File(PROJECT_BASE_FOLDER, "src/test/data/test_zip/docs"); ZipUtils.insertFileInto(zip, toInsert, "docs"); // File modifiedZip = ZipUtils.insertFileInto(zip, toInsert, "images/test_gif"); // File insertMore = new File("tests/test-files/documents/test_pdf/"); // modifiedZip = ZipUtils.insertFileInto(zip, insertMore, "documents/test_pdf"); System.out.println("Zip modified. Please find it here: " + zip.getAbsolutePath()); }
From source file:S3DataManagerTest.java
private void clearSourceDirectory() throws IOException { File zip = new File("/tmp/source.zip"); if (zip.exists()) { FileUtils.deleteQuietly(zip);//from w w w . ja v a 2 s. c o m } File unzipFolder = new File("/tmp/folder"); if (unzipFolder.exists()) { FileUtils.cleanDirectory(unzipFolder); } File src = new File("/tmp/source"); if (src.exists()) { if (src.isDirectory()) { FileUtils.cleanDirectory(src); } else { FileUtils.deleteQuietly(src); } } src.mkdir(); }
From source file:com.github.seqware.queryengine.impl.TmpFileStorage.java
/** {@inheritDoc} */ @Override/*from w w w . ja va 2 s . c om*/ public final void clearStorage() { try { FileUtils.cleanDirectory(tempDir); } catch (IOException ex) { Logger.getLogger(TmpFileStorage.class.getName()).fatal("failed to clear serialization store", ex); } }
From source file:com.roquahacks.semafor4j.FrameNetService.java
public void cleanFNDataFiles() { try {/*ww w.j a v a2 s .com*/ FileUtils.cleanDirectory(new File(FrameNetOptions.ABS_PATH_FNDATA)); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.github.ipaas.ideploy.agent.handler.RollbackCodeHandlerTest.java
/** * , USING_VERSION,? ROLLBACKTO_VERSION * /*from w w w . ja v a 2s . co m*/ * @throws Exception */ @Test public void rollbackCodeTest() throws Exception { String deployRoot = "/www/app" + APP_NAME; File usingfile = new File(deployRoot); RollbackCodeHandler rollback = new RollbackCodeHandler(); String localBkPath = "/www/appbk" + APP_NAME + "/firstVer0"; Map<String, Object> cantRollBackParams = new HashMap<String, Object>(); cantRollBackParams.put("localBkPath", localBkPath); cantRollBackParams.put("deployPath", deployRoot); try { rollback.execute(null, null, cantRollBackParams, null); // : // ,?,?! fail("Created fraction 1/0! That's undefined!"); } catch (Exception e) { assertEquals("?,?!", e.getMessage()); } File localBkFile = new File(localBkPath); if (!localBkFile.exists()) { localBkFile.mkdirs(); } rollback.execute(null, null, cantRollBackParams, null); Integer hostStatus4New = 1; String savePath = "/www/apptemp/" + USING_VERSION; Map<String, Object> firstRollbackParams = new HashMap<String, Object>(); firstRollbackParams.put("usingCodeVerPath", TEST_GROUP + TAGS + "/" + USING_VERSION); firstRollbackParams.put("hostStatus", hostStatus4New); firstRollbackParams.put("savePath", savePath); firstRollbackParams.put("deployPath", deployRoot); rollback.execute(null, null, firstRollbackParams, null); // ,,? DownloadCodeHandler downLoadHandler = new DownloadCodeHandler(); Integer notUpdateAll = 2; Integer hostStatus4Old = 2; Map<String, Object> secondDownLoadParams = new HashMap<String, Object>(); secondDownLoadParams.put("doingCodeVerPath", TEST_GROUP + TAGS + "/" + ROLLBACKTO_VERSION); secondDownLoadParams.put("usingCodeVerPath", TEST_GROUP + TAGS + "/" + USING_VERSION); secondDownLoadParams.put("hostStatus", hostStatus4Old); secondDownLoadParams.put("savePath", "/www/apptemp/rollback_test_vaild");// ?? secondDownLoadParams.put("updateAll", notUpdateAll); downLoadHandler.execute(null, null, secondDownLoadParams, null); File updateFile = new File("/www/apptemp/rollback_test_vaild/update.txt"); List<String> updateList = FileUtils.readLines(updateFile);// ??,? String savePath2 = "/www/apptemp/" + ROLLBACKTO_VERSION; Map<String, Object> secondRollbackParams = new HashMap<String, Object>(); secondRollbackParams.put("usingCodeVerPath", TEST_GROUP + TAGS + "/" + ROLLBACKTO_VERSION); secondRollbackParams.put("doingCodeVerPath", TEST_GROUP + TAGS + "/" + USING_VERSION); secondRollbackParams.put("hostStatus", hostStatus4Old); secondRollbackParams.put("savePath", savePath2); secondRollbackParams.put("deployPath", deployRoot); rollback.execute(null, null, secondRollbackParams, null); // , // ? for (String str : updateList) { if (str.startsWith("+")) { // Assert.assertTrue(new File(deployRoot + StringUtils.removeStart(str, "+").trim()).exists()); } else if (str.startsWith("-")) { // String f = deployRoot + StringUtils.removeStart(str, "-").trim(); Assert.assertFalse(new File(f).exists()); } } FileUtils.cleanDirectory(usingfile); FileUtils.forceDelete(localBkFile); FileUtils.cleanDirectory(new File("/www/apptemp")); }
From source file:com.github.neio.filesystem.paths.TestDirectoryPath.java
@After public void after() throws IOException { FileUtils.cleanDirectory(testDir); }
From source file:main.java.miro.validator.fetcher.RsyncFetcher.java
private void setupDirectories() throws IOException { File baseDirFile = new File(baseDirectory); FileUtils.forceMkdir(baseDirFile);/*from ww w . j ava 2s .c o m*/ FileUtils.cleanDirectory(baseDirFile); prefetchURIstorage.getParentFile().mkdirs(); prefetchURIstorage.createNewFile(); }
From source file:net.sourceforge.jweb.maven.mojo.InWarMinifyMojo.java
public void execute() throws MojoExecutionException, MojoFailureException { if (disabled) return;/* ww w. j a v a 2s . c om*/ processConfiguration(); String name = this.getBuilddir().getAbsolutePath() + File.separator + this.getFinalName() + "." + this.getPacking(); this.getLog().info(name); MinifyFileFilter fileFilter = new MinifyFileFilter(); int counter = 0; try { File finalWarFile = new File(name); File tempFile = File.createTempFile(finalWarFile.getName(), null); tempFile.delete();//check deletion boolean renameOk = finalWarFile.renameTo(tempFile); if (!renameOk) { getLog().error("Can not rename file, please check."); } ZipOutputStream out = new ZipOutputStream(new FileOutputStream(finalWarFile)); ZipFile zipFile = new ZipFile(tempFile); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); //no compress, just transfer to war if (!fileFilter.accept(entry)) { getLog().debug("nocompress entry: " + entry.getName()); out.putNextEntry(entry); InputStream inputStream = zipFile.getInputStream(entry); byte[] buf = new byte[512]; int len = -1; while ((len = inputStream.read(buf)) > 0) { out.write(buf, 0, len); } inputStream.close(); continue; } File sourceTmp = new File(FileUtils.getUserDirectoryPath() + File.separator + ".mvntmp" + File.separator + counter + ".tmp"); File destTmp = new File(FileUtils.getUserDirectoryPath() + File.separator + ".mvntmp" + File.separator + counter + ".min.tmp"); FileUtils.writeStringToFile(sourceTmp, ""); FileUtils.writeStringToFile(destTmp, ""); //assemble arguments String[] provied = getYuiArguments(); int length = (provied == null ? 0 : provied.length); length += 5; int i = 0; String[] ret = new String[length]; ret[i++] = "--type"; ret[i++] = (entry.getName().toLowerCase().endsWith(".css") ? "css" : "js"); if (provied != null) { for (String s : provied) { ret[i++] = s; } } ret[i++] = sourceTmp.getAbsolutePath(); ret[i++] = "-o"; ret[i++] = destTmp.getAbsolutePath(); try { InputStream in = zipFile.getInputStream(entry); FileUtils.copyInputStreamToFile(in, sourceTmp); in.close(); YUICompressorNoExit.main(ret); } catch (Exception e) { this.getLog().warn("compress error, this file will not be compressed:" + buildStack(e)); FileUtils.copyFile(sourceTmp, destTmp); } out.putNextEntry(new ZipEntry(entry.getName())); InputStream compressedIn = new FileInputStream(destTmp); byte[] buf = new byte[512]; int len = -1; while ((len = compressedIn.read(buf)) > 0) { out.write(buf, 0, len); } compressedIn.close(); String sourceSize = decimalFormat.format(sourceTmp.length() * 1.0d / 1024) + " KB"; String destSize = decimalFormat.format(destTmp.length() * 1.0d / 1024) + " KB"; getLog().info("compressed entry:" + entry.getName() + " [" + sourceSize + " ->" + destSize + "/" + numberFormat.format(1 - destTmp.length() * 1.0d / sourceTmp.length()) + "]"); counter++; } zipFile.close(); out.close(); FileUtils.cleanDirectory(new File(FileUtils.getUserDirectoryPath() + File.separator + ".mvntmp")); FileUtils.forceDelete(new File(FileUtils.getUserDirectoryPath() + File.separator + ".mvntmp")); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.vsquaresystem.safedeals.readyreckoner.ReadyReckonerService.java
private boolean saveToDatabase(Vector dataHolder) throws IOException { readyReckonerDAL.truncateAll();/* w ww . j a v a2 s. c o m*/ dataHolder.remove(0); Readyreckoner readyReckoner = new Readyreckoner(); String id = ""; String locationId = ""; String rrYear = ""; String rrRateLand = ""; String rrRatePlot = ""; String rrRateApartment = ""; System.out.println(dataHolder); DataFormatter formatter = new DataFormatter(); for (Iterator iterator = dataHolder.iterator(); iterator.hasNext();) { List list = (List) iterator.next(); logger.info("list", list); locationId = list.get(1).toString(); rrYear = list.get(2).toString(); rrRateLand = list.get(3).toString(); rrRatePlot = list.get(4).toString(); rrRateApartment = list.get(5).toString(); try { readyReckoner.setLocationId(Integer.parseInt(locationId)); readyReckoner.setRrYear(Double.parseDouble(rrYear)); readyReckoner.setRrRateLand(Double.parseDouble(rrRateLand)); readyReckoner.setRrRatePlot(Double.parseDouble(rrRatePlot)); readyReckoner.setRrRateApartment(Double.parseDouble(rrRateApartment)); readyReckonerDAL.insert(readyReckoner); } catch (Exception e) { e.printStackTrace(); } } File excelFile = attachmentUtils .getDirectoryByAttachmentType(AttachmentUtils.AttachmentType.READY_RECKONER); FileUtils.cleanDirectory(excelFile); return true; }