List of usage examples for org.apache.commons.io FileUtils forceMkdir
public static void forceMkdir(File directory) throws IOException
From source file:eu.scape_project.arc2warc.ArcMigrator.java
public void migrateArcFile() { try {//from w w w .j av a2 s .c o m reader = JwatArcReaderFactory.getReader(new FileInputStream(arcFile)); FileUtils.forceMkdir(warcFile.getParentFile()); writer = WarcWriterFactory.getWriter(new FileOutputStream(warcFile), config.createCompressedWarc()); warcInfoId = getRecordID().toString(); createWarcInfoRecord(); Iterator<ArcRecordBase> arcIterator = reader.iterator(); boolean first = true; while (arcIterator.hasNext()) { ArcRecordBase jwatArcRecord = arcIterator.next(); if (first) { migrateMetadataRecord(jwatArcRecord); first = false; } else if (deduplicate) { if (RegexUtils.pathMatchesRegexFilter(jwatArcRecord.getUrlStr(), "^metadata://.*/crawl/logs/crawl\\.log.*$")) { migrateCrawlLog(jwatArcRecord, writer); } } else { migrateResponseRecord(jwatArcRecord); } } LOG.info("File processed: " + arcFile.getAbsolutePath()); } catch (URISyntaxException ex) { LOG.error("File not found error", ex); throw new RuntimeException(ex); } catch (FileNotFoundException ex) { LOG.error("File not found error", ex); throw new RuntimeException(ex); } catch (IOException ex) { LOG.error("I/O Error", ex); throw new RuntimeException(ex); } finally { IOUtils.closeQuietly(reader); IOUtils.closeQuietly(writer); clear(); } }
From source file:it.geosolutions.geostore.services.rest.auditing.AuditingFilesManager.java
private void init() { updateCurrentDay();/*from w w w .java 2s . co m*/ outputFile = new File(outputDirectory, String.format("audit-geostore.%s", fileExtension)); if (outputDirectory.exists()) { LogUtils.info(logger, "Output directory '%s' exists.", outputDirectory.getPath()); handleExistingOutputDirectory(); } else { LogUtils.info(logger, "Creating output directory '%s'.", outputDirectory.getPath()); try { FileUtils.forceMkdir(outputDirectory); } catch (Exception exception) { throw new AuditingException(exception, "Error creating output directory '%s'.", outputDirectory); } } }
From source file:fr.lirmm.yamplusplus.yampponline.YamFileHandler.java
/** * YamFileHandler constructor. It gets the workdir from the conf.properties * file//from w ww.ja v a 2s.c o m * * @throws IOException * @throws ClassNotFoundException */ public YamFileHandler() throws IOException, ClassNotFoundException { // Load properties file for work directory Properties prop = new Properties(); prop.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("conf.properties")); this.workDir = prop.getProperty("workdir"); // Create the working directory FileUtils.forceMkdir(new File(this.workDir)); FileUtils.forceMkdir(new File(this.tmpDir)); }
From source file:ch.admin.suis.msghandler.common.CompleteMultiReceiverTest.java
@Override protected void setUp() throws Exception { super.setUp(); dirsToClean.add(new File(BASE_PATH_MH, "nativeApp1/inbox")); dirsToClean.add(new File(BASE_PATH_MH, "nativeApp1/outbox")); dirsToClean.add(new File(BASE_PATH_MH, "transApp1/inbox")); dirsToClean.add(new File(BASE_PATH_MH, "transApp1/outbox")); dirsToClean.add(new File(BASE_PATH_MH, "transApp1/receipts")); dirsToClean.add(new File(BASE_PATH_MH, "transApp2/inbox")); dirsToClean.add(new File(BASE_PATH_MH, "transApp2/outbox")); dirsToClean.add(new File(BASE_PATH_MH, "transApp2/receipts")); dirsToClean.add(new File(INSTALL_DIR, "workingDir/tmp/receiving")); dirsToClean.addAll(addSedexDirectories(BASE_PATH_SDX)); dirsToClean.addAll(addMHWorkingDirectories(INSTALL_DIR + "/workingDir")); dirsToClean.forEach((dir) -> {//from w w w. j a va2s. c o m try { FileUtils.forceMkdir(dir); } catch (IOException ex) { // ignore } }); File dbFile = new File(BASE_PATH_MH, "../../DB"); if (!dbFile.exists()) { dbFile.mkdir(); } dirsToClean.add(dbFile); addToClassPath(INSTALL_DIR + "/conf"); }
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 {/* w ww . j a v a 2 s. co m*/ 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.datatorrent.lib.io.fs.FSInputModuleAppTest.java
@Before public void setup() throws Exception { inputDir = testMeta.baseDirectory + File.separator + "input"; outputDir = testMeta.baseDirectory + File.separator + "output"; FileUtils.writeStringToFile(new File(inputDir + File.separator + FILE_1), FILE_1_DATA); FileUtils.writeStringToFile(new File(inputDir + File.separator + FILE_2), FILE_2_DATA); FileUtils.forceMkdir(new File(inputDir + File.separator + "dir")); FileUtils.writeStringToFile(new File(inputDir + File.separator + "dir/inner.txt"), FILE_1_DATA); }
From source file:gov.nih.nci.cabig.caaers.service.adverseevent.AdditionalInformationDocumentService.java
public AdditionalInformationDocument uploadFile(String fileName, AdditionalInformation additionalInformation, InputStream inputStream, AdditionalInformationDocumentType additionalInformationDocumentType) { try {// w w w . j a va 2 s. c o m String aeAttachmentsLocation = configuration.get(Configuration.AE_ATTACHMENTS_LOCATION); String directory = FilenameUtils.normalize(aeAttachmentsLocation + "/" + additionalInformation.getId()); String extension = StringUtils.isNotBlank(FilenameUtils.getExtension(fileName)) ? "." + FilenameUtils.getExtension(fileName) : ""; String filePath = FilenameUtils.normalize(directory + "/" + FilenameUtils.getBaseName(fileName) + Calendar.getInstance().getTimeInMillis() + RandomUtils.nextInt(100) + extension); if (logger.isDebugEnabled()) { logger.debug(String.format("creating file %s of type %s for additional information %s at %s ", fileName, additionalInformationDocumentType, additionalInformation.getId(), filePath)); } FileUtils.forceMkdir(new File(directory)); File file = new File(filePath); if (file.createNewFile()) { long bytesCopied = IOUtils.copyLarge(inputStream, new FileOutputStream(file)); AdditionalInformationDocument additionalInformationDocument = new AdditionalInformationDocument(); additionalInformationDocument .setAdditionalInformationDocumentType(additionalInformationDocumentType); additionalInformationDocument.setAdditionalInformation(additionalInformation); additionalInformationDocument.setFileId(DigestUtils.md5Hex(file.getAbsolutePath())); additionalInformationDocument.setOriginalFileName(fileName); additionalInformationDocument.setFileName(file.getName()); additionalInformationDocument.setFilePath(file.getCanonicalPath()); additionalInformationDocument.setRelativePath(file.getAbsolutePath()); additionalInformationDocument.setFileSize(bytesCopied); additionalInformationDocumentDao.save(additionalInformationDocument); if (logger.isDebugEnabled()) { logger.debug(String.format( "successfully created file %s of type %s for additional information %s at %s. File information is - %s ", fileName, additionalInformationDocumentType, additionalInformation.getId(), filePath, additionalInformationDocument)); } return additionalInformationDocument; } else { String errorMessage = String.format( "error while creating file %s of type %s for additional information %s ", fileName, additionalInformationDocumentType, additionalInformation.getId()); throw new RuntimeException(errorMessage); } } catch (Exception e) { String errorMessage = String.format( "error while creating file %s of type %s for additional information %s ", fileName, additionalInformationDocumentType, additionalInformation.getId()); logger.error(errorMessage, e); return null; } }
From source file:com.yahoo.sshd.authentication.file.TestPKUpdating.java
private TestContext setup() throws IOException, InterruptedException { TestContext testContext = new TestContext(); // first build dirs. if (homeDir.exists()) { FileUtils.forceDelete(homeDir);/*from www . j a va 2 s. c o m*/ } FileUtils.forceMkdir(homeDir); // build user directories. User[] dirs = new User[normalUsers.length + notUsers.length]; System.arraycopy(normalUsers, 0, dirs, 0, normalUsers.length); System.arraycopy(notUsers, 0, dirs, normalUsers.length, notUsers.length); buildSshDirs(homeDir, dirs); // this point everyone in users has a public key, so we can load it, and // check for them. CountDownLatch waiter = new CountDownLatch(1); testContext.publickeyAuthenticator = new HomeDirectoryScanningPKAuthenticator(waiter, homeDir, Arrays.asList(new Path[] { new File(homeDir, "y").toPath() })); testContext.publickeyAuthenticator.start(); waiter.await(); checkExist(testContext, normalUsers); checkDoesntExist(testContext, notUsers); return testContext; }
From source file:com.galenframework.reports.HtmlReportBuilder.java
private void makeSureReportFolderExists(String reportFolderPath) throws IOException { FileUtils.forceMkdir(new File(reportFolderPath)); }
From source file:com.ariht.maven.plugins.config.ConfigGenerationMojoTest.java
/** * Given a relative path on the classpath, in this case src/tests/resources. *//* w w w .java 2 s . com*/ private String getAbsolutePath(final String subDirectoryName) throws IOException { final URL resource = getClass().getResource("/"); final String normalizedAbsolutePath = FilenameUtils.normalize(resource.getFile() + subDirectoryName); final File directoryFile = new File(normalizedAbsolutePath); if (!directoryFile.exists()) { FileUtils.forceMkdir(directoryFile); } return normalizedAbsolutePath; }