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

The following are Jave code examples for showing how to use canExecute() of the java.io.File class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: flume-release-1.7.0   File: TestUtil.java   View Source Code Vote up 7 votes
@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);
}
 
Example 2
Project: sstore-soft   File: TarGenerator.java   View Source Code Vote up 6 votes
/**
         * This method is so-named because it only sets the owner privileges,
         * not any "group" or "other" privileges.
         * <P/>
         * This is because of Java limitation.
         * Incredibly, with Java 1.6, the API gives you the power to set
         * privileges for "other" (last nibble in file Mode), but no ability
         * to detect the same.
         */
        static protected String getLameMode(File file) {

            int umod = 0;

//#ifdef JAVA6
            if (file.canExecute()) {
                umod = 1;
            }

//#endif
            if (file.canWrite()) {
                umod += 2;
            }

            if (file.canRead()) {
                umod += 4;
            }

            return "0" + umod + "00";

            // Conservative since Java gives us no way to determine group or
            // other privileges on a file, and this file may contain passwords.
        }
 
Example 3
Project: Cybernet-VPN   File: VPNLaunchHelper.java   View Source Code Vote up 6 votes
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 4
Project: Equella   File: LibAvCallback.java   View Source Code Vote up 6 votes
private File findExe(Wizard installer, File path, String exe)
{
	for( String exeType : EXE_TYPES )
	{
		File exeFile = new File(path, exe + exeType);
		if( exeFile.canExecute() )
		{
			return exeFile;
		}
	}

	JOptionPane.showMessageDialog(installer.getFrame(),
		"The directory you have specified" + " does not contain the Libav program '" + exe
			+ "'.\nPlease select the" + " correct path, and try again.", "Incorrect LibAv Directory",
		JOptionPane.ERROR_MESSAGE);
	return null;
}
 
Example 5
Project: VirusTotal-public-and-private-API-2.0-implementation-in-pure-Java   File: Engine.java   View Source Code Vote up 5 votes
FileScanMetaData scanFile(File file) throws FileNotFoundException, IOException {
    if (!isNull(file) && file.canExecute()) {
        String fileName = file.getName();
        try (FileInputStream fileInputStream = new FileInputStream(file)) {
            return scanFile(fileName, fileInputStream);
        }
    } else {
        throw new InvalidFileException("A valid java.io.File is required");
    }
}
 
Example 6
Project: openjdk-jdk10   File: Jexec.java   View Source Code Vote up 5 votes
Jexec() throws IOException {
    jexecCmd = new File(JAVA_LIB, "jexec");
    if (!jexecCmd.exists() || !jexecCmd.canExecute()) {
        throw new Error("jexec: does not exist or not executable");
    }

    testJar = new File("test.jar");
    StringBuilder tsrc = new StringBuilder();
    tsrc.append("public static void main(String... args) {\n");
    tsrc.append("   for (String x : args) {\n");
    tsrc.append("        System.out.println(x);\n");
    tsrc.append("   }\n");
    tsrc.append("}\n");
    createJar(testJar, tsrc.toString());
}
 
Example 7
Project: openjdk-jdk10   File: RunpathTest.java   View Source Code Vote up 5 votes
final String findElfReader() {
    String[] paths = {"/usr/sbin", "/usr/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 8
Project: marathonv5   File: LaunchWebStartTest.java   View Source Code Vote up 5 votes
public static String getPathTo(String name) throws AssertionError {
    String path = System.getenv("Path");
    if (path == null)
        path = System.getenv("PATH");
    for (String dirname : path.split(File.pathSeparator)) {
        File file = new File(dirname, name);
        if (file.isFile() && file.canExecute()) {
            return file.getAbsolutePath();
        }
    }
    return null;
}
 
Example 9
Project: talchain   File: Solc.java   View Source Code Vote up 5 votes
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();
    }
}
 
Example 10
Project: rskj   File: Solc.java   View Source Code Vote up 5 votes
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 {
        throw new RuntimeException("No Solc version provided. Check if 'solc.path' config is set.");
    }
}
 
Example 11
Project: JRF   File: FileInfos.java   View Source Code Vote up 5 votes
public FileInfos(File f) {
	name = f.getName();
	if (name.isEmpty()) // Happens when 'f' is a root
		name = f.getPath();
	length = f.length();
	lastModified = f.lastModified();
	attributes = 0;
	if (f.isDirectory()) attributes |= BIT_ISDIRECTORY;
	if (f.isFile())      attributes |= BIT_ISFILE;
	if (f.isHidden())    attributes |= BIT_ISHIDDEN;
	if (f.canRead())     attributes |= BIT_CANREAD;
	if (f.canWrite())    attributes |= BIT_CANWRITE;
	if (f.canExecute())  attributes |= BIT_CANEXECUTE;
}
 
Example 12
Project: SmartMath   File: IOLib.java   View Source Code Vote up 5 votes
public static boolean isExecutable(String strPath) throws JFCALCExpErrException {
    File f = getFileFromCurrentDir(strPath);
    try {
        return f.canExecute();
    } catch (Exception e) {
        throw new JFCALCExpErrException(ERRORTYPES.ERROR_CANNOT_ACCESS_FILE);
    }
}
 
Example 13
Project: Equella   File: ExecUtils.java   View Source Code Vote up 5 votes
public static File findExe(File path, String exe)
{
	for( String exeType : EXE_TYPES )
	{
		File exeFile = new File(path, exe + exeType);
		if( exeFile.exists() && exeFile.canExecute() )
		{
			return exeFile;
		}
	}
	return null;
}
 
Example 14
Project: jdk8u-jdk   File: Utils.java   View Source Code Vote up 5 votes
static String getAjavaCmd(String cmdStr) {
    File binDir = new File(JavaHome, "bin");
    File unpack200File = IsWindows
            ? new File(binDir, cmdStr + ".exe")
            : new File(binDir, cmdStr);

    String cmd = unpack200File.getAbsolutePath();
    if (!unpack200File.canExecute()) {
        throw new RuntimeException("please check" +
                cmd + " exists and is executable");
    }
    return cmd;
}
 
Example 15
Project: openjdk-jdk10   File: UnixCommands.java   View Source Code Vote up 5 votes
private static String findCommand0(String name) {
    for (String path : paths) {
        File file = new File(path, name);
        if (file.canExecute()) {
            return file.getPath();
        }
    }
    return null;
}
 
Example 16
Project: csap-core   File: FileRequests.java   View Source Code Vote up 4 votes
private void addUserReadPermissions ( File targetFile ) {

		String[] lines = {
				"#!/bin/bash",
				"setfacl -m u:" + csapApp.getAgentRunUser() + ":r " + targetFile.getAbsolutePath(),
				"" };

		String[] result = runScriptAndUseRootIfPermitted( "permissions", lines );

		StringBuilder results = new StringBuilder( "Updating access using setfacl: " + targetFile.getAbsolutePath() );

		results.append( "\nCommand: " + Arrays.asList( lines ) + "\n Result:" + Arrays.asList( result ) );

		File parentFolder = targetFile.getParentFile();

		logger.debug( "parentFolderL {}, exists: {}, canExecute: {}, read: {}",
			parentFolder.getAbsolutePath(), parentFolder.exists(), parentFolder.canExecute(), parentFolder.canRead() );
		int maxDepth = 8;
		while ((maxDepth-- > 0)
				&& (parentFolder != null)
				&& (!parentFolder.canExecute() || !parentFolder.canRead())) {

			String[] parentLines = {
					"#!/bin/bash",
					"setfacl -m u:" + csapApp.getAgentRunUser() + ":rx " + parentFolder.getAbsolutePath(),
					"" };

			String[] parentResult = runScriptAndUseRootIfPermitted( "permissions", parentLines );

			results.append( "\nCommand: " + Arrays.asList( parentLines ) + "\n Result:" + Arrays.asList( parentResult ) );
			parentFolder = parentFolder.getParentFile();
		}

		csapEventClient.generateEvent( CsapEventClient.CSAP_OS_CATEGORY + "/file/permissions",
			securityConfig.getUserIdFromContext(),
			"Adding read permissions: " + getFileNameForEvents( targetFile, 50 ),
			results.toString() );

		logger.debug( "Result: {}", results );

		return;
	}
 
Example 17
Project: cythara   File: PipeDecoder.java   View Source Code Vote up 4 votes
public PipeDecoder(){
	pipeBuffer = 10000;

	//Use sensible defaults depending on the platform
	if(System.getProperty("os.name").indexOf("indows") > 0 ){
		pipeEnvironment = "cmd.exe";
		pipeArgument = "/C";
	}else if(new File("/bin/bash").exists()){
		pipeEnvironment = "/bin/bash";
		pipeArgument = "-c";
	}else if (new File("/system/bin/sh").exists()){
		//probably we are on android here
		pipeEnvironment = "/system/bin/sh";
		pipeArgument = "-c";
	}else{
		LOG.severe("Coud not find a command line environment (cmd.exe or /bin/bash)");
		throw new Error("Decoding via a pipe will not work: Coud not find a command line environment (cmd.exe or /bin/bash)");
	}
	
	String path = System.getenv("PATH");
	String arguments = " -ss %input_seeking%  %number_of_seconds% -i \"%resource%\" -vn -ar %sample_rate% -ac %channels% -sample_fmt s16 -f s16le pipe:1";
	if(isAvailable("ffmpeg")){
		LOG.info("found ffmpeg on the path (" + path + "). Will use ffmpeg for decoding media files.");
		pipeCommand = "ffmpeg" + arguments;	
	}else if (isAvailable("avconv")){
		LOG.info("found avconv on your path(" + path + "). Will use avconv for decoding media files.");
		pipeCommand = "avconv" + arguments;
	}else {
		if(isAndroid()) {
			String tempDirectory = System.getProperty("java.io.tmpdir");
			printErrorstream=true;
			File f = new File(tempDirectory, "ffmpeg");
			if (f.exists() && f.length() > 1000000 && f.canExecute()) {
				decoderBinaryAbsolutePath = f.getAbsolutePath();
			} else {
				LOG.severe("Could not find an ffmpeg binary for your Android system. Did you forget calling: 'new AndroidFFMPEGLocator(this);' ?");
				LOG.severe("Tried to unpack a statically compiled ffmpeg binary for your architecture to: " + f.getAbsolutePath());
			}
		}else{
			LOG.warning("Dit not find ffmpeg or avconv on your path(" + path + "), will try to download it automatically.");
			FFMPEGDownloader downloader = new FFMPEGDownloader();
			decoderBinaryAbsolutePath = downloader.ffmpegBinary();
			if(decoderBinaryAbsolutePath==null){
				LOG.severe("Could not download an ffmpeg binary automatically for your system.");
			}
		}
		if(decoderBinaryAbsolutePath == null){
			pipeCommand = "false";
			throw new Error("Decoding via a pipe will not work: Could not find an ffmpeg binary for your system");
		}else{
			pipeCommand = '"' + decoderBinaryAbsolutePath + '"' + arguments;
		}
	}
}
 
Example 18
Project: cythara   File: AndroidFFMPEGLocator.java   View Source Code Vote up 4 votes
private boolean ffmpegIsCorrectlyInstalled(){
    File ffmpegTargetLocation = AndroidFFMPEGLocator.ffmpegTargetLocation();
    //assumed to be correct if existing and executable and larger than 1MB:
    return ffmpegTargetLocation.exists() && ffmpegTargetLocation.canExecute() && ffmpegTargetLocation.length() > 1000000;
}
 
Example 19
Project: jcommander-ext   File: ExistsDirectoryExecutable.java   View Source Code Vote up 4 votes
@Override
protected boolean check(File value) {
	return value.exists() && value.isDirectory() && value.canExecute();
}
 
Example 20
Project: AndroTickler   File: FileUtil.java   View Source Code Vote up 2 votes
/**
 * Returns whether a file is executable, used with dex2jar and other external tools
 * @param path
 * @return
 */
public boolean isExecutable(String path){
	File file = new File(path);
	return file.canExecute();
}