List of usage examples for org.apache.commons.io FileUtils touch
public static void touch(File file) throws IOException
From source file:jmassivesort.algs.chunks.BaseChunkReaderTest.java
protected File createTmpFile(String dir, String name) throws IOException { File out = new File(dir + "/" + name); if (out.exists()) FileUtils.forceDelete(out);/*from ww w .ja v a2 s . co m*/ FileUtils.touch(out); return out; }
From source file:FileInit.java
public void doJob() throws Exception { Logger.info("Creating required folders"); File readme = new File(ArtifactsController.getArtifactsFolder(), "README.md"); if (!readme.exists()) { FileUtils.touch(readme); FileUtils.writeStringToFile(readme, "This is the local artifacts repository"); }/* w ww. j a v a 2 s . c om*/ // getting all files from the folder and adding them to the artifacts // repository if not already here... Iterator<File> iter = FileUtils.iterateFiles(ArtifactsController.getArtifactsFolder(), new String[] { "zip" }, false); while (iter.hasNext()) { File file = iter.next(); // find the artifact with the file name as URL if (!ArtifactURL.localExists(file.getName())) { ArtifactURL a = new ArtifactURL(); a.date = new Date(); a.local = true; a.name = file.getName(); a.url = file.getName(); a.save(); } else { Logger.info("Aleady registered " + file.getName()); } } }
From source file:com.izforge.izpack.event.AntActionLogBuildListener.java
public AntActionLogBuildListener(File logFile, boolean append, int level) { this.setMessageOutputLevel(level); if (logFile != null) { PrintStream printStream;//from w ww.j a v a2 s . c om try { final File canonicalLogFile = logFile.getCanonicalFile(); FileUtils.forceMkdir(canonicalLogFile.getParentFile()); FileUtils.touch(canonicalLogFile); printStream = new PrintStream(new FileOutputStream(canonicalLogFile, append)); this.setOutputPrintStream(printStream); this.setErrorPrintStream(printStream); } catch (IOException e) { logger.warning("Cannot log to file '" + logFile + "': " + e.getMessage()); this.setOutputPrintStream(System.out); this.setErrorPrintStream(System.err); } } else { this.setOutputPrintStream(System.out); this.setErrorPrintStream(System.err); } }
From source file:com.googlecode.xtecuannet.framework.catalina.manager.tomcat.constants.Constants.java
public static PropertiesConfiguration getConfig(String basePath, Class clazze) { PropertiesConfiguration pc = null;// w w w . j a v a2s . c o m String className = clazze.getSimpleName(); File basePathObj = new File(basePath); File fileCfg = new File(basePathObj, className + PROPERTIES); try { if (!basePathObj.exists()) { if (basePathObj.mkdirs()) { logger.info(basePath + " created!!!"); } } else { logger.info(basePath + " already exists skipping!!!"); if (!fileCfg.exists()) { FileUtils.touch(fileCfg); logger.info(fileCfg.getName() + " created!!!"); } else { logger.info(fileCfg.getName() + " already exists skipping!!!"); } } pc = new PropertiesConfiguration(fileCfg); pc.setReloadingStrategy(new FileChangedReloadingStrategy()); // pc.setAutoSave(true); pc.setDelimiterParsingDisabled(false); logger.info(fileCfg.getName() + " loaded!!!"); } catch (IOException e) { logger.error("Error creating config file or directory for class: " + className, e); } catch (ConfigurationException ex) { logger.error("Error getting/initializacion config for class: " + className, ex); } return pc; }
From source file:io.kamax.mxisd.spring.CryptoFactory.java
@Bean public KeyManager getKeyManager(KeyConfig keyCfg) { File keyStore = new File(keyCfg.getPath()); if (!keyStore.exists()) { try {/*from w ww .j a va 2 s .com*/ FileUtils.touch(keyStore); } catch (IOException e) { throw new RuntimeException(e); } } return new KeyManager(new KeyFileStore(keyCfg.getPath())); }
From source file:com.github.mojo.bdd.NoseMojo.java
@Override protected void preExecute() throws MojoExecutionException, MojoFailureException { super.preExecute(); try {/*from ww w. ja v a2 s . c om*/ FileUtils.touch(new File("target/bdd-reports/nosetests.xml")); } catch (IOException e) { getLog().error("Failed to create touch target/bdd-reports/nosetests.xml", e); throw new MojoExecutionException("Failed to create touch target/bdd-reports/nosetests.xml"); } //add support for explicitly specifying a path for BDD tests if (System.getProperty(PATH) != null) { String path = System.getProperty(PATH); getRequestOptions().add(path); } //add support for running with tags if (System.getProperty(TAGS) != null) { String tags = System.getProperty(TAGS); getRequestOptions().add("--tags=" + tags); } //add support for re-running last failed tesrs only if ("true".equals(System.getProperty(BddConstants.FAILED_ONLY))) { getRequestOptions().add("--failed"); } }
From source file:edu.umn.msi.tropix.common.test.FileDisposableResourceImplTest.java
@Test(groups = "unit", timeOut = 1000) public void dispose() throws IOException { final File tempFile = File.createTempFile("tpxtest", ""); FileUtils.touch(tempFile); assert tempFile.exists(); final FileDisposableResourceImpl resource = new FileDisposableResourceImpl(tempFile); assert resource.getFile().equals(tempFile); resource.dispose();//from w w w. ja v a 2s . c o m assert !tempFile.exists(); }
From source file:ml.shifu.shifu.fs.ShifuFileUtilsTest.java
@Test public void getDataScannersTest() throws IOException { File file = new File("common-utils"); if (file.exists()) { FileUtils.deleteDirectory(file); }//from w w w .j a v a2s .c o m FileUtils.forceMkdir(file); List<Scanner> list = ShifuFileUtils.getDataScanners(Arrays.asList(new String[] { "common-utils" }), SourceType.HDFS); Assert.assertTrue(list.size() == 0); file = new File("common-utils/part-0000"); FileUtils.touch(file); list = ShifuFileUtils.getDataScanners(Arrays.asList(new String[] { "common-utils" }), SourceType.HDFS); Assert.assertTrue(list.size() == 1); for (Scanner scanner : list) { scanner.close(); } FileUtils.deleteDirectory(new File("common-utils")); }
From source file:edu.kit.dama.util.SystemUtils.java
/** * Lock the provided folder pLocalFolder. At first, the current operating * system is checked for beeing a Unix based system. In this case, a dedicated * script will be used for locking. In all other cases or if the script-based * approach fails, a single file '.locked' is created inside pLocalFolder. * * @param pFolder The folder to lock (must be a directory) * * @return TRUE on success, FALSE on any error */// w w w . java2 s . co m public static boolean lockFolder(File pFolder) { if (!pFolder.isDirectory()) { LOGGER.error("Provided argument 'pLocalFolder' ({}) must be a directory", pFolder); return false; } if (org.apache.commons.lang3.SystemUtils.IS_OS_UNIX && lockFolderUnix(pFolder)) { return true; } //else...fallback using '.locked' file File lockFile = new File(FilenameUtils.concat(pFolder.getAbsolutePath(), ".locked")); try { LOGGER.debug("Try to create lock '{}'", lockFile); FileUtils.touch(lockFile); } catch (IOException ioe) { LOGGER.error("Failed to lock folder '" + pFolder.getAbsolutePath() + "'", ioe); return false; } return true; }
From source file:com.cloudant.sync.util.TestUtils.java
public static String createTempFile(String dir, String file) throws IOException { File f = new File(dir + File.separator + file); FileUtils.touch(f); return f.getAbsolutePath(); }