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.liferay.portal.deploy.DeployUtil.java

public static void redeployJetty(String context) throws Exception {
    String contextsDirName = System.getProperty("jetty.home") + "/contexts";

    File contextXml = new File(contextsDirName + "/" + context + ".xml");

    if (contextXml.exists()) {
        FileUtils.touch(contextXml);
    } else {/*  w w w.j  a  va 2 s  .  c o  m*/
        Map<String, String> filterMap = new HashMap<String, String>();

        filterMap.put("context", context);

        copyDependencyXml("jetty-context-configure.xml", contextsDirName, context + ".xml", filterMap, true);
    }
}

From source file:com.googlecode.t7mp.scanner.ModifiedFileTimerTask.java

@Override
public void run() {
    long timeStamp = lastrun;
    lastrun = System.currentTimeMillis();
    Set<File> fileSet = FileUtil.getAllFiles(rootDirectory);
    Collection<File> changedFiles = Collections2.filter(fileSet,
            Predicates.and(new ModifiedFilePredicate(timeStamp), new FileSuffixPredicate(suffixe)));
    for (File file : changedFiles) {
        String absolutePath = file.getAbsolutePath();
        String def = getResourceDef(absolutePath);

        int endIndex = absolutePath.lastIndexOf(def);
        String copyFragment = absolutePath.substring(endIndex + def.length());
        File copyToFile = new File(webappDirectory, copyFragment);
        log.debug("CHANGED: " + absolutePath);
        log.debug("COPY TO : " + copyToFile.getAbsolutePath());
        try {/*from   ww  w .  j  a  v a2s  .  co  m*/
            FileUtils.copyFile(file, copyToFile);
            FileUtils.touch(copyToFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    log.debug("-----------END SCAN-------------");
}

From source file:net.paissad.jcamstream.utils.PropertiesConfTest.java

private final int isEmpty_1() throws IOException {
    PropertiesConf props = new PropertiesConf();
    FileUtils.touch(tempFile);
    props.load(new FileInputStream(tempFile));
    return (props.isEmpty()) ? 0 : 1;
}

From source file:com.BuildCraft.utils.Settings.java

public void checkSettings() {
    if (!file.exists()) {
        ConsoleOut.printMsg("Settings: Creating new settings " + file.getName());
        try {//from  w w  w.j  a  v  a  2 s  .  co  m
            FileUtils.touch(file);
        } catch (IOException ex) {
            ConsoleOut.doError("Failed to generate settings " + file.getName());
        }
        aValues = defaults;
        if (saveSettings()) {
            ConsoleOut.printMsg("Settings: File creation successful!");
        } else {
            ConsoleOut.doError("Failed to generate settings " + file.getName());
        }
    } else {
        ConsoleOut.printMsg("Settings: Loaded settings " + file.getName());
    }
}

From source file:com.cedarsoft.file.FileNamesTest.java

License:asdf

@Test
public void testParse() throws IOException {
    File dir = TestUtils.createEmptyTmpDir();

    try {//from  w w  w  .  j  ava2 s .c  o m
        FileUtils.touch(new File(dir, "1.jpg"));
        FileUtils.touch(new File(dir, "2.jpg"));
        FileUtils.touch(new File(dir, "3.jpg"));
        FileUtils.touch(new File(dir, "4.jpg"));
        FileUtils.touch(new File(dir, "5.jpg"));
        FileUtils.touch(new File(dir, "5.cr2"));

        FileNames fileNames = new FileNamesFactory(new FileTypeRegistry()).create(dir);

        assertEquals(6, fileNames.getFileNames().size());
    } finally {
        FileUtils.deleteDirectory(dir);
    }
}

From source file:edu.ku.brc.specify.config.init.DBLocationPanel.java

/**
 * Creates a dialog for entering database name and selecting the appropriate driver.
 *//*from   ww w .  j a v a 2 s  . co  m*/
public DBLocationPanel(final JButton nextBtn) {
    super("Storage", null, nextBtn, null);

    localDirOK = true;
    File currentPath = new File(UIRegistry.getAppDataDir() + File.separator + "specify_tmp.tmp");
    try {
        FileUtils.touch(currentPath);
        currentPath.delete();

    } catch (IOException ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DBLocationPanel.class, ex);
        localDirOK = false;
    }

    //localDirOK = false ; // XXX TESTING

    ButtonGroup grp = new ButtonGroup();
    useHomeRB = new JRadioButton(
            "<html>Use your home directory: <b>" + UIRegistry.getUserHomeAppDir() + "</b></html>");
    grp.add(useHomeRB);
    useHomeRB.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (browse != null) {
                browse.setEnabled(false);
            }
            updateBtnUI();
        }
    });

    int numRows = 3;
    StringBuilder header = new StringBuilder(
            "<html>This step requires you to select a storage for the database.");
    //localDirOK = false; // DEBUG
    if (localDirOK) {
        header.append("There are three options:</html>");

        useCurrentRB = new JRadioButton(
                "<html>Use your current directory: <b>" + UIRegistry.getDefaultWorkingPath() + "</b></html>");
        grp.add(useCurrentRB);
        useCurrentRB.setSelected(true);
        numRows++;

    } else {
        header.append(
                "<br>The database cannot be stored on the media you are currently running Workbench from, ");
        header.append(
                "so you can allow it to default to your '<i>home</i>' directory. Or choose a different storage.</html>");
        useHomeRB.setSelected(true);
    }

    useUserDefinedRB = new JRadioButton("Use other storage:");
    grp.add(useUserDefinedRB);
    useUserDefinedRB.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            browse.setEnabled(true);
            updateBtnUI();
        }
    });

    filePath = new JTextField(30);
    filePath.getDocument().addDocumentListener(new DocumentListener() {
        public void insertUpdate(DocumentEvent e) {
            updateBtnUI();
        }

        public void removeUpdate(DocumentEvent e) {
            updateBtnUI();
        }

        public void changedUpdate(DocumentEvent e) {
            updateBtnUI();
        }
    });
    browse = new BrowseBtnPanel(filePath, true, true);
    browse.setEnabled(false);

    CellConstraints cc = new CellConstraints();

    JLabel lbl = new JLabel(header.toString());
    PanelBuilder cmtBldr = new PanelBuilder(new FormLayout("f:min(300px;p):g", "f:p:g"));
    cmtBldr.add(lbl, cc.xy(1, 1));

    PanelBuilder builder = new PanelBuilder(new FormLayout("p,2px,p:g",
            "p:g,2px," + UIHelper.createDuplicateJGoodiesDef("p", "2px", numRows) + ",f:p:g"), this);
    int row = 1;

    builder.add(cmtBldr.getPanel(), cc.xywh(1, row, 3, 1));
    row += 2;
    builder.add(useHomeRB, cc.xy(1, row));
    row += 2;
    if (useCurrentRB != null) {
        builder.add(useCurrentRB, cc.xy(1, row));
        row += 2;
    }
    builder.add(useUserDefinedRB, cc.xy(1, row));
    row += 2;
    builder.add(browse, cc.xy(1, row));
    row += 2;

}

