Java Code Examples for java.io.File#canExecute()

The following examples show how to use java.io.File#canExecute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VPNLaunchHelper.java    From android with GNU General Public License v3.0 6 votes vote down vote up
static private String writeMiniVPN(Context context) {
       String[] abis;
       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
           abis = getSupportedAbisLollipop();
       else
           abis = new String[]{Build.CPU_ABI, Build.CPU_ABI2};

       for (String abi: abis) {

           File mvpnout = new File(context.getCacheDir(), getMiniVPNExecutableName() + "." + abi);
           if ((mvpnout.exists() && mvpnout.canExecute()) || writeMiniVPNBinary(context, abi, mvpnout)) {
               return mvpnout.getPath();
           }
       }

       return null;
}
 
Example 2
Source File: VPNLaunchHelper.java    From Cake-VPN with GNU General Public License v2.0 6 votes vote down vote up
private static String writeMiniVPN(Context context) {
    String[] abis;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) abis = getSupportedABIsLollipop();
    else
        //noinspection deprecation
        abis = new String[]{Build.CPU_ABI, Build.CPU_ABI2};
    String nativeAPI = NativeUtils.getNativeAPI();
    if (!nativeAPI.equals(abis[0])) {
        VpnStatus.logWarning(R.string.abi_mismatch, Arrays.toString(abis), nativeAPI);
        abis = new String[]{nativeAPI};
    }
    for (String abi : abis) {
        File vpnExecutable = new File(context.getCacheDir(), getMiniVPNExecutableName() + "." + abi);
        if ((vpnExecutable.exists() && vpnExecutable.canExecute()) || writeMiniVPNBinary(context, abi, vpnExecutable)) {
            return vpnExecutable.getPath();
        }
    }
    return null;
}
 
