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.moscona.dataSpace.debug.BadLocks.java

public static void main(String[] args) {
    try {/*from  ww w.  j  a va  2  s.  c  om*/
        String lockFile = "C:\\Users\\Admin\\projects\\intellitrade\\tmp\\bad.lock";
        FileUtils.touch(new File(lockFile));
        FileOutputStream stream = new FileOutputStream(lockFile);
        //            FileInputStream stream = new FileInputStream(lockFile);
        FileChannel channel = stream.getChannel();
        //            FileLock lock = channel.lock(0,Long.MAX_VALUE, true);
        FileLock lock = channel.lock();
        stream.write(new UndocumentedJava().pid().getBytes());
        stream.flush();
        long start = System.currentTimeMillis();
        //            while (System.currentTimeMillis()-start < 10000) {
        //                Thread.sleep(500);
        //            }
        lock.release();
        stream.close();
        File f = new File(lockFile);
        System.out.println("Before write: " + FileUtils.readFileToString(f));
        FileUtils.writeStringToFile(f, "written after lock released");
        System.out.println("After write: " + FileUtils.readFileToString(f));
    } catch (Exception e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    }

}

From source file:com.foudroyantfactotum.mod.fousarchive.utility.midi.FileSupporter.java

public static void main(String[] args) throws InterruptedException, IOException {
    for (int i = 0; i < noOfWorkers; ++i)
        pool.submit(new ConMidiDetailsPuller());

    final File sourceDir = new File(source);
    final File outputDir = new File(output);

    Logger.info(UserLogger.GENERAL, "source directory: " + sourceDir.getAbsolutePath());
    Logger.info(UserLogger.GENERAL, "output directory: " + outputDir.getAbsolutePath());
    Logger.info(UserLogger.GENERAL, "processing midi files using " + noOfWorkers + " cores");

    FileUtils.deleteDirectory(outputDir);
    FileUtils.touch(new File(outputDir + "/master.json.gz"));

    for (File sfile : sourceDir.listFiles()) {
        recFile(sfile, files);//from  w  w  w . ja v  a2  s  . c  om
    }

    for (int i = 0; i < noOfWorkers; ++i)
        files.put(TERMINATOR);

    pool.shutdown();
    pool.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);//just get all the work done first.

    try (final OutputStream fstream = new FileOutputStream(outputDir + "/master.json.gz")) {
        try (final GZIPOutputStream gzstream = new GZIPOutputStream(fstream)) {
            final OutputStreamWriter osw = new OutputStreamWriter(gzstream);

            osw.write(JSON.toJson(processedMidiFiles));
            osw.flush();
        }
    } catch (IOException e) {
        Logger.info(UserLogger.GENERAL, e.toString());
    }

    Logger.info(UserLogger.GENERAL, "Processed " + processedMidiFiles.size() + " midi files out of " + fileCount
            + " files. " + (fileCount - processedMidiFiles.size()) + " removed");
}

From source file:com.cloudant.sync.datastore.DatastoreTestUtils.java

public static SQLDatabase createDatabase(String database_dir, String database_file)
        throws IOException, SQLException {
    String path = database_dir + File.separator + database_file + DATABASE_FILE_EXT;
    File dbFile = new File(path);
    FileUtils.touch(dbFile);
    SQLDatabase database = SQLDatabaseFactory.openSqlDatabase(dbFile.getAbsolutePath());
    SQLDatabaseFactory.updateSchema(database, DatastoreConstants.getSchemaVersion3(), 3);
    SQLDatabaseFactory.updateSchema(database, DatastoreConstants.getSchemaVersion4(), 4);
    SQLDatabaseFactory.updateSchema(database, DatastoreConstants.getSchemaVersion5(), 5);
    return database;
}

From source file:com.splunk.shuttl.archiver.util.UtilsFile.java

/**
 * Creates a {@link File} and its parents without throwing exceptions. See
 * {@link FileUtils#touch(File)}//from w  w  w .  j  a v  a 2  s  .  com
 */
