List of usage examples for org.apache.commons.io FileUtils forceMkdir
public static void forceMkdir(File directory) throws IOException
From source file:com.datatorrent.stram.client.AppPackage.java
/** * Creates an App Package object.//from w w w . j a v a 2 s . co m * * If app directory is to be processed, there may be resource leak in the class loader. Only pass true for short-lived * applications * * If contentFolder is not null, it will try to create the contentFolder, file will be retained on disk after App Package is closed * If contentFolder is null, temp folder will be created and will be cleaned on close() * * @param file * @param contentFolder the folder that the app package will be extracted to * @param processAppDirectory * @throws java.io.IOException * @throws net.lingala.zip4j.exception.ZipException */ public AppPackage(File file, File contentFolder, boolean processAppDirectory) throws IOException, ZipException { super(file); if (contentFolder != null) { FileUtils.forceMkdir(contentFolder); cleanOnClose = false; } else { cleanOnClose = true; contentFolder = Files.createTempDirectory("dt-appPackage-").toFile(); } directory = contentFolder; Manifest manifest = getManifest(); if (manifest == null) { throw new IOException("Not a valid app package. MANIFEST.MF is not present."); } Attributes attr = manifest.getMainAttributes(); appPackageName = attr.getValue(ATTRIBUTE_DT_APP_PACKAGE_NAME); appPackageVersion = attr.getValue(ATTRIBUTE_DT_APP_PACKAGE_VERSION); appPackageGroupId = attr.getValue(ATTRIBUTE_DT_APP_PACKAGE_GROUP_ID); dtEngineVersion = attr.getValue(ATTRIBUTE_DT_ENGINE_VERSION); appPackageDisplayName = attr.getValue(ATTRIBUTE_DT_APP_PACKAGE_DISPLAY_NAME); appPackageDescription = attr.getValue(ATTRIBUTE_DT_APP_PACKAGE_DESCRIPTION); String classPathString = attr.getValue(ATTRIBUTE_CLASS_PATH); if (appPackageName == null || appPackageVersion == null || classPathString == null) { throw new IOException( "Not a valid app package. App Package Name or Version or Class-Path is missing from MANIFEST.MF"); } classPath.addAll(Arrays.asList(StringUtils.split(classPathString, " "))); extractToDirectory(directory, file); if (processAppDirectory) { processAppDirectory(new File(directory, "app")); } File confDirectory = new File(directory, "conf"); if (confDirectory.exists()) { processConfDirectory(confDirectory); } resourcesDirectory = new File(directory, "resources"); File propertiesXml = new File(directory, "META-INF/properties.xml"); if (propertiesXml.exists()) { processPropertiesXml(propertiesXml, null); } if (processAppDirectory) { for (AppInfo app : applications) { app.requiredProperties.addAll(requiredProperties); app.defaultProperties.putAll(defaultProperties); File appPropertiesXml = new File(directory, "META-INF/properties-" + app.name + ".xml"); if (appPropertiesXml.exists()) { processPropertiesXml(appPropertiesXml, app); } } } }
From source file:com.talis.entity.db.babudb.DatabaseManager.java
private void initDbDir(File dbDir) { LOG.info("Initialising Database directory: {}", dbDir.getAbsolutePath()); try {//from w ww . j av a2 s. com FileUtils.forceMkdir(dbDir); } catch (IOException e) { LOG.error("Error creating Database directory", e); throw new RuntimeException("Unable to create database", e); } }
From source file:hu.bme.mit.sette.tools.jpet.JPetRunner.java
@Override protected void runOne(Snippet snippet, File infoFile, File outputFile, File errorFile) throws IOException, SetteConfigurationException { // TODO extract, make more clear File pet = getTool().getPetExecutable(); File testCaseXml = getTool().getTestCaseXmlFile(getRunnerProjectSettings(), snippet); FileUtils.forceMkdir(testCaseXml.getParentFile()); StringBuilder jPetName = new StringBuilder(); jPetName.append(JavaFileUtils.packageNameToFilename(snippet.getContainer().getJavaClass().getName())); jPetName.append('.'); jPetName.append(snippet.getMethod().getName()); // params/* w w w . j a va 2 s .c om*/ jPetName.append('('); for (Class<?> param : snippet.getMethod().getParameterTypes()) { System.err.println(param.getName() + "-" + param.getCanonicalName()); jPetName.append(JPetTypeConverter.fromJava(param)); } jPetName.append(')'); // return type System.err.println(snippet.getMethod().getReturnType().getName() + "-" + snippet.getMethod().getReturnType().getCanonicalName()); jPetName.append(JPetTypeConverter.fromJava(snippet.getMethod().getReturnType())); // TODO better way to create command // create command List<String> cmd = new ArrayList<>(); cmd.add(pet.getAbsolutePath()); cmd.add(jPetName.toString()); cmd.add("-cp"); cmd.add("build"); cmd.add("-c"); cmd.add("bck"); cmd.add("10"); cmd.add("-td"); cmd.add("num"); cmd.add("-d"); cmd.add("-100000"); cmd.add("100000"); cmd.add("-l"); cmd.add("ff"); cmd.add("-v"); cmd.add("2"); cmd.add("-w"); cmd.add("-tr"); cmd.add("statements"); cmd.add("-cc"); cmd.add("yes"); cmd.add("-xml"); cmd.add(testCaseXml.getCanonicalPath()); System.out.println(" command: " + StringUtils.join(cmd, ' ')); // run process ProcessRunner pr = new ProcessRunner(); pr.setCommand(cmd); ; pr.setWorkingDirectory(getRunnerProjectSettings().getBaseDirectory()); pr.setTimeoutInMs(getTimeoutInMs()); pr.setPollIntervalInMs(RunnerProjectRunner.POLL_INTERVAL); OutputWriter l = new OutputWriter(cmd.toString(), infoFile, outputFile, errorFile); pr.addListener(l); pr.execute(); }
From source file:com.github.neio.filesystem.paths.TestDirectoryPath.java
@Test public void test_Path_Iterator() throws IOException { Directory directory = new DirectoryPath("./testTempDir"); FileUtils.forceMkdir(new File("./testTempDir/path1")); FileUtils.touch(new File("./testTempDir/path1/file1")); Iterator<Path> iterator = directory.iterator(); Assert.assertTrue(iterator.hasNext()); Path path1 = iterator.next(); Assert.assertTrue(path1 instanceof FilePath); Assert.assertEquals("testTempDir/path1/file1", path1.getPath()); }
From source file:com.impetus.ankush.common.utils.UploadHandler.java
/** * Gets the upload folder path.// w w w. ja v a 2 s . c om * * @return the uploadFolderPath * @throws IOException * Signals that an I/O exception has occurred. */ private String getUploadFolderPath() throws IOException { String path = null; // equals the category provide. if (category.equalsIgnoreCase("bundle")) { path = REPO_PATH; } else if (category.equals("log")) { // Getting application real path. String appRealPath = AppStoreWrapper.getAppPath(); // Getting the application public/clusters folder. String clustersFolderPath = FileNameUtils.convertToValidPath(appRealPath) + "resources/clusters/"; // Getting the cluster folder path. path = clustersFolderPath + "/logs/"; } else if (category.equals(LICENSE)) { path = LICENSE_PATH; } else { if (category.equals(PATCHES)) { path = PATCHES_REPO_PATH; } else { // other paths. path = UPLOAD_PATH + getHash() + File.separator; } } // Create file. File file = new File(path); FileUtils.forceMkdir(file); return path; }
From source file:io.druid.data.input.impl.prefetch.PrefetchableTextFilesFirehoseFactoryTest.java
private static File createFirehoseTmpDir(String dirSuffix) throws IOException { final File firehoseTempDir = File .createTempFile(PrefetchableTextFilesFirehoseFactoryTest.class.getSimpleName(), dirSuffix); FileUtils.forceDelete(firehoseTempDir); FileUtils.forceMkdir(firehoseTempDir); FIREHOSE_TMP_DIRS.add(firehoseTempDir); return firehoseTempDir; }
From source file:fr.letroll.ttorrentandroid.client.TorrentHandler.java
@Nonnull private static TorrentByteStorage toStorage(@Nonnull Torrent torrent, @Nonnull File parent) throws IOException { Preconditions.checkNotNull(parent, "Parent directory was null."); String parentPath = parent.getCanonicalPath(); if (!torrent.isMultifile() && parent.isFile()) return new FileStorage(parent, torrent.getSize()); List<FileStorage> files = new LinkedList<FileStorage>(); long offset = 0L; for (Torrent.TorrentFile file : torrent.getFiles()) { // TODO: Files.simplifyPath() is a security check here to avoid jail-escape. // However, it uses "/" not File.separator internally. String path = Files.simplifyPath("/" + file.path); File actual = new File(parent, path); String actualPath = actual.getCanonicalPath(); if (!actualPath.startsWith(parentPath)) throw new SecurityException("Torrent file path attempted to break directory jail: " + actualPath + " is not within " + parentPath); FileUtils.forceMkdir(actual.getParentFile()); files.add(new FileStorage(actual, offset, file.size)); offset += file.size;/*from w ww .j a v a2 s . co m*/ } return new FileCollectionStorage(files, torrent.getSize()); }
From source file:com.impetus.ankush.agent.AgentConf.java
/** * Load the properties from the default file. * //w w w. j ava 2 s . c om * @throws IOException * * @throws FileNotFoundException */ public void load() throws IOException { File file = new File(fileName); if (!file.exists()) { String confPath = FilenameUtils.getFullPathNoEndSeparator(fileName); FileUtils.forceMkdir(new File(confPath)); FileUtils.touch(file); } this.properties = load(fileName); }
From source file:eu.planets_project.services.utils.ZipUtilsTest.java
/** * Test method for {@link eu.planets_project.services.utils.ZipUtils#removeFileFrom(java.io.File, java.lang.String)}. * @throws IOException /*from www. j a v a 2 s.c o m*/ */ @Test public void testRemoveFile() throws IOException { FileUtils.cleanDirectory(outputFolder); ZipUtils.listAllFilesAndFolders(TEST_FILE_FOLDER, new ArrayList<File>()).size(); File zip = ZipUtils.createZip(TEST_FILE_FOLDER, outputFolder, "zipUtilsTestRemove.zip", true); System.out.println("Zip created. Please find it here: " + zip.getAbsolutePath()); String folderName = zip.getName().substring(0, zip.getName().lastIndexOf(".")); File extract = new File(outputFolder, folderName); FileUtils.forceMkdir(extract); ZipUtils.unzipTo(zip, extract); new File(PROJECT_BASE_FOLDER, "src/test/data/test_zip/docs/lorem-ipsum.txt"); // File deleteSingleFile = new File("IF/common/src/test/resources/test_zip/images/test_jp2/canon-ixus.jpg.jp2"); ZipUtils.removeFileFrom(zip, "docs/lorem-ipsum.txt"); ZipUtils.removeFileFrom(zip, "docs"); System.out.println("Zip modified. Please find it here: " + zip.getAbsolutePath()); }
From source file:de.blizzy.documentr.context.ContextConfig.java
@Bean(destroyMethod = "shutdown") @SuppressWarnings("deprecation") public net.sf.ehcache.CacheManager ehCacheManager(Settings settings) throws IOException { File cacheDir = new File(settings.getDocumentrDataDir(), DocumentrConstants.CACHE_DIR_NAME); FileUtils.forceMkdir(cacheDir); net.sf.ehcache.CacheManager ehCacheManager = net.sf.ehcache.CacheManager .newInstance(new net.sf.ehcache.config.Configuration().name("Ehcache") //$NON-NLS-1$ .updateCheck(false)// w ww .ja v a 2 s . co m .diskStore(new DiskStoreConfiguration().path(cacheDir.getAbsolutePath()))); ehCacheManager.addCache(new Cache(new CacheConfiguration().name("page_html") //$NON-NLS-1$ .overflowToDisk(true).diskPersistent(true).maxEntriesLocalHeap(1000) .maxBytesLocalDisk(100, MemoryUnit.MEGABYTES) .timeToIdleSeconds(TimeUnit.SECONDS.convert(30, TimeUnit.DAYS)))); ehCacheManager.addCache(new Cache(new CacheConfiguration().name("page_header_html") //$NON-NLS-1$ .overflowToDisk(true).diskPersistent(true).maxEntriesLocalHeap(100) .maxBytesLocalDisk(10, MemoryUnit.MEGABYTES) .timeToIdleSeconds(TimeUnit.SECONDS.convert(30, TimeUnit.DAYS)))); ehCacheManager.addCache(new Cache(new CacheConfiguration().name("page_metadata") //$NON-NLS-1$ .overflowToDisk(true).diskPersistent(true).maxEntriesLocalHeap(1000) .maxBytesLocalDisk(10, MemoryUnit.MEGABYTES) .timeToIdleSeconds(TimeUnit.SECONDS.convert(30, TimeUnit.DAYS)))); ehCacheManager.addCache(new Cache(new CacheConfiguration().name("page_view_restriction_role") //$NON-NLS-1$ .overflowToDisk(true).diskPersistent(true).maxEntriesLocalHeap(1000) .maxBytesLocalDisk(10, MemoryUnit.MEGABYTES) .timeToIdleSeconds(TimeUnit.SECONDS.convert(30, TimeUnit.DAYS)))); return ehCacheManager; }