Example 3
Source File: DebuggersRegistry.java    From aCute with Eclipse Public License 2.0 6 votes vote down vote up
public static DebuggerInfo getDefaultDebugger() {
	URL netcoredbgUrl = FileLocator.find(AcutePlugin.getDefault().getBundle(), new Path("netcoredbg")); //$NON-NLS-1$
	if (netcoredbgUrl != null) {
		try {
			netcoredbgUrl = FileLocator.toFileURL(netcoredbgUrl);
			File dbgDir = new File(netcoredbgUrl.toURI().normalize()).getAbsoluteFile();
			if (!dbgDir.canExecute() && dbgDir.canExecute()) {
				Files.setPosixFilePermissions(dbgDir.toPath(), Collections.singleton(PosixFilePermission.OWNER_EXECUTE));
			}
			return new DebuggerInfo(new File(dbgDir,Platform.OS_WIN32.equals(Platform.getOS()) ? "netcoredbg.exe" : "netcoredbg"), Collections.singletonList("--interpreter=vscode")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		} catch (IOException | URISyntaxException ex) {
			AcutePlugin.logError(ex);
		}
	}
	return new DebuggerInfo(new File("/home/mistria/apps/netcoredbg-linux-master/netcoredbg/netcoredbg"), Collections.singletonList("--interpreter=vscode")); //$NON-NLS-1$ //$NON-NLS-2$
}
 
Example 4
Source File: CommandLine.java    From testcontainers-java with MIT License 6 votes vote down vote up
/**
 * Check whether an executable exists, either at a specific path (if a full path is given) or
 * on the PATH.
 *
 * @param executable the name of an executable on the PATH or a complete path to an executable that may/may not exist
 * @return  whether the executable exists and is executable
 */
public static boolean executableExists(String executable) {

    // First check if we've been given the full path already
    File directFile = new File(executable);
    if (directFile.exists() && directFile.canExecute()) {
        return true;
    }

    for (String pathString : getSystemPath()) {
        Path path = Paths.get(pathString);
        if (Files.exists(path.resolve(executable)) && Files.isExecutable(path.resolve(executable))) {
            return true;
        }
    }

    return false;
}
 
Example 5
Source File: CActionProvider.java    From binnavi with Apache License 2.0 6 votes vote down vote up
/**
 * Prompts the user for the location of the IDA executable.
 * 
 * @param parent Parent component used to display dialogs.
 * @param initialDirectory The directory to select by default.
 * 
 * @return The selected IDA executable or null if no executable was selected.
 */
public static String selectIDADirectory(final Component parent, final String initialDirectory) {
  Preconditions.checkNotNull(parent, "IE02067: Parent argument can not be null");
  Preconditions.checkNotNull(initialDirectory, "IE02259: Initial directory can not be null");

  final CIdaSelectionDialog dialog =
      CIdaSelectionDialog.show(SwingUtilities.getWindowAncestor(parent), initialDirectory);

  final File selectedFile = dialog.getSelectedFile();

  if (selectedFile == null) {
    return null;
  } else if (!selectedFile.exists()) {
    CMessageBox.showError(parent, "File does not exist.");

    return null;
  } else if (selectedFile.canExecute()) {
    return selectedFile.getAbsolutePath();
  } else {
    CMessageBox.showError(parent, "File is not an executable file.");

    return null;
  }
}
 
Example 6
Source File: FileManager.java    From JavaExercises with GNU General Public License v2.0 6 votes vote down vote up
public Object getValueAt(int row, int column) {
    File file = files[row];
    switch (column) {
        case 0:
            return fileSystemView.getSystemIcon(file);
        case 1:
            return fileSystemView.getSystemDisplayName(file);
        case 2:
            return file.getPath();
        case 3:
            return file.length();
        case 4:
            return file.lastModified();
        case 5:
            return file.canRead();
        case 6:
            return file.canWrite();
        case 7:
            return file.canExecute();
        default:
            System.err.println("Logic Error");
    }
    return "";
}
 
Example 7
Source File: RunnerJava.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs path to Java VM executable and verifies if it exists.
 * <p/>
 * @param server Payara server entity object.
 * @param command lassFish server administration command with local Java VM.
 * @return Path to Java VM executable
 */
private static String getJavaVM(final PayaraServer server,
        final CommandJava command) {
    final String METHOD = "getJavaVM";
    String javaVmExe = JavaUtils.javaVmExecutableFullPath(command.javaHome);
    File javaVmFile = new File(javaVmExe);
    // Java VM executable should exist and should be executable.
    if (!javaVmFile.canExecute()) {
        LOGGER.log(Level.INFO, METHOD, "noJavaVMExe", javaVmExe);
        return null;
    }
    return javaVmExe;
}
 
Example 8
Source File: IPCClientService.java    From Repeat with Apache License 2.0 5 votes vote down vote up
public void setExecutingProgram(File executablePath) {
	if (!executablePath.canExecute()) {
		LOGGER.warning("File is not executable: " + executablePath.getAbsolutePath());
		return;
	}

	this.executingProgram = executablePath;
}
 
Example 9
Source File: AudioInfoDialog.java    From GreenDamFileExploere with Apache License 2.0 5 votes vote down vote up
private void setReadWrite(File file) {
    StringBuilder builder = new StringBuilder();
    if (file.canRead()) {
        builder.append("可读");
    }
    if (file.canWrite()) {
        if (builder.length() > 0) {
            builder.append("/可写");
        } else {
            builder.append("可写");
        }
    }

    if (file.canExecute()) {
        if (file.isFile()) {
            if (builder.length() > 0) {
                builder.append("/可执行");
            } else {
                builder.append("可执行");
            }
        } else if (file.isDirectory()) {
            if (builder.length() > 0) {
                builder.append("/可进入");
            } else {
                builder.append("可进入");
            }
        }
    }

    if (builder.length() == 0) {
        builder.append("无权限");
    }
    mTvAudioInfoReadWrite.setText(builder.toString());
}
 
Example 10
Source File: Rdaemon.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
static void setRecursiveExecutable(File path) {
  for (File f : path.listFiles()) {
    if (f.isDirectory()) {
      f.setExecutable(true);
      setRecursiveExecutable(f);
    } else if (!f.canExecute() && (f.getName().endsWith(".so") || f.getName().endsWith(".dll"))) {
      f.setExecutable(true);
    }
  }

}
 
Example 11
Source File: RootPresenter.java    From WIFIADB with Apache License 2.0 5 votes vote down vote up
public void chooseADBPath(@NotNull VirtualFile vFile) {
    final File adbFile = findADB(vFile);

    if (adbFile == null || !adbFile.canExecute() || !adbFile.getName().equalsIgnoreCase("adb")) {
        fail2FindADB();
    } else {
        checkAdbAvailable(adbFile);
    }
}
 
Example 12
Source File: BashInterpreterDetection.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
public boolean isSuitable(String guessLocation) {
    if (guessLocation == null) {
        return false;
    }

    File f = new File(guessLocation);
    return f.isFile() && f.canRead() && f.canExecute();
}
 
Example 13
Source File: RunpathTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
final String findElfReader() {
    String[] paths = {"/bin", "/sbin", "/usr/bin", "/usr/sbin", "/usr/ccs/bin"};
    final String cmd = isSolaris ? "elfdump" : "readelf";
    for (String x : paths) {
        File p = new File(x);
        File e = new File(p, cmd);
        if (e.canExecute()) {
            return e.getAbsolutePath();
        }
    }
    System.err.println("Warning: no suitable elf reader!");
    return null;
}
 
Example 14
Source File: WebInterfaceServer.java    From stratosphere with Apache License 2.0 5 votes vote down vote up
/**
 * Checks and creates the directory described by the abstract directory path. This function checks
 * if the directory exists and creates it if necessary. It also checks read permissions and
 * write permission, if necessary.
 * 
 * @param dir
 *        The String describing the directory path.
 * @param needWritePermission
 *        A flag indicating whether to check write access.
 * @throws IOException
 *         Thrown, if the directory could not be created, or if one of the checks failed.
 */
private final void checkAndCreateDirectories(File f, boolean needWritePermission) throws IOException {
	String dir = f.getAbsolutePath();

	// check if it exists and it is not a directory
	if (f.exists() && !f.isDirectory()) {
		throw new IOException("A none directory file with the same name as the configured directory '" + dir
			+ "' already exists.");
	}

	// try to create the directory
	if (!f.exists()) {
		if (!f.mkdirs()) {
			throw new IOException("Could not create the directory '" + dir + "'.");
		}
	}

	// check the read and execute permission
	if (!(f.canRead() && f.canExecute())) {
		throw new IOException("The directory '" + dir + "' cannot be read and listed.");
	}

	// check the write permission
	if (needWritePermission && !f.canWrite()) {
		throw new IOException("No write access could be obtained on directory '" + dir + "'.");
	}
}
 
Example 15
Source File: KuduLocal.java    From geowave with Apache License 2.0 5 votes vote down vote up
private boolean isInstalled() {
  final File kuduMasterBinary = new File(kuduLocalDir, KUDU_MASTER);
  final File kuduTabletBinary = new File(kuduLocalDir, KUDU_TABLET);
  final boolean okMaster = kuduMasterBinary.exists() && kuduMasterBinary.canExecute();
  final boolean okTablet = kuduTabletBinary.exists() && kuduTabletBinary.canExecute();
  return okMaster && okTablet;
}
 
Example 16
Source File: SimpleExecutableFinder.java    From synopsys-detect with Apache License 2.0 5 votes vote down vote up
@Nullable
public File findExecutable(final String executable, final List<File> locations) {
    final List<String> executables = executablesFromName(executable);

    for (final File location : locations) {
        for (final String possibleExecutable : executables) {
            final File foundFile = fileFinder.findFile(location, possibleExecutable);
            if (foundFile != null && foundFile.exists() && foundFile.canExecute()) {
                return foundFile;
            }
        }
    }

    return null;
}
 
Example 17
Source File: Permissions.java    From SimpleExplorer with GNU General Public License v3.0 5 votes vote down vote up
public static String getBasicPermission(File file) {
    String per = "";

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

    return per;
}
 
Example 18
Source File: GaugeUtil.java    From Intellij-Plugin with Apache License 2.0 4 votes vote down vote up
private static boolean isValidGaugeExec(File file) {
    return file.exists() && file.isFile() && file.canExecute();
}
 
Example 19
Source File: CF6Impl.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public boolean canExecute(File file) {
  return file.canExecute();
}
 
Example 20
Source File: ServerBootstrapClassLoader.java    From actframework with Apache License 2.0 4 votes vote down vote up
private boolean verifyDir(File dir) {
    return dir.exists() && dir.canExecute() && dir.isDirectory();
}