List of usage examples for org.apache.commons.io FileUtils touch
public static void touch(File file) throws IOException
From source file:com.impetus.ankush.agent.AgentConf.java
/** * Load the properties from the default file. * // ww w . j a v a2s . co m * @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:com.qcadoo.plugin.internal.filemanager.PluginFileManagerTest.java
@Test(expected = PluginException.class) public void shouldThrowExceptionOnUploadingPluginFileWhenOperationFail() throws Exception { // given/* w ww . ja v a2s .c om*/ File newPluginFile = new File(source, "newpluginname.jar"); FileUtils.touch(newPluginFile); PluginArtifact pluginArtifact = mock(PluginArtifact.class); given(pluginArtifact.getInputStream()).willReturn(new FileInputStream(newPluginFile)); given(pluginArtifact.getName()).willReturn(""); // when defaultPluginFileManager.uploadPlugin(pluginArtifact); }
From source file:com.opera.core.systems.OperaPaths.java
/** * Tries to load the launcher executable from the jar file A copy of the * launcher is put into user directory and on each call is compared to the * content in jar file/*from w w w. j a v a 2 s . com*/ * * @return path to launcher executable */ public String getOperaLauncherPath() { String launcherName = getLauncherNameForOS(); String executablePath = null; // Get the launcher path URL res = OperaDriver.class.getClassLoader().getResource("launcher/" + launcherName); if (res != null) { String url = res.toExternalForm(); // If the launcher is inside the jar we will need to copy it out if ((url.startsWith("jar:")) || (url.startsWith("wsjar:"))) { executablePath = FileUtils.getUserDirectoryPath() + File.separatorChar + ".launcher" + File.separatorChar + launcherName; File cur_launcher = new File(executablePath); // Whether we need to copy a new launcher across, either because // it doesn't currently exist, or because its hash differs from // our launcher boolean copy = false; if (!cur_launcher.exists()) { copy = true; } else { try { // Copy if launchers don't match copy = !Arrays.equals(md5(executablePath), md5(res.openStream())); } catch (Exception e) { copy = true; } } if (copy == true) { try { if (!cur_launcher.exists()) FileUtils.touch(cur_launcher); InputStream is = res.openStream(); OutputStream os = new FileOutputStream(cur_launcher); IOUtils.copy(is, os); is.close(); os.close(); cur_launcher.setLastModified(cur_launcher.lastModified()); } catch (IOException e) { throw new WebDriverException("Cant write file to disk : " + e.getMessage()); } logger.fine("New launcher copied"); } // If launcher is not inside jar we can run it from it's current // location } else if (url.startsWith("file:")) { File f; try { f = new File(res.toURI()); } catch (URISyntaxException e) { f = new File(res.getPath()); } executablePath = f.getAbsolutePath(); } } if (executablePath != null) makeLauncherExecutable(executablePath); return executablePath; }
From source file:com.ning.metrics.collector.hadoop.processing.TestHadoopWriterFactory.java
public void testProcessLeftBelowFilesWithFilesRemaining() throws Exception { final HadoopWriterFactory factory = new NoWriteHadoopWriterFactory(null, config); FileUtils.touch(new File(tmpDirectory.getPath() + "/dont_touch_me")); FileUtils.touch(new File(lockDirectory.getPath() + "/some_file_which_should_be_sent_1")); FileUtils.touch(new File(lockDirectory.getPath() + "/some_file_which_should_be_sent_2")); FileUtils.touch(new File(quarantineDirectory.getPath() + "/some_other_file_which_should_be_sent")); Assert.assertEquals(FileUtils/*from ww w . jav a 2 s . c o m*/ .listFiles(spoolDirectory, FileFilterUtils.trueFileFilter(), FileFilterUtils.trueFileFilter()) .size(), 4); Assert.assertTrue(spoolDirectory.exists()); Assert.assertTrue(tmpDirectory.exists()); Assert.assertTrue(lockDirectory.exists()); Assert.assertTrue(quarantineDirectory.exists()); Thread.sleep(2 * CUTOFF_TIME); factory.processLeftBelowFiles(); // The file in /_tmp should no have been sent Assert.assertEquals(FileUtils .listFiles(spoolDirectory, FileFilterUtils.trueFileFilter(), FileFilterUtils.trueFileFilter()) .size(), 1); Assert.assertTrue(spoolDirectory.exists()); Assert.assertTrue(tmpDirectory.exists()); Assert.assertFalse(lockDirectory.exists()); Assert.assertFalse(quarantineDirectory.exists()); // We could even test the mapping in HDFS here (with the keys) Assert.assertEquals(hdfs.values().size(), 3); }
From source file:com.meltmedia.cadmium.deployer.JBossUtil.java
public static void deploy(String warName, File warFile, Logger log) throws Exception { String deployPath = System.getProperty("jboss.server.home.dir", "/opt/jboss/server/meltmedia") + "/deploy"; log.info("Moving war {} into deployment directory {}", warFile.getName(), deployPath); File newWar = new File(deployPath, warName); FileUtils.copyFile(warFile, newWar); FileUtils.deleteQuietly(warFile);//from w ww .java 2s. c om FileUtils.touch(newWar); }
From source file:com.orange.mmp.dao.flf.DeliveryTicketDaoFlfImpl.java
public void delete(DeliveryTicket deliveryTicket) throws MMPDaoException { DeliveryTicket deliveryTickets[] = this.find(deliveryTicket); try {/*from ww w. j av a 2 s . c o m*/ this.lock.lock(); for (DeliveryTicket currentTicket : deliveryTickets) { File toDelete = new File(this.path, currentTicket.getId().concat(".tmp")); if (!toDelete.delete()) { throw new MMPDaoException("failed to delete ticket " + currentTicket.getId()); } } FileUtils.touch(new File(this.path)); } catch (IOException ioe) { throw new MMPDaoException("failed to delete ticket : " + ioe.getMessage()); } finally { this.lock.unlock(); } }
From source file:edu.kit.dama.dataworkflow.impl.LocalExecutionHandler.java
/** * Execute the user application. This method will start a new process running * the prepared user application locally. The method will return as soon as * the application has terminated. An asnychronous monitoring task my check * whether the process is still running or not via {@link #getTaskStatus(edu.kit.dama.mdm.dataworkflow.DataWorkflowTask) * } This method will check the runningIndicator file '.RUNNING', which only * exists as long as the application is running. * * @param pTask The task whose application should be executed. * * @throws DataWorkflowProcessingException If either the startup or the * processing fails for any reason, or if the user application returns an exit * code != 0./*from ww w. ja v a 2s . c o m*/ */ @Override public void startUserApplication(DataWorkflowTask pTask) throws DataWorkflowProcessingException { //simply start the process...monitoring will be connected later File runningIndicator = getRunningIndicator(pTask); FileOutputStream fout = null; FileOutputStream ferr = null; File executablePath; try { executablePath = DataWorkflowHelper.getTaskMainExecutable(pTask); File executionBasePath = DataWorkflowHelper.getExecutionBasePath(pTask); File workingDirectory = DataWorkflowHelper.getTaskWorkingDirectory(executionBasePath); File tempDirectory = DataWorkflowHelper.getTaskTempDirectory(executionBasePath); File inputDirectory = DataWorkflowHelper.getTaskInputDirectory(executionBasePath); File outputDirectory = DataWorkflowHelper.getTaskOutputDirectory(executionBasePath); if (!executablePath.canExecute()) { LOGGER.debug("Executable at location {} seems not to be executable. Taking care of this..."); if (executablePath.setExecutable(true)) { LOGGER.debug("Executable was successfully set to be executable."); } else { LOGGER.warn("Failed to set executable to be executable. Trying to continue."); } } String cmdLineString = executablePath.getAbsolutePath() + " " + pTask.getConfiguration().getApplicationArguments() + " " + pTask.getApplicationArguments(); LOGGER.debug("Building up command array from string '{}'", cmdLineString); CommandLine cmdLine = CommandLine.parse(cmdLineString); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); Map<String, String> env = new HashMap<>(); env.put("WORKING_DIR", workingDirectory.getAbsolutePath()); env.put("TEMP_DIR", tempDirectory.getAbsolutePath()); env.put("INPUT_DIR", inputDirectory.getAbsolutePath()); env.put("OUTPUT_DIR", outputDirectory.getAbsolutePath()); fout = new FileOutputStream(new File(tempDirectory, "stdout.log")); ferr = new FileOutputStream(new File(tempDirectory, "stderr.log")); LOGGER.debug("Setting stream handler for stdout and stderr."); executor.setStreamHandler(new PumpStreamHandler(fout, ferr)); LOGGER.debug("Creating .RUNNING file for monitoring."); FileUtils.touch(runningIndicator); LOGGER.debug("Executing process."); int exitCode = executor.execute(cmdLine); if (exitCode != 0) { throw new DataWorkflowProcessingException( "Execution returned exit code " + exitCode + ". See logfiles for details."); } else { LOGGER.debug("Process successfully finished with exit code {}", exitCode); } } catch (IOException | UnsupportedOperatingSystemException e) { throw new DataWorkflowProcessingException("Failed to start executable for task " + pTask.getId(), e); } finally { LOGGER.debug("Removing running indicator file {}", runningIndicator); FileUtils.deleteQuietly(runningIndicator); if (fout != null) { try { fout.close(); } catch (IOException ex) { } } if (ferr != null) { try { ferr.close(); } catch (IOException ex) { } } } }
From source file:ml.shifu.shifu.util.CommonUtilsTest.java
public void syncUpEvalTest() throws IOException { ModelConfig config = ModelConfig.createInitModelConfig(".", ALGORITHM.NN, "test", false); config.setModelSetName("shifu"); File file = new File("evals/EvalA"); if (!file.exists()) { FileUtils.forceMkdir(file);/*from ww w .j a v a 2 s. c om*/ } file = new File("testEval/EvalConfig.json"); FileUtils.touch(file); // CommonUtils.copyEvalConfFromLocalToHDFS(config, "testEval"); Assert.assertTrue(file.exists()); FileUtils.deleteDirectory(new File("ModelSets")); FileUtils.deleteDirectory(new File("evals")); }
From source file:com.linkedin.pinot.core.segment.index.column.ColumnIndexContainer.java
private static BitmapInvertedIndexReader createAndLoadInvertedIndexFor(String column, DataFileReader fwdIndex, ColumnMetadata metadata, File invertedIndexFile, ReadMode mode, File indexDir) throws IOException { File inProgress = new File(column + "_inv.inprogress"); // returning inverted index from file only when marker file does not exist and inverted file exist if (!inProgress.exists() && invertedIndexFile.exists()) { LOGGER.warn("found inverted index for colummn {}, loading it", column); return new BitmapInvertedIndexReader(invertedIndexFile, metadata.getCardinality(), mode == ReadMode.mmap);/*from w w w .j av a2 s .c o m*/ } // creating the marker file FileUtils.touch(inProgress); if (invertedIndexFile.exists()) { // if inverted index file exists, it means that we got an exception while creating inverted index last time // deleting it FileUtils.deleteQuietly(invertedIndexFile); } LOGGER.warn("did not find inverted index for colummn {}, creating it", column); // creating inverted index for the column now InvertedIndexCreator creator = new BitmapInvertedIndexCreator(indexDir, metadata.getCardinality(), metadata.toFieldSpec()); if (!metadata.isSingleValue()) { SingleColumnMultiValueReader mvFwdIndex = (SingleColumnMultiValueReader) fwdIndex; int[] container = new int[metadata.getMaxNumberOfMultiValues()]; for (int i = 0; i < metadata.getTotalDocs(); i++) { int len = mvFwdIndex.getIntArray(i, container); Integer[] dicIds = new Integer[len]; for (int j = 0; j < len; j++) { dicIds[j] = container[j]; } creator.add(i, dicIds); } } else { FixedBitCompressedSVForwardIndexReader svFwdIndex = (FixedBitCompressedSVForwardIndexReader) fwdIndex; for (int i = 0; i < metadata.getTotalDocs(); i++) { creator.add(i, svFwdIndex.getInt(i)); } } creator.seal(); // delete the marker file FileUtils.deleteQuietly(inProgress); LOGGER.warn("created inverted index for colummn {}, loading it", column); return new BitmapInvertedIndexReader(invertedIndexFile, metadata.getCardinality(), mode == ReadMode.mmap); }
From source file:com.comcast.cats.domain.configuration.CatsHome.java
/** * Make sure these directories exist by "touching" a temporary file inside * tmp.// w w w.jav a2 s . co m * * @throws IOException */ protected void createDirectoryStructure() throws IOException { FileUtils.touch(new File(getTouchFile())); }