List of usage examples for org.apache.commons.io FileUtils cleanDirectory
public static void cleanDirectory(File directory) throws IOException
From source file:com.codejumble.osbfa.attacker.CombinationFinder.java
/** * Initializes the combination finder with the charsets to be used. * * @param mainFrame Main frame of the application * @param options Preferences of the user * @param maxPasswordLength maximum key size * @param amountOfThreads number of threads * @param zipFile Zipfile to be attacked *///from ww w . ja va 2 s . co m public CombinationFinder(Main mainFrame, List<String> options, int minPasswordLength, int maxPasswordLength, int amountOfThreads, ZipFile zipFile) { tmpFolder = new File("tmp"); try { FileUtils.cleanDirectory(tmpFolder); } catch (IOException ex) { mainFrame.createErrorDialog(mainFrame, "Error", ex.getMessage()); } CombinationFinder.mainFrame = mainFrame; alreadyTriedCombinations = 0; done = false; this.options = options; createEndCharSet(); maxPasswordSize = maxPasswordLength; minPasswordSize = minPasswordLength; totalNumberOfCombinations = (long) Math.pow(endCharSet.length, maxPasswordSize); mainFrame.appendToMainLog("Number of possible combinations: " + getTotalNumberOfCombinations()); combinations = new ArrayList<String>(); miners = new ArrayList<CombinationExploiter>(); for (int i = 0; i < amountOfThreads; i++) { mainFrame.appendToMainLog("Adding exploiter thread number " + (i + 1)); File destFile = new File(tmpFolder.getAbsolutePath().concat(File.separator + i)); miners.add(new CombinationExploiter(this, zipFile, destFile)); } }
From source file:com.legstar.jaxb.AbstractJaxbGenTest.java
/** * Make sure we have an output folder./*from ww w.ja va2 s . co m*/ * * @throws Exception if output folder cannot be created */ public void setUp() throws Exception { CodeGenUtil.checkDirectory(GEN_SRC_DIR, true); FileUtils.cleanDirectory(GEN_SRC_DIR); CodeGenUtil.checkDirectory(GEN_XJB_DIR, true); FileUtils.cleanDirectory(GEN_XJB_DIR); DocumentBuilderFactory docFac = DocumentBuilderFactory.newInstance(); docFac.setNamespaceAware(true); _db = docFac.newDocumentBuilder(); }
From source file:com.legstar.cob2xsd.AbstractXsdTester.java
/** {@inheritDoc} */ public void setUp() throws Exception { _docFac = DocumentBuilderFactory.newInstance(); _docFac.setNamespaceAware(true);/* w ww .j av a 2s . co m*/ _docFac.setValidating(false); _docFac.setIgnoringElementContentWhitespace(true); _docFac.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); _docFac.setAttribute(JAXP_SCHEMA_SOURCE, W3C_XML_SCHEMA_SOURCE); _docBuilder = _docFac.newDocumentBuilder(); GEN_XSD_DIR.mkdirs(); FileUtils.cleanDirectory(GEN_XSD_DIR); GEN_ANT_DIR.mkdirs(); FileUtils.cleanDirectory(GEN_ANT_DIR); }
From source file:com.buddycloud.mediaserver.download.DownloadMediasInfoTest.java
private void deleteFile(String id) throws Exception { FileUtils.cleanDirectory( new File(configuration.getProperty(MediaServerConfiguration.MEDIA_STORAGE_ROOT_PROPERTY) + File.separator + BASE_CHANNEL)); dataSource.deleteMedia(MEDIA_ID);/*from w w w .j ava 2s. c o m*/ }
From source file:com.assemblade.opendj.OpenDJUtils.java
public static DirectoryEnvironmentConfig buildEnvironmentConfig(String rootDirectory) throws IOException, InitializationException { DirectoryEnvironmentConfig config = new DirectoryEnvironmentConfig(); File serverRoot = new File(rootDirectory); if (!serverRoot.exists()) { initializeDatastore(rootDirectory); }// w w w .j a va 2s .com config.setServerRoot(serverRoot); config.setMaintainConfigArchive(false); config.setDisableConnectionHandlers(true); config.setForceDaemonThreads(true); if (!config.getLockDirectory().exists()) { initializeDatastore(rootDirectory); } FileUtils.cleanDirectory(config.getLockDirectory()); return config; }
From source file:de.burlov.amazon.s3.dirsync.test.TestDirSync.java
private void createTestData(File baseDir, int fileAmount, int medianSize) throws IOException { if (baseDir.exists()) { FileUtils.cleanDirectory(baseDir); }//w w w. j a va 2 s . c om for (int i = 0; i < fileAmount; i++) { int count = RandomUtils.nextInt(512); String filename = RandomStringUtils.random(count, "1234567890/"); count = RandomUtils.nextInt(medianSize); byte[] data = new byte[count]; new Random().nextBytes(data); File file = new File(baseDir, filename); file.getParentFile().mkdirs(); OutputStream out = FileUtils.openOutputStream(file); out.write(data); out.close(); } }
From source file:appeng.core.RecipeLoader.java
@Override public final void run() { if (this.config.isEnabled()) { // setup copying final RecipeResourceCopier copier = new RecipeResourceCopier("assets/appliedenergistics2/recipes/"); final File generatedRecipesDir = new File(this.recipeDirectory, "generated"); final File userRecipesDir = new File(this.recipeDirectory, "user"); // generates generated and user recipes dir // will clean the generated every time to keep it up to date // copies over the recipes in the jar over to the generated folder // copies over the readmes try {/*from w w w.j a va2s . c om*/ FileUtils.forceMkdir(generatedRecipesDir); FileUtils.forceMkdir(userRecipesDir); FileUtils.cleanDirectory(generatedRecipesDir); copier.copyTo(".recipe", generatedRecipesDir); copier.copyTo(".html", this.recipeDirectory); // parse recipes prioritising the user scripts by using the generated as template this.handler.parseRecipes(new ConfigLoader(generatedRecipesDir, userRecipesDir), "index.recipe"); } // on failure use jar parsing catch (final IOException e) { AELog.debug(e); this.handler.parseRecipes(new JarLoader(ASSETS_RECIPE_PATH), "index.recipe"); } catch (final URISyntaxException e) { AELog.debug(e); this.handler.parseRecipes(new JarLoader(ASSETS_RECIPE_PATH), "index.recipe"); } } else { this.handler.parseRecipes(new JarLoader(ASSETS_RECIPE_PATH), "index.recipe"); } }
From source file:com.jagornet.dhcp.db.BaseTestCase.java
public BaseTestCase(String schemaType, int schemaVersion) { DhcpServerConfiguration.configFilename = configFilename; if (config == null) { try {/*from w ww .j a va2s.c o m*/ config = DhcpServerConfiguration.getInstance(); DhcpServerPolicies.setProperty(Property.DATABASE_SCHEMA_TYTPE, schemaType); DhcpServerPolicies.setProperty(Property.DATABASE_SCHEMA_VERSION, Integer.toString(schemaVersion)); if (schemaType.contains("derby")) { // start with a fresh database System.out.println("Cleaning db/derby..."); FileUtils.cleanDirectory(new File("db/derby")); } else if (schemaType.contains("h2")) { // start with a fresh database System.out.println("Cleaning db/h2..."); FileUtils.cleanDirectory(new File("db/h2")); } else if (schemaType.contains("sqlite")) { // start with a fresh database System.out.println("Cleaning db/sqlite..."); FileUtils.cleanDirectory(new File("db/sqlite")); } String[] appContext = JagornetDhcpServer.getAppContextFiles(schemaType, schemaVersion); ctx = new ClassPathXmlApplicationContext(appContext); IaManager iaMgr = (IaManager) ctx.getBean("iaManager"); iaMgr.init(); config.setIaMgr(iaMgr); V6NaAddrBindingManager v6NaAddrBindingMgr = (V6NaAddrBindingManager) ctx .getBean("v6NaAddrBindingManager"); v6NaAddrBindingMgr.init(); config.setNaAddrBindingMgr(v6NaAddrBindingMgr); V6TaAddrBindingManager v6TaAddrBindingMgr = (V6TaAddrBindingManager) ctx .getBean("v6TaAddrBindingManager"); v6TaAddrBindingMgr.init(); config.setTaAddrBindingMgr(v6TaAddrBindingMgr); V6PrefixBindingManager v6PrefixBindingMgr = (V6PrefixBindingManager) ctx .getBean("v6PrefixBindingManager"); v6PrefixBindingMgr.init(); config.setPrefixBindingMgr(v6PrefixBindingMgr); V4AddrBindingManager v4AddrBindingMgr = (V4AddrBindingManager) ctx.getBean("v4AddrBindingManager"); v4AddrBindingMgr.init(); config.setV4AddrBindingMgr(v4AddrBindingMgr); } catch (Exception e) { throw new RuntimeException(e); } } }
From source file:net.rptools.lib.image.ThumbnailManager.java
public void clearImageThumbCache() { try {/*from ww w . jav a2 s . co m*/ if (thumbnailLocation != null) { FileUtils.cleanDirectory(thumbnailLocation); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.alibaba.jstorm.daemon.supervisor.Supervisor.java
/** * create and start one supervisor//from ww w .ja v a 2s. c om * * @param conf : configurationdefault.yaml storm.yaml * @param sharedContext : null (right now) * @return SupervisorManger: which is used to shutdown all workers and supervisor */ @SuppressWarnings("rawtypes") public SupervisorManger mkSupervisor(Map conf, IContext sharedContext) throws Exception { LOG.info("Starting Supervisor with conf " + conf); /** * Step 1: cleanup all files in /storm-local-dir/supervisor/tmp */ String path = StormConfig.supervisorTmpDir(conf); FileUtils.cleanDirectory(new File(path)); /* * Step 2: create ZK operation instance StromClusterState */ StormClusterState stormClusterState = Cluster.mk_storm_cluster_state(conf); String hostName = JStormServerUtils.getHostName(conf); WorkerReportError workerReportError = new WorkerReportError(stormClusterState, hostName); /* * Step 3, create LocalStat LocalStat is one KV database 4.1 create LocalState instance; 4.2 get supervisorId, if no supervisorId, create one */ LocalState localState = StormConfig.supervisorState(conf); String supervisorId = (String) localState.get(Common.LS_ID); if (supervisorId == null) { supervisorId = UUID.randomUUID().toString(); localState.put(Common.LS_ID, supervisorId); } Vector<AsyncLoopThread> threads = new Vector<AsyncLoopThread>(); // Step 5 create HeartBeat // every supervisor.heartbeat.frequency.secs, write SupervisorInfo to ZK // sync hearbeat to nimbus Heartbeat hb = new Heartbeat(conf, stormClusterState, supervisorId); hb.update(); AsyncLoopThread heartbeat = new AsyncLoopThread(hb, false, null, Thread.MIN_PRIORITY, true); threads.add(heartbeat); // Sync heartbeat to Apsara Container AsyncLoopThread syncContainerHbThread = SyncContainerHb.mkSupervisorInstance(conf); if (syncContainerHbThread != null) { threads.add(syncContainerHbThread); } // Step 6 create and start sync Supervisor thread // every supervisor.monitor.frequency.secs second run SyncSupervisor EventManagerImp processEventManager = new EventManagerImp(); AsyncLoopThread processEventThread = new AsyncLoopThread(processEventManager); threads.add(processEventThread); ConcurrentHashMap<String, String> workerThreadPids = new ConcurrentHashMap<String, String>(); SyncProcessEvent syncProcessEvent = new SyncProcessEvent(supervisorId, conf, localState, workerThreadPids, sharedContext, workerReportError); EventManagerImp syncSupEventManager = new EventManagerImp(); AsyncLoopThread syncSupEventThread = new AsyncLoopThread(syncSupEventManager); threads.add(syncSupEventThread); SyncSupervisorEvent syncSupervisorEvent = new SyncSupervisorEvent(supervisorId, conf, processEventManager, syncSupEventManager, stormClusterState, localState, syncProcessEvent, hb); int syncFrequence = JStormUtils.parseInt(conf.get(Config.SUPERVISOR_MONITOR_FREQUENCY_SECS)); EventManagerPusher syncSupervisorPusher = new EventManagerPusher(syncSupEventManager, syncSupervisorEvent, syncFrequence); AsyncLoopThread syncSupervisorThread = new AsyncLoopThread(syncSupervisorPusher); threads.add(syncSupervisorThread); Httpserver httpserver = null; if (StormConfig.local_mode(conf) == false) { // Step 7 start httpserver int port = ConfigExtension.getSupervisorDeamonHttpserverPort(conf); httpserver = new Httpserver(port, conf); httpserver.start(); } // SupervisorManger which can shutdown all supervisor and workers return new SupervisorManger(conf, supervisorId, threads, syncSupEventManager, processEventManager, httpserver, stormClusterState, workerThreadPids); }