From source file:io.apiman.manager.api.war.WarApiManagerBootstrapperServlet.java

/**
 * @see javax.servlet.GenericServlet#init()
 *//*from  w  w w  . ja v  a  2  s .  c  o  m*/
@Override
public void init() throws ServletException {
    Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
            // Wait 5s before doing this - hopefully dependencies will have started up by then
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e1) {
            }
            File dataDir = getDataDir();
            if (dataDir != null && dataDir.isDirectory()) {
                logger.debug("Checking for bootstrap files in " + dataDir); //$NON-NLS-1$
                Collection<File> files = FileUtils.listFiles(dataDir, new String[] { "json" }, false); //$NON-NLS-1$
                TreeSet<File> sortedFiles = new TreeSet<>(files);
                for (File file : sortedFiles) {
                    File alreadyProcessed = new File(file.getAbsolutePath() + ".imported"); //$NON-NLS-1$
                    if (!alreadyProcessed.isFile()) {
                        doImport(file);
                        try {
                            FileUtils.touch(alreadyProcessed);
                        } catch (IOException e) {
                        }
                    } else {
                        logger.debug("Skipping (already processed) file: " + file); //$NON-NLS-1$
                    }
                }
            }
        }
    });
    t.setDaemon(true);
    t.start();
}

From source file:ke.co.tawi.babblesms.server.persistence.utils.DbFileUtils.java

/**
 * This is used to export the results of an SQL query into a CSV text file.
 *
 * @param sqlQuery/*  ww w. ja  v  a 2 s. co  m*/
 * @param fileName this should include the full path of the file e.g.
 * /tmp/myFile.csv
 * @param delimiter
 *
 * @return whether the action was successful or not
 */
public boolean sqlResultToCSV(String sqlQuery, String fileName, char delimiter) {
    boolean success = true;

    String sanitizedQuery = StringUtils.remove(sqlQuery, ';');

    BufferedWriter writer;

    try (
            // Return a database connection that is not pooled
            // to enable the connection to be cast to BaseConnection
            Connection conn = dbCredentials.getJdbcConnection();) {

        FileUtils.deleteQuietly(new File(fileName));
        FileUtils.touch(new File(fileName));
        writer = new BufferedWriter(new FileWriter(fileName));

        CopyManager copyManager = new CopyManager((BaseConnection) conn);

        StringBuffer query = new StringBuffer("COPY (").append(sanitizedQuery)
                .append(") to STDOUT WITH DELIMITER '").append(delimiter).append("'");

        copyManager.copyOut(query.toString(), writer);
        writer.close();

    } catch (SQLException e) {
        logger.error(
                "SQLException while exporting results of query '" + sqlQuery + "' to file '" + fileName + "'.");
        logger.error(ExceptionUtils.getStackTrace(e));
        success = false;

    } catch (IOException e) {
        logger.error(
                "IOException while exporting results of query '" + sqlQuery + "' to file '" + fileName + "'.");
        logger.error(ExceptionUtils.getStackTrace(e));
        success = false;
    }

    return success;
}

From source file:com.thoughtworks.go.agent.launcher.Lockfile.java

void touch() throws IOException {
    FileUtils.touch(lockFile);
}

From source file:com.liferay.portal.deploy.DeployUtil.java

public static void redeployTomcat(String context) throws Exception {
    File webXml = new File(getAutoDeployDestDir(), "/WEB-INF/web.xml");

    FileUtils.touch(webXml);
}