public static void touch(File file) {
    try {
        FileUtils.touch(file);
    } catch (IOException e) {
        logger.debug(did("Tried to create file and its parents", "Got IOException", "The file to be created",
                "file", file, "exception", e));
        throw new RuntimeException(e);
    }
}

From source file:com.cloudant.sync.util.TestUtils.java

public static SQLDatabase createEmptyDatabase(String database_dir, String database_file)
        throws IOException, SQLException {
    File dbFile = new File(database_dir + File.separator + database_file + DATABASE_FILE_EXT);
    FileUtils.touch(dbFile);
    SQLDatabase database = SQLDatabaseFactory.openSqlDatabase(dbFile.getAbsolutePath());
    return database;
}

From source file:com.mbrlabs.mundus.utils.TerrainIO.java

/**
 * Binary gziped format./*from  ww  w  .j  av a2s . c o m*/
 *
 * @param terrain
 */
public static void exportTerrain(ProjectContext projectContext, Terrain terrain) {
    float[] data = terrain.heightData;
    long start = System.currentTimeMillis();

    // create file
    File file = new File(FilenameUtils.concat(projectContext.path, terrain.terraPath));
    try {
        FileUtils.touch(file);
    } catch (IOException e) {
        e.printStackTrace();
    }

    // write .terra
    try (DataOutputStream outputStream = new DataOutputStream(
            new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file))))) {

        for (float f : data) {
            outputStream.writeFloat(f);
        }
        outputStream.flush();
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }

    // write splatmap
    SplatMap splatmap = terrain.getTerrainTexture().getSplatmap();
    if (splatmap != null) {
        splatmap.savePNG(Gdx.files.absolute(FilenameUtils.concat(projectContext.path, splatmap.getPath())));
    }

    //Log.debug("Terrain export execution time (" + data.length + " floats): "
    //        + (System.currentTimeMillis() - start) + " ms");
}

From source file:de.tudarmstadt.ukp.dkpro.core.frequency.tfidf.util.TfidfUtils.java

public static void serialize(Object object, String fileName) throws Exception {
    File file = new File(fileName);
    if (!file.exists())
        FileUtils.touch(file);
    if (file.isDirectory()) {
        throw new IOException("A directory with that name exists!");
    }// ww w .j  a v a2s.co  m
    ObjectOutputStream objOut;
    objOut = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
    objOut.writeObject(object);
    objOut.flush();
    objOut.close();

}

From source file:kaljurand_at_gmail_dot_com.diktofon.MyFileUtils.java

public static void createNomedia() {
    File f = Dirs.getNomediaFile();
    if (!f.exists()) {
        try {/*w w  w  . jav  a2  s  . co  m*/
            FileUtils.touch(f);
        } catch (IOException e) {
        }
    }
}

From source file:com.enonic.cms.core.boot.HomeResolverTest.java

@Before
public void setUp() throws Exception {
    this.tmpDir = new File(SystemUtils.getJavaIoTmpDir(), "tmp-" + UUID.randomUUID().toString());
    this.defaultHomeDir = new File(this.tmpDir, "cms.home").getCanonicalFile();
    this.invalidHomeDir = new File(this.tmpDir, "invalid.home").getCanonicalFile();
    this.validHomeDir = new File(this.tmpDir, "valid.home").getCanonicalFile();
    this.notCreatedHomeDir = new File(this.tmpDir, "not.created.home").getCanonicalFile();

    this.defaultHomeDir.mkdirs();
    this.validHomeDir.mkdirs();
    FileUtils.touch(this.invalidHomeDir);
}

From source file:com.leverno.ysbos.item.domain.ItemTest.java

public void setUp() throws Exception {
    super.setUp();

    rootFolder = new String("/tmp/archiverTest/");
    FileUtils.forceMkdir(new File(rootFolder));

    fileOne = new File(String.format("%s/one", rootFolder));
    FileUtils.touch(fileOne);
}