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:com.igormaznitsa.jcp.utils.PreprocessorUtils.java

public static void copyFileAttributes(@Nonnull final File from, @Nonnull final File to) {
    to.setExecutable(from.canExecute());
    to.setReadable(from.canRead());/*w ww  . j  ava2  s. co  m*/
    to.setWritable(from.canWrite());
}

From source file:io.github.bonigarcia.wdm.Downloader.java

private static File checkPhantom(File archive, String export) throws IOException {
    File target = null;/*from   w  ww  .  ja  v a2 s .co  m*/
    String phantomName = "phantomjs";
    if (export.contains(phantomName)) {
        String fileNoExtension = archive.getName().replace(".tar.bz2", "").replace(".zip", "");

        File phantomjs = null;
        try {
            phantomjs = new File(archive.getParentFile().getAbsolutePath() + File.separator + fileNoExtension
                    + File.separator + "bin" + File.separator).listFiles()[0];
        } catch (Exception e) {
            String extension = IS_OS_WINDOWS ? ".exe" : "";
            phantomjs = new File(archive.getParentFile().getAbsolutePath() + File.separator + fileNoExtension
                    + File.separator + phantomName + extension);
        }

        target = new File(archive.getParentFile().getAbsolutePath() + File.separator + phantomjs.getName());
        phantomjs.renameTo(target);

        File delete = new File(archive.getParentFile().getAbsolutePath() + File.separator + fileNoExtension);
        log.trace("Folder to be deleted: {}", delete);
        FileUtils.deleteDirectory(delete);
    } else {
        File[] ls = archive.getParentFile().listFiles();
        for (File f : ls) {
            if (IS_OS_WINDOWS) {
                if (f.getName().endsWith(".exe")) {
                    target = f;
                    break;
                }
            } else if (f.canExecute()) {
                target = f;
                break;
            }
        }
    }
    return target;
}

From source file:com.google.dart.tools.core.utilities.io.FileUtilities.java

/**
 * Ensure that the given file exists and is executable. If it exists but is not executable, then
 * make it executable and log that it was necessary for us to do so.
 * <p>//from w  w w .jav a 2s.  c om
 * Originally copied from the engine project
 * 
 * @return {@code true} if the file exists and is executable, else {@code false}.
 */
public static boolean ensureExecutable(File file) {
    if (file == null || !file.exists()) {
        return false;
    }
    if (!file.canExecute()) {
        Logger logger = AnalysisEngine.getInstance().getLogger();
        if (!makeExecutable(file)) {
            logger.logError(file + " cannot be made executable");
            return false;
        }
        logger.logError(file + " was not executable");
    }
    return true;
}

From source file:com.dumontierlab.pdb2rdf.Pdb2Rdf.java

private static Pdb2RdfInputIterator processInput(CommandLine cmd) {
    boolean gzip = cmd.hasOption("gzip");
    try {//  w w  w.ja v  a  2s.co  m
        if (cmd.hasOption("file")) {
            File file = new File(cmd.getOptionValue("file"));
            if (!file.exists() || !file.canRead()) {
                LOG.fatal("Cannot access file: " + file);
                System.exit(1);
            }
            return new Pdb2RdfInputIteratorAdapter(new FileIterator(file, gzip));
        } else if (cmd.hasOption("dir")) {
            File dir = new File(cmd.getOptionValue("dir"));
            if (!dir.exists() || !dir.canRead() || !dir.canExecute()) {
                LOG.fatal("Cannot access directory: " + dir);
                System.exit(1);
            }
            return new Pdb2RdfInputIteratorAdapter(new DirectoryIterator(dir, gzip));
        } else if (cmd.hasOption("cluster")) {
            String url = cmd.getOptionValue("cluster");
            return new ClusterIterator(url);
        } else {
            String[] args = cmd.getArgs();
            if (args.length == 0) {
                LOG.fatal(
                        "You need to specified the file option, the dir option, or explicitly list the pdb ids.");
                printUsage();
                System.exit(1);
            }
            return new PdbsIterator(args);
        }
    } catch (Exception e) {
        LOG.fatal(e);
        System.exit(1);
        return null;
    }
}

From source file:com.google.dart.tools.update.core.internal.UpdateUtils.java

/**
 * Ensure that the execute bit is set on the given files.
 * //  w  w w.j ava2  s .co m
 * @param files the files that should be executable
 */
public static void ensureExecutable(File... files) {
    if (files != null) {
        for (File file : files) {
            if (!file.canExecute()) {
                if (!makeExecutable(file)) {
                    UpdateCore.logError("Could not make " + file.getAbsolutePath() + " executable");
                }
            }
        }
    }
}

From source file:com.asakusafw.runtime.util.hadoop.ConfigurationProvider.java

private static File findHadoopCommandFromPath(Map<String, String> envp) {
    String path = envp.get(ENV_PATH);
    if (path != null && path.trim().isEmpty() == false) {
        String[] pathPrefixArray = path.split(Pattern.quote(File.pathSeparator));
        for (String prefix : pathPrefixArray) {
            String p = prefix.trim();
            if (p.isEmpty()) {
                continue;
            }//from  ww  w  . ja v  a  2s  .  c  o  m
            File bin = new File(p);
            if (bin.isDirectory() == false) {
                continue;
            }
            File command = new File(bin, PATH_HADOOP_COMMAND_FILE);
            if (command.canExecute()) {
                return command;
            }
        }
    }
    return null;
}

From source file:com.excelsiorjet.maven.plugin.JetMojo.java

private static void compressDirectoryToZipfile(String rootDir, String sourceDir, ZipArchiveOutputStream out)
        throws IOException {
    File[] files = new File(sourceDir).listFiles();
    assert files != null;
    for (File file : files) {
        if (file.isDirectory()) {
            compressDirectoryToZipfile(rootDir, sourceDir + File.separator + file.getName(), out);
        } else {/*w ww .  j a v a 2  s. c  o m*/
            ZipArchiveEntry entry = new ZipArchiveEntry(file.getAbsolutePath().substring(rootDir.length() + 1));
            if (Utils.isUnix() && file.canExecute()) {
                entry.setUnixMode(0100777);
            }
            out.putArchiveEntry(entry);
            InputStream in = new BufferedInputStream(
                    new FileInputStream(sourceDir + File.separator + file.getName()));
            IOUtils.copy(in, out);
            IOUtils.closeQuietly(in);
            out.closeArchiveEntry();
        }
    }
}

From source file:org.rapidcontext.util.FileUtil.java

/**
 * Copies a file or a directory. Directories are copied
 * recursively and file modification dates are kept. If the
 * executable bit is set on the source file, that bit will also
 * be set on the destination file./*from w  ww .  j av  a  2 s . c om*/
 *
 * @param src            the source file or directory
 * @param dst            the destination file or directory
 *
 * @throws IOException if some file couldn't be copied
 */
@SuppressWarnings("resource")
public static void copy(File src, File dst) throws IOException {
    if (src.isDirectory()) {
        dst.mkdirs();
        File[] files = src.listFiles();
        for (int i = 0; i < files.length; i++) {
            copy(files[i], new File(dst, files[i].getName()));
        }
    } else {
        copy(new FileInputStream(src), dst);
        dst.setExecutable(src.canExecute());
    }
    dst.setLastModified(src.lastModified());
}

From source file:com.excelsiorjet.api.util.Utils.java

private static void compressDirectoryToZipfile(String rootDir, String sourceDir, ZipArchiveOutputStream out)
        throws IOException {
    File[] files = new File(sourceDir).listFiles();
    assert files != null;
    for (File file : files) {
        if (file.isDirectory()) {
            compressDirectoryToZipfile(rootDir, sourceDir + File.separator + file.getName(), out);
        } else {//from w w w .j ava2  s  .co  m
            ZipArchiveEntry entry = new ZipArchiveEntry(file.getAbsolutePath().substring(rootDir.length() + 1));
            if (Host.isUnix()) {
                if (file.canExecute()) {
                    //set -rwxr-xr-x
                    entry.setUnixMode(0100755);
                } else {
                    //set -rw-r--r--
                    entry.setUnixMode(0100644);
                }
            }
            out.putArchiveEntry(entry);
            try (InputStream in = new BufferedInputStream(
                    new FileInputStream(sourceDir + File.separator + file.getName()))) {
                copy(in, out);
            }
            out.closeArchiveEntry();
        }
    }
}

From source file:org.asqatasun.runner.Asqatasun.java

/**
 * /*from   ww  w  .  j a  v  a2 s . co  m*/
 * @param path
 * @param option
 * @param testWritable
 * @return whether the given path is valid for the given argument
 */
private static boolean isValidPath(String path, String option, boolean testWritable) {
    File file = FileUtils.getFile(path);
    if (file.exists() && file.canExecute() && file.canRead()) {
        if (!testWritable) {
            return true;
        } else if (file.canWrite()) {
            return true;
        }
    }
    System.out.println("\n" + path + " is an invalid path for " + option + " option.\n");
    return false;
}