List of usage examples for org.apache.commons.io FileUtils forceMkdir
public static void forceMkdir(File directory) throws IOException
From source file:com.github.neio.filesystem.paths.DirectoryPath.java
@Override public void mkdir() throws FilesystemException { try {//from w w w. j a v a 2 s . c o m FileUtils.forceMkdir(platformDirectory); } catch (IOException e) { throw new FilesystemException("Unable to make directory [" + super.getPath() + "]", e); } }
From source file:com.bbc.remarc.servlet.ResourceServletContextListener.java
private void createResourceFolders(String resourcesPath) { log.debug("checking resource internal folders..."); File audioDir = new File(resourcesPath + Configuration.CONTENT_DIR + Configuration.AUDIO_DIR_NAME); File imagesDir = new File(resourcesPath + Configuration.CONTENT_DIR + Configuration.IMAGE_DIR_NAME); File videoDir = new File(resourcesPath + Configuration.CONTENT_DIR + Configuration.VIDEO_DIR_NAME); File uploadDir = new File(resourcesPath + Configuration.UPLOAD_DIR_NAME); try {//from ww w. ja v a 2 s . com // create the audio, images, video and upload folders if (!audioDir.exists()) { FileUtils.forceMkdir(audioDir); log.debug("audio folder created"); } ; if (!imagesDir.exists()) { FileUtils.forceMkdir(imagesDir); log.debug("images folder created"); } ; if (!videoDir.exists()) { FileUtils.forceMkdir(videoDir); log.debug("video folder created"); } ; if (!uploadDir.exists()) { FileUtils.forceMkdir(uploadDir); log.debug("upload folder created"); } ; } catch (IOException e) { log.error("Error creating resources content folders, may lead to unexpected behaviour: " + e); } }
From source file:ml.shifu.shifu.actor.EvalModelActorTest.java
public void testActor() throws IOException, InterruptedException { Environment.setProperty(Environment.SHIFU_HOME, "."); File tmpModels = new File("models"); File tmpCommon = new File("common"); File models = new File("src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/models"); FileUtils.copyDirectory(models, tmpModels); File tmpEvalA = new File("evals"); FileUtils.forceMkdir(tmpEvalA); ActorRef modelEvalRef = actorSystem.actorOf(new Props(new UntypedActorFactory() { private static final long serialVersionUID = -1437127862571741369L; public UntypedActor create() { return new EvalModelActor(modelConfig, columnConfigList, new AkkaExecStatus(true), evalConfig); }// w ww . j a v a 2s. c om }), "model-evaluator"); List<Scanner> scanners = ShifuFileUtils.getDataScanners( "src/test/resources/example/cancer-judgement/DataStore/EvalSet1", SourceType.LOCAL); modelEvalRef.tell(new AkkaActorInputMessage(scanners), modelEvalRef); while (!modelEvalRef.isTerminated()) { Thread.sleep(5000); } File outputFile = new File("evals/EvalA/EvalScore"); Assert.assertTrue(outputFile.exists()); FileUtils.deleteDirectory(tmpModels); FileUtils.deleteDirectory(tmpCommon); FileUtils.deleteDirectory(tmpEvalA); }
From source file:com.blockwithme.longdb.leveldb.LevelDBBackend.java
@Override protected LevelDBDatabase createDatabaseInternal(final String theDBName) { try {/*from w w w . j ava2s . c om*/ final File dataRoot = new File(rootFolder); if (!dataRoot.exists()) FileUtils.forceMkdir(dataRoot); final File databaseDir = new File(dataRoot.getAbsolutePath() + File.separator + theDBName); FileUtils.forceMkdir(databaseDir); final LevelDBDatabase bdb = new LevelDBDatabase(this, databaseDir, theDBName); return bdb; } catch (final IOException e) { throw new DBException("Error creating connection: " + theDBName, e); } }
From source file:com.norconex.collector.core.data.store.impl.mapdb.MapDBCrawlDataStore.java
public MapDBCrawlDataStore(String path, boolean resume, Serializer<ICrawlData> valueSerializer) { super();//from ww w .j av a 2s. co m this.valueSerializer = valueSerializer; this.path = path; LOG.info("Initializing reference store " + path); try { FileUtils.forceMkdir(new File(path)); } catch (IOException e) { throw new CrawlDataStoreException("Cannot create crawl data store directory: " + path, e); } File dbFile = new File(path + "/mapdb"); boolean create = !dbFile.exists() || !dbFile.isFile(); // Configure and open database this.db = createDB(dbFile); initDB(create); if (resume) { if (LOG.isDebugEnabled()) { LOG.debug("Active count: " + active.size()); LOG.debug("Cache count: " + cache.size()); LOG.debug("Processed valid count: " + processedValid.size()); LOG.debug("Processed invalid count: " + processedInvalid.size()); LOG.debug(path + " Putting active URLs back in the queue..."); } for (ICrawlData crawlData : active.values()) { queue.add(crawlData); } LOG.debug(path + ": Cleaning active database..."); active.clear(); } else if (!create) { LOG.debug(path + ": Cleaning queue database..."); queue.clear(); LOG.debug(path + ": Cleaning active database..."); active.clear(); LOG.debug(path + ": Cleaning invalid URLs database..."); processedInvalid.clear(); LOG.debug(path + ": Cleaning cache database..."); db.delete(STORE_CACHE); LOG.debug(path + ": Caching valid URLs from last run (if applicable)..."); db.rename(STORE_PROCESSED_VALID, STORE_CACHE); cache = processedValid; processedValid = db.createHashMap(STORE_PROCESSED_VALID).counterEnable().make(); db.commit(); } else { LOG.debug(path + ": New databases created."); } LOG.info(path + ": Done initializing databases."); }
From source file:com.mediaworx.ziputils.Zipper.java
/** * Creates a new zip file./*w w w .ja v a2 s.c o m*/ * @param zipFilename filename for the zip * @param zipTargetFolderPath path of the target folder where the zip should be stored (it will be created if it * doesn't exist) * @throws IOException Exceptions from the underlying package framework are bubbled up */ public Zipper(String zipFilename, String zipTargetFolderPath) throws IOException { File targetFolder = new File(zipTargetFolderPath); if (!targetFolder.exists()) { FileUtils.forceMkdir(targetFolder); } if (!zipTargetFolderPath.endsWith(File.separator)) { zipTargetFolderPath = zipTargetFolderPath.concat(File.separator); } zipOutputStream = new FileOutputStream(zipTargetFolderPath + zipFilename); try { zip = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, zipOutputStream); } catch (ArchiveException e) { // This should never happen, because "zip" is a known archive type, but let's log it anyway LOG.error("Cant create an archive of type " + ArchiveStreamFactory.ZIP); } }
From source file:heigit.ors.util.FileUtility.java
public static void makeDirectory(String directory) throws Exception { File dir = new File(directory); if (!dir.exists()) { try {//from w w w .j a va 2 s .c om FileUtils.forceMkdir(dir); } catch (SecurityException se) { // handle it } if (!dir.exists()) throw new Exception("Unable to create directory - " + directory); } }
From source file:com.github.brandtg.pantopod.tor.TorProxyManager.java
@Override public void start() throws Exception { synchronized (sync) { File dataDir = new File(torRootDir, String.format("tor_%d", socksPort)); pidFile = new File(dataDir, PID_FILE_NAME); if (pidFile.exists()) { LOG.info("Stopping existing process {}", pidFile); stopProcess(pidFile, 2 /* SIGINT */); }/* w ww . java2 s . c om*/ LOG.info("Creating {}", dataDir); FileUtils.forceMkdir(dataDir); String command = torExecutable + " --RunAsDaemon 1" + " --CookieAuthentication 0" + " --HashedControlPassword \"\"" + " --ControlPort " + controlPort + " --PidFile " + pidFile.getAbsolutePath() + " --SocksPort " + socksPort + " --DataDirectory " + dataDir.getAbsolutePath(); LOG.info("Executing {}", command); DefaultExecutor executor = new DefaultExecutor(); int retCode = executor.execute(CommandLine.parse(command)); LOG.info("Executed {} #=> {}", command, retCode); // Set the system socket proxy System.setProperty("socksProxyHost", "localhost"); System.setProperty("socksProxyPort", String.valueOf(socksPort)); // Schedule a watchdog to periodically send SIGHUP, which resets the tor circuit if (watchdogDelayMillis > 0) { scheduler.schedule(new SigHupWatchdog(pidFile), watchdogDelayMillis, TimeUnit.MILLISECONDS); } } }
From source file:com.perceptive.epm.perkolcentral.bl.ImageNowLicenseBL.java
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.SERIALIZABLE, rollbackFor = ExceptionWrapper.class) public void addImageNowLicenseRequest(Imagenowlicenses imagenowlicenses, String groupRequestedFor, String employeeUIDWhoRequestedLicense, File sysfpFile, String originalFileName) throws ExceptionWrapper { try {/*from w ww .j a v a 2s.co m*/ imageNowLicenseDataAccessor.addImageNowLicense(imagenowlicenses, groupRequestedFor, employeeUIDWhoRequestedLicense); if (!new File(fileUploadPath).exists()) FileUtils.forceMkdir(new File(fileUploadPath)); File filePathForThisRequest = new File( FilenameUtils.concat(fileUploadPath, imagenowlicenses.getImageNowLicenseRequestId())); FileUtils.forceMkdir(filePathForThisRequest); File fileNameToCopy = new File( FilenameUtils.concat(filePathForThisRequest.getAbsolutePath(), originalFileName)); FileUtils.copyFile(sysfpFile, fileNameToCopy); //Send the email String messageToSend = String.format(Constants.email_license_request, imagenowlicenses.getEmployeeByRequestedByEmployeeId().getEmployeeName(), imagenowlicenses.getGroups().getGroupName(), new SimpleDateFormat("dd-MMM-yyyy").format(imagenowlicenses.getLicenseRequestedOn()), imagenowlicenses.getImageNowVersion(), imagenowlicenses.getHostname(), Long.toString(imagenowlicenses.getNumberOfLicenses())); email = new HtmlEmail(); email.setHostName(emailHost); email.setHtmlMsg(messageToSend); email.setSubject("ImageNow License Request"); //email.setFrom("ImageNowLicenseRequest@perceptivesoftware.com", "ImageNow License Request"); email.setFrom("ImageNowLicenseRequest@lexmark.com", "ImageNow License Request"); // Create the attachment EmailAttachment attachment = new EmailAttachment(); attachment.setPath(fileNameToCopy.getAbsolutePath()); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription(originalFileName); attachment.setName(originalFileName); email.attach(attachment); //Send mail to scrum masters for (EmployeeBO item : employeeBL.getAllEmployeesKeyedByGroupId().get(Integer.valueOf("14"))) { email.addTo(item.getEmail(), item.getEmployeeName()); } //email.addTo("saibal.ghosh@perceptivesoftware.com","Saibal Ghosh"); email.addCc(imagenowlicenses.getEmployeeByRequestedByEmployeeId().getEmail()); email.send(); } catch (Exception ex) { throw new ExceptionWrapper(ex); } }
From source file:net.sourceforge.floggy.maven.PersistenceMojo.java
/** * DOCUMENT ME!//from w w w .ja v a2s . com * * @throws MojoExecutionException DOCUMENT ME! */ public void execute() throws MojoExecutionException { MavenLogWrapper.setLog(getLog()); LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "net.sourceforge.floggy.maven.MavenLogWrapper"); Weaver weaver = new Weaver(); try { List list = project.getCompileClasspathElements(); File temp = new File(project.getBuild().getDirectory(), String.valueOf(System.currentTimeMillis())); FileUtils.forceMkdir(temp); weaver.setOutputFile(temp); weaver.setInputFile(input); weaver.setClasspath((String[]) list.toArray(new String[list.size()])); if (configurationFile == null) { Configuration configuration = new Configuration(); configuration.setAddDefaultConstructor(addDefaultConstructor); configuration.setGenerateSource(generateSource); weaver.setConfiguration(configuration); } else { weaver.setConfigurationFile(configurationFile); } weaver.execute(); FileUtils.copyDirectory(temp, output); FileUtils.forceDelete(temp); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } }