Example usage for org.apache.commons.io FileUtils touch

List of usage examples for org.apache.commons.io FileUtils touch

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils touch.

Prototype

public static void touch(File file) throws IOException 

Source Link

Document

Implements the same behaviour as the "touch" utility on Unix.

Usage

From source file:com.walmart.gatling.endpoint.v1.FileUploadController.java

@RequestMapping(method = RequestMethod.POST, value = "/upload")
public String handleFileUpload(@RequestParam("name") String name, @RequestParam("role") String role,
        @RequestParam("type") String type, @RequestParam("file") MultipartFile file,
        RedirectAttributes redirectAttributes) {

    if (!file.isEmpty()) {
        try {/*from   w ww .  ja v a 2  s .  com*/
            String path = tempFileDir + "/" + name;
            System.out.println(path);
            FileUtils.touch(new File(path));
            BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(new File(path)));
            FileCopyUtils.copy(file.getInputStream(), stream);
            stream.close();
            Optional<String> trackingId = serverRepository.uploadFile(path, name, role, type);
            redirectAttributes.addFlashAttribute("message", "You successfully uploaded " + name + "! ");

            redirectAttributes.addFlashAttribute("link", "/#/file/" + trackingId.get());
        } catch (Exception e) {
            redirectAttributes.addFlashAttribute("message",
                    "You failed to upload " + name + " => " + e.getMessage());
        }
    } else {
        redirectAttributes.addFlashAttribute("message",
                "You failed to upload " + name + " because the file was empty");
    }

    return "redirect:upload";
}

From source file:com.github.neio.filesystem.paths.FilePath.java

@Override
public void touch() throws FilesystemException {
    try {//from   w  w  w  .  ja  v  a 2 s.co m
        FileUtils.touch(platformFile);
    } catch (IOException e) {
        throw new FilesystemException("Unable to touch file [" + super.getPath() + "]", e);
    }
}

From source file:de.tudarmstadt.ukp.dkpro.spelling.io.SpellingErrorInContextEvaluator.java

@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
    super.initialize(context);

    performanceCounter = new SpellingErrorPerformanceCounter();

    try {//ww  w . j  a v a 2 s  .  co m
        if (outputFile == null) {
            outputFile = new File("target/output.txt");
        }
        if (outputFile.exists()) {
            outputFile.delete();
        }
        FileUtils.touch(outputFile);
        writer = new BufferedWriter(new FileWriter(outputFile));

        if (labOutputFile != null) {
            if (labOutputFile.exists()) {
                labOutputFile.delete();
            }
            FileUtils.touch(labOutputFile);
            labWriter = new BufferedWriter(new FileWriter(labOutputFile));
        } else {
            labWriter = null;
        }
    } catch (IOException e) {
        throw new ResourceInitializationException(e);
    }
}

From source file:com.orange.mmp.dao.flf.MidletDaoFlfImpl.java

public void delete(Midlet midlet) throws MMPDaoException {
    Midlet[] pfmList = this.find(midlet);
    try {//  ww w .ja va 2  s  . co m
        this.lock.lock();
        for (Midlet toDelete : pfmList) {
            FileUtils.deleteDirectory(new File(this.path, toDelete.getType()));
        }
        FileUtils.touch(new File(this.path));
    } catch (IOException ioe) {
        throw new MMPDaoException("failed to delete PFM : " + ioe.getMessage());
    } finally {
        this.lock.unlock();
    }
}

From source file:com.ning.metrics.collector.processing.TestEventSpoolWriterFactory.java

private void testProcessLeftBelowFilesAllClean() throws Exception {
    final EventSpoolWriterFactory factory = new EventSpoolWriterFactory(
            new HashSet<EventSpoolProcessor>(Arrays.asList(new NoWriteHadoopWriterFactory(null, config))),
            config, configFactory);/*from w  w  w .  j  a v a 2s.  c  o m*/
    factory.setCutoffTime(CUTOFF_TIME);

    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
            .listFiles(spoolDirectory, FileFilterUtils.trueFileFilter(), FileFilterUtils.trueFileFilter())
            .size(), 3);
    Assert.assertTrue(spoolDirectory.exists());
    Assert.assertTrue(tmpDirectory.exists());
    Assert.assertTrue(lockDirectory.exists());
    Assert.assertTrue(quarantineDirectory.exists());

    Thread.sleep(2 * CUTOFF_TIME);

    factory.processLeftBelowFiles();

    // All files should have been sent
    Assert.assertFalse(spoolDirectory.exists());
    Assert.assertFalse(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:hoot.services.controllers.ingest.BasemapResourceTest.java

@Test
@Category(UnitTest.class)
public void TestToggleBasemap() throws Exception {
    BasemapResource mapRes = new BasemapResource();
    File f = new File(mapRes._ingestStagingPath + "/BASEMAP/controltest.enabled");
    FileUtils.touch(f);
    mapRes._toggleBaseMap("controltest", false);
    f = new File(mapRes._ingestStagingPath + "/BASEMAP/controltest.disabled");
    org.junit.Assert.assertTrue(f.exists());

    mapRes._toggleBaseMap("controltest", true);

    f = new File(mapRes._ingestStagingPath + "/BASEMAP/controltest.enabled");
    org.junit.Assert.assertTrue(f.exists());

    FileUtils.forceDelete(f);/*from   w ww . j  a v  a2  s.  co  m*/
}

From source file:br.edu.ufcg.lsd.commune.context.PropertiesFileParser.java

private Map<Object, Object> getDefaultProperties(File propertiesFile) {

    Properties properties = new Properties();

    properties.putAll(new DefaultContextFactory().getDefaultProperties());
    try {//from  ww  w  .j av  a2 s  .  c  o  m
        FileUtils.touch(propertiesFile);

        FileOutputStream fileOutputStream = new FileOutputStream(propertiesFile);
        properties.store(fileOutputStream, null);
        fileOutputStream.close();

    } catch (Exception e) {
        e.printStackTrace();
        throw new CommuneRuntimeException("File could not be created: " + fileName);
    }
    return properties;
}

From source file:com.linkedin.pinot.core.segment.index.converter.SegmentV1V2ToV3FormatConverterTest.java

@BeforeMethod
public void setUp() throws Exception {

    INDEX_DIR = Files.createTempDirectory(SegmentV1V2ToV3FormatConverter.class.getName() + "_segmentDir")
            .toFile();//from   w w  w . ja  va2 s.c o m

    final String filePath = TestUtils.getFileFromResourceUrl(
            SegmentV1V2ToV3FormatConverter.class.getClassLoader().getResource(AVRO_DATA));

    // intentionally changed this to TimeUnit.Hours to make it non-default for testing
    final SegmentGeneratorConfig config = SegmentTestUtils.getSegmentGenSpecWithSchemAndProjectedColumns(
            new File(filePath), INDEX_DIR, "daysSinceEpoch", TimeUnit.HOURS, "testTable");
    config.setSegmentNamePostfix("1");
    config.setTimeColumnName("daysSinceEpoch");
    final SegmentIndexCreationDriver driver = SegmentCreationDriverFactory.get(null);
    driver.init(config);
    driver.build();
    segmentDirectory = new File(INDEX_DIR, driver.getSegmentName());
    File starTreeFile = new File(segmentDirectory, V1Constants.STAR_TREE_INDEX_FILE);
    FileUtils.touch(starTreeFile);
    FileUtils.writeStringToFile(starTreeFile, "This is a star tree index");
    Configuration tableConfig = new PropertiesConfiguration();
    tableConfig.addProperty(IndexLoadingConfigMetadata.KEY_OF_SEGMENT_FORMAT_VERSION, "v1");
    v1LoadingConfig = new IndexLoadingConfigMetadata(tableConfig);

    tableConfig.clear();
    tableConfig.addProperty(IndexLoadingConfigMetadata.KEY_OF_SEGMENT_FORMAT_VERSION, "v3");
    v3LoadingConfig = new IndexLoadingConfigMetadata(tableConfig);
}

From source file:com.comcast.cats.domain.configuration.CatsProperties.java

protected void loadPropertiesFromFile() throws IOException {
    /**/*from w  w w  .  ja v  a 2  s  . com*/
     * Touch the cats props to make sure we have one. If one exists the
     * updated time will be changed.
     */
    logger.info("Loading cats.props [" + catsPropsFileName + "]");
    File catsPropsFile = new File(catsPropsFileName);

    FileUtils.touch(catsPropsFile);
    this.load(new FileInputStream(catsPropsFile));
}

From source file:com.palantir.paxos.PaxosStateLogImpl.java

public PaxosStateLogImpl(String path) {
    this.path = path;
    try {/*from   w ww  .  j  av a  2s.  c  o m*/
        FileUtils.forceMkdir(new File(path));
        if (getGreatestLogEntry() == PaxosAcceptor.NO_LOG_ENTRY) {
            // For a brand new log, we create a lowest entry so #getLeastLogEntry will return the right thing
            // If we didn't add this then we could miss seq 0 and accept seq 1, then when we restart we will
            // start ignoring seq 0 which may cause things to get stalled
            FileUtils.touch(new File(path, getFilenameFromSeq(PaxosAcceptor.NO_LOG_ENTRY)));
        }
    } catch (IOException e) {
        throw new RuntimeException("IO problem related to the path " + new File(path).getAbsolutePath(), e);
    }
}