本文整理了Java中java.io.File.canExecute()
方法的一些代码示例,展示了File.canExecute()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。File.canExecute()
方法的具体详情如下:
包路径:java.io.File
类名称:File
方法名:canExecute
[英]Tests whether or not this process is allowed to execute this file. Note that this is a best-effort result; the only way to be certain is to actually attempt the operation.
[中]测试是否允许此进程执行此文件。请注意,这是一个尽力而为的结果;唯一确定的方法是实际尝试该操作。
代码示例来源:origin: gocd/gocd
public static boolean isDirectoryReadable(File directory) {
return directory.canRead() && directory.canExecute() && directory.listFiles() != null;
}
代码示例来源:origin: azkaban/azkaban
private void validate() {
if (!this.binaryExecutable.canExecute()) {
throw new RuntimeException("Unable to execute execute-as-user binary. Invalid Path: "
+ this.binaryExecutable.getAbsolutePath());
}
}
代码示例来源:origin: jphp-group/jphp
public static boolean is_executable(String path) {
return new File(path).canExecute();
}
代码示例来源:origin: KronicDeth/intellij-elixir
public static boolean pathIsValidSdkHome(String path) {
File bin = new File(path, "bin").getAbsoluteFile();
File elixir = new File(bin, "elixir");
File elixirc = new File(bin, "elixirc");
File iex = new File(bin, "iex");
File mix = new File(bin, "mix");
return elixir.canExecute() && elixirc.canExecute() && iex.canExecute() && mix.canExecute();
}
代码示例来源:origin: plantuml/plantuml
private static String findExecutableOnPath(String name) {
for (String dirname : System.getenv("PATH").split(File.pathSeparator)) {
File file = new File(dirname, name);
if (file.isFile() && file.canExecute()) {
return file.getAbsolutePath();
}
}
return null;
}
代码示例来源:origin: netty/netty
private static boolean canExecuteExecutable(File file) throws IOException {
if (PlatformDependent.javaVersion() < 7) {
// Pre-JDK7, the Java API did not directly support POSIX permissions; instead of implementing a custom
// work-around, assume true, which disables the check.
return true;
}
// If we can already execute, there is nothing to do.
if (file.canExecute()) {
return true;
}
// On volumes, with noexec set, even files with the executable POSIX permissions will fail to execute.
// The File#canExecute() method honors this behavior, probaby via parsing the noexec flag when initializing
// the UnixFileStore, though the flag is not exposed via a public API. To find out if library is being
// loaded off a volume with noexec, confirm or add executalbe permissions, then check File#canExecute().
// Note: We use FQCN to not break when netty is used in java6
Set<java.nio.file.attribute.PosixFilePermission> existingFilePermissions =
java.nio.file.Files.getPosixFilePermissions(file.toPath());
Set<java.nio.file.attribute.PosixFilePermission> executePermissions =
EnumSet.of(java.nio.file.attribute.PosixFilePermission.OWNER_EXECUTE,
java.nio.file.attribute.PosixFilePermission.GROUP_EXECUTE,
java.nio.file.attribute.PosixFilePermission.OTHERS_EXECUTE);
if (existingFilePermissions.containsAll(executePermissions)) {
return false;
}
Set<java.nio.file.attribute.PosixFilePermission> newPermissions = EnumSet.copyOf(existingFilePermissions);
newPermissions.addAll(executePermissions);
java.nio.file.Files.setPosixFilePermissions(file.toPath(), newPermissions);
return file.canExecute();
}
代码示例来源:origin: alibaba/jstorm
private static List<String> generateCommands(String filePath) {
File path = new File(filePath);
List<String> commands = new ArrayList<>();
if (path.exists()) {
File[] files = path.listFiles();
if (files == null) {
return commands;
}
for (File file : files) {
if (!file.isDirectory() && file.canExecute()) {
commands.add(file.getAbsolutePath());
}
}
}
LOG.debug("The generated check commands are {}", commands);
return commands;
}
代码示例来源:origin: twosigma/beakerx
public String findMvn() {
if (mavenLocation == null) {
if (System.getenv("M2_HOME") != null) {
mavenLocation = System.getenv("M2_HOME") + "/bin/mvn";
return mavenLocation;
}
for (String dirname : System.getenv("PATH").split(File.pathSeparator)) {
File file = new File(dirname, "mvn");
if (file.isFile() && file.canExecute()) {
mavenLocation = file.getAbsolutePath();
return mavenLocation;
}
}
throw new RuntimeException("No mvn found, please install mvn by 'conda install maven' or setup M2_HOME");
}
return mavenLocation;
}
代码示例来源:origin: KronicDeth/intellij-elixir
@Override
public boolean isValidSdkHome(String path) {
File erl = Erlang.getByteCodeInterpreterExecutable(path);
return erl.canExecute();
}
代码示例来源:origin: jphp-group/jphp
@Signature
public Memory canExecute(Environment env, Memory... args){
return file.canExecute() ? Memory.TRUE : Memory.FALSE;
}
代码示例来源:origin: redisson/redisson
private static boolean canExecuteExecutable(File file) throws IOException {
if (PlatformDependent.javaVersion() < 7) {
// Pre-JDK7, the Java API did not directly support POSIX permissions; instead of implementing a custom
// work-around, assume true, which disables the check.
return true;
}
// If we can already execute, there is nothing to do.
if (file.canExecute()) {
return true;
}
// On volumes, with noexec set, even files with the executable POSIX permissions will fail to execute.
// The File#canExecute() method honors this behavior, probaby via parsing the noexec flag when initializing
// the UnixFileStore, though the flag is not exposed via a public API. To find out if library is being
// loaded off a volume with noexec, confirm or add executalbe permissions, then check File#canExecute().
// Note: We use FQCN to not break when netty is used in java6
Set<java.nio.file.attribute.PosixFilePermission> existingFilePermissions =
java.nio.file.Files.getPosixFilePermissions(file.toPath());
Set<java.nio.file.attribute.PosixFilePermission> executePermissions =
EnumSet.of(java.nio.file.attribute.PosixFilePermission.OWNER_EXECUTE,
java.nio.file.attribute.PosixFilePermission.GROUP_EXECUTE,
java.nio.file.attribute.PosixFilePermission.OTHERS_EXECUTE);
if (existingFilePermissions.containsAll(executePermissions)) {
return false;
}
Set<java.nio.file.attribute.PosixFilePermission> newPermissions = EnumSet.copyOf(existingFilePermissions);
newPermissions.addAll(executePermissions);
java.nio.file.Files.setPosixFilePermissions(file.toPath(), newPermissions);
return file.canExecute();
}
代码示例来源:origin: KronicDeth/intellij-elixir
@Override
public boolean isValidSdkHome(@NotNull String path) {
File elixir = Elixir.getScriptInterpreterExecutable(path);
File elixirc = Elixir.getByteCodeCompilerExecutable(path);
File iex = Elixir.getIExExecutable(path);
File mix = Elixir.mixFile(path);
// Determine whether everything is can run
return elixir.canExecute() && elixirc.canExecute() && iex.canExecute() && mix.canRead();
}
代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin
@Override
protected GoExecutor patchExecutor(@NotNull GoExecutor executor) throws ExecutionException {
if (isDebug()) {
File dlv = dlv();
if (dlv.exists() && !dlv.canExecute()) {
//noinspection ResultOfMethodCallIgnored
dlv.setExecutable(true, false);
}
return executor.withExePath(dlv.getAbsolutePath())
.withParameters("--listen=localhost:" + myDebugPort, "--headless=true", "exec", myOutputFilePath, "--");
}
return executor.showGoEnvVariables(false).withExePath(myOutputFilePath);
}
代码示例来源:origin: ethereum/ethereumj
private void init(SystemProperties config) throws IOException {
if (config != null && config.customSolcPath() != null) {
solc = new File(config.customSolcPath());
if (!solc.canExecute()) {
throw new RuntimeException(String.format(
"Solidity compiler from config solc.path: %s is not a valid executable",
config.customSolcPath()
));
}
} else {
initBundled();
}
}
代码示例来源:origin: apache/flink
public static void writeFileInfoToConfig(String name, DistributedCacheEntry e, Configuration conf) {
int num = conf.getInteger(CACHE_FILE_NUM, 0) + 1;
conf.setInteger(CACHE_FILE_NUM, num);
conf.setString(CACHE_FILE_NAME + num, name);
conf.setString(CACHE_FILE_PATH + num, e.filePath);
conf.setBoolean(CACHE_FILE_EXE + num, e.isExecutable || new File(e.filePath).canExecute());
conf.setBoolean(CACHE_FILE_DIR + num, e.isZipped || new File(e.filePath).isDirectory());
if (e.blobKey != null) {
conf.setBytes(CACHE_FILE_BLOB_KEY + num, e.blobKey);
}
}
代码示例来源:origin: gocd/gocd
public CommandSnippets getAllCommandSnippets(String repositoryDirectory) {
serverHealthService.update(ServerHealthState.success(HealthStateType.commandRepositoryAccessibilityIssue()));
try {
File commandRepositoryDirectory = new File(repositoryDirectory);
//adding the exists check till packaging command repository with Go story is played.
if (commandRepositoryDirectory.isDirectory() && commandRepositoryDirectory.canRead() && commandRepositoryDirectory.canExecute()) {
return new CommandSnippets(walk(commandRepositoryDirectory));
} else {
throw new IOException("Failed to access command repository located in Go Server Directory at " + repositoryDirectory +
". The directory does not exist or Go does not have sufficient permissions to access it.");
}
} catch (IOException e) {
ServerHealthState serverHealthState = ServerHealthState.warning("Command Repository", e.getMessage(), HealthStateType.commandRepositoryAccessibilityIssue(),
systemEnvironment.getCommandRepoWarningTimeout());
serverHealthService.update(serverHealthState);
LOGGER.warn(e.getMessage());
}
return new CommandSnippets(new ArrayList<>());
}
代码示例来源:origin: gocd/gocd
@Test
public void shouldReturnTrueIfDirectoryIsReadable() throws IOException {
File readableDirectory = mock(File.class);
when(readableDirectory.canRead()).thenReturn(true);
when(readableDirectory.canExecute()).thenReturn(true);
when(readableDirectory.listFiles()).thenReturn(new File[]{});
assertThat(FileUtil.isDirectoryReadable(readableDirectory), is(true));
File unreadableDirectory = mock(File.class);
when(readableDirectory.canRead()).thenReturn(false);
when(readableDirectory.canExecute()).thenReturn(false);
assertThat(FileUtil.isDirectoryReadable(unreadableDirectory), is(false));
verify(readableDirectory).canRead();
verify(readableDirectory).canExecute();
verify(readableDirectory).listFiles();
verify(unreadableDirectory).canRead();
verify(unreadableDirectory, never()).canExecute();
}
代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin
@Override
public boolean isValidSdkHome(@NotNull String path) {
GoSdkService.LOG.debug("Validating sdk path: " + path);
String executablePath = GoSdkService.getGoExecutablePath(path);
if (executablePath == null) {
GoSdkService.LOG.debug("Go executable is not found: ");
return false;
}
if (!new File(executablePath).canExecute()) {
GoSdkService.LOG.debug("Go binary cannot be executed: " + path);
return false;
}
if (getVersionString(path) != null) {
GoSdkService.LOG.debug("Cannot retrieve version for sdk: " + path);
return true;
}
return false;
}
代码示例来源:origin: docker-java/docker-java
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (attrs.isSymbolicLink()) { // symbolic link to folder
return FileVisitResult.CONTINUE;
}
TarArchiveEntry tarEntry = new TarArchiveEntry(FilePathUtil.relativize(basePath, file));
if (file.toFile().canExecute()) {
tarEntry.setMode(tarEntry.getMode() | 0755);
}
CompressArchiveUtil.putTarEntry(tarArchiveOutputStream, tarEntry, file);
return FileVisitResult.CONTINUE;
}
代码示例来源:origin: apache/storm
@Override
public FileStatus getFileStatus(Path path) throws IOException {
File file = pathToFile(path);
if (!file.exists()) {
throw new FileNotFoundException("Can't find " + path);
}
// get close enough
short mod = 0;
if (file.canRead()) {
mod |= 0444;
}
if (file.canWrite()) {
mod |= 0200;
}
if (file.canExecute()) {
mod |= 0111;
}
ShimLoader.getHadoopShims();
return new FileStatus(file.length(), file.isDirectory(), 1, 1024,
file.lastModified(), file.lastModified(),
FsPermission.createImmutable(mod), "owen", "users", path);
}
}
内容来源于网络,如有侵权,请联系作者删除!