Example usage for java.io File canExecute

List of usage examples for java.io File canExecute

Introduction

In this page you can find the example usage for java.io File canExecute.

Prototype

public boolean canExecute() 

Source Link

Document

Tests whether the application can execute the file denoted by this abstract pathname.

Usage

From source file:de.codesourcery.geoip.trace.TracePath.java

private static boolean isTraceRouteAvailable() {
    final File executable = new File(TRACEROUTE);
    return executable.exists() && executable.canExecute();
}

From source file:com.thoughtworks.go.util.FileUtil.java

public static boolean isDirectoryReadable(File directory) {
    return directory.canRead() && directory.canExecute() && directory.listFiles() != null;
}

From source file:com.dnielfe.manager.dialogs.DirectoryInfoDialog.java

private static String getFilePermissions(File file) {
    String per = "";

    per += file.isDirectory() ? "d" : "-";
    per += file.canRead() ? "r" : "-";
    per += file.canWrite() ? "w" : "-";
    per += file.canExecute() ? "x" : "-";

    return per;/*from  w  w  w .j ava  2s . com*/
}

From source file:org.parakoopa.gmnet.tests.GameMakerCompiler.java

/**
 * Check if game.exe is created, not empty and executeable
 * @return //  w w w.  j  av  a 2  s .c  om
 */
public static boolean gameExeExists() {
    File game = new File(Workspace.COMPILED_GAME_DIR + "/game.exe");

    return game.exists() && game.length() != 0 && game.canExecute();
}

From source file:org.broad.igv.track.CombinedFeatureSource.java

/**
 * Checks the global bedtools path, to see if bedtools
 * is actually there. Check is 2-fold://from w  ww.  j  av  a  2s.c  o m
 * First, we check if path exists.
 * If so, we run version command
 *
 * @return
 */
public static boolean checkBEDToolsPathValid() {
    String path = Globals.BEDtoolsPath;
    File bedtoolsFile = new File(path);
    boolean pathValid = bedtoolsFile.isFile();
    if (pathValid && !bedtoolsFile.canExecute()) {
        log.debug(path + " exists but is not executable. ");
        return false;
    }

    String cmd = path + " --version";
    String resp;
    try {
        resp = RuntimeUtils.executeShellCommand(cmd, null, null);
    } catch (IOException e) {
        log.error(e);
        return false;
    }
    String line0 = resp.split("\n")[0].toLowerCase();
    pathValid &= line0.contains("bedtools v");
    pathValid &= !line0.contains("command not found");
    return pathValid;
}

From source file:org.geopublishing.geopublisher.GpUtil.java

/**
 * this method checks for permission on java.io.tmpdir and changes it to a
 * given path if files in current tmpDir may not be executed. (Possibly due
 * to noexec mountoption on /tmp)/*from  w w w. j a v a  2s  .c  o m*/
 */
public static void checkAndResetTmpDir(String path) {
    if (SystemUtils.IS_OS_UNIX) {
        String tmpDir = System.getProperty("java.io.tmpdir");
        try {
            File file = File.createTempFile("geopublisher", "tmpDirTest", new File(tmpDir));
            file.setExecutable(true);
            if (!file.canExecute()) {
                System.setProperty("java.io.tmpdir", path);
                LOGGER.debug("tmpDir has no execute rights, changing to " + path);
            }
            FileUtils.deleteQuietly(file);
        } catch (IOException e) {
            LOGGER.log(Level.ERROR, e);
        }
    }
}

From source file:org.apache.hadoop.mapred.NodeHealthCheckerService.java

/**
 * Method used to determine if or not node health monitoring service should be
 * started or not. Returns true if following conditions are met:
 * // w  w  w.  ja va  2  s  .c o m
 * <ol>
 * <li>Path to Node health check script is not empty</li>
 * <li>Node health check script file exists</li>
 * </ol>
 * 
 * @param conf
 * @return true if node health monitoring service can be started.
 */
static boolean shouldRun(Configuration conf) {
    String nodeHealthScript = conf.get(HEALTH_CHECK_SCRIPT_PROPERTY);
    if (nodeHealthScript == null || nodeHealthScript.trim().isEmpty()) {
        return false;
    }
    File f = new File(nodeHealthScript);
    return f.exists() && f.canExecute();
}

From source file:org.apache.hadoop.NodeHealthCheckerService.java

/**
 * Method used to determine if or not node health monitoring service should be
 * started or not. Returns true if following conditions are met:
 * // ww  w  .  j av  a  2  s . c  o m
 * <ol>
 * <li>Path to Node health check script is not empty</li>
 * <li>Node health check script file exists</li>
 * </ol>
 * 
 * @param conf
 * @return true if node health monitoring service can be started.
 */
public static boolean shouldRun(Configuration conf) {
    String nodeHealthScript = conf.get(HEALTH_CHECK_SCRIPT_PROPERTY);
    if (nodeHealthScript == null || nodeHealthScript.trim().isEmpty()) {
        return false;
    }
    File f = new File(nodeHealthScript);
    return f.exists() && f.canExecute();
}

From source file:org.apache.kudu.client.MiniKdc.java

private static String getBinaryPath(String executable, List<String> searchPaths) throws IOException {
    for (String path : searchPaths) {
        File f = Paths.get(path).resolve(executable).toFile();
        if (f.exists() && f.canExecute()) {
            return f.getPath();
        }/* ww w. ja  v  a  2 s. co  m*/
    }

    Process which = new ProcessBuilder().command("which", executable).start();
    checkReturnCode(which, "which", false);
    return CharStreams.toString(new InputStreamReader(which.getInputStream())).trim();
}

From source file:io.fabric8.maven.core.util.ProcessUtil.java

public static File findExecutable(Logger log, String name, List<File> directories) {
    for (File directory : directories) {
        for (String extension : isWindows() ? new String[] { ".exe", ".bat", ".cmd", "" }
                : new String[] { "" }) {
            File file = new File(directory, name + extension);
            if (file.exists() && file.isFile()) {
                if (!file.canExecute()) {
                    log.warn("Found %s on the PATH but it is not executable. Ignoring ...", file);
                } else {
                    return file;
                }/* ww  w .jav  a 2s  .c  om*/
            }
        }
    }
    return null;
}