List of usage examples for java.io File canExecute
public boolean canExecute()
From source file:Main.java
public static void main(String[] args) { // create new file File f = new File("c:/text.txt"); // true if the file is executable boolean bool = f.canExecute(); // find the absolute path String a = f.getAbsolutePath(); // prints absolute path System.out.print(a);/*from ww w . j ava 2 s . co m*/ // prints System.out.println(" is executable: " + bool); }
From source file:Main.java
public static void main(String[] args) { File f = new File("test.txt"); boolean bool = f.setExecutable(true); System.out.println("setExecutable() succeeded?: " + bool); bool = f.canExecute(); System.out.print("Can execute?: " + bool); }
From source file:Main.java
public static void main(String[] args) { File f = new File("test.txt"); // set executable() boolean bool = f.setExecutable(true, true); System.out.println("setExecutable() succeeded?: " + bool); // can execute bool = f.canExecute(); System.out.print("Can execute?: " + bool); }
From source file:de.unibi.techfak.bibiserv.util.codegen.Main.java
public static void main(String[] args) { // check & validate cmdline options OptionGroup opt_g = getCMDLineOptionsGroups(); Options opt = getCMDLineOptions();/*from ww w .j av a 2 s.c o m*/ opt.addOptionGroup(opt_g); CommandLineParser cli = new DefaultParser(); try { CommandLine cl = cli.parse(opt, args); if (cl.hasOption("v")) { VerboseOutputFilter.SHOW_VERBOSE = true; } switch (opt_g.getSelected()) { case "V": try { URL jarUrl = Main.class.getProtectionDomain().getCodeSource().getLocation(); String jarPath = URLDecoder.decode(jarUrl.getFile(), "UTF-8"); JarFile jarFile = new JarFile(jarPath); Manifest m = jarFile.getManifest(); StringBuilder versionInfo = new StringBuilder(); for (Object key : m.getMainAttributes().keySet()) { versionInfo.append(key).append(":").append(m.getMainAttributes().getValue(key.toString())) .append("\n"); } System.out.println(versionInfo.toString()); } catch (Exception e) { log.error("Version info could not be read."); } break; case "h": HelpFormatter help = new HelpFormatter(); String header = ""; //TODO: missing infotext StringBuilder footer = new StringBuilder("Supported configuration properties :"); help.printHelp("CodeGen -h | -V | -g [...]", header, opt, footer.toString()); break; case "g": // target dir if (cl.hasOption("t")) { File target = new File(cl.getOptionValue("t")); if (target.isDirectory() && target.canExecute() && target.canWrite()) { config.setProperty("target.dir", cl.getOptionValue("t")); } else { log.error("Target dir '{}' is inaccessible!", cl.getOptionValue("t")); break; } } else { config.setProperty("target.dir", System.getProperty("java.io.tmpdir")); } // project dir if (cl.hasOption("p")) { File project = new File(cl.getOptionValue("p")); if (!project.exists()) { if (!project.mkdirs()) { log.error("Project dir '{}' can't be created!", cl.getOptionValue("p")); break; } } if (project.isDirectory() && project.canExecute() && project.canWrite()) { config.setProperty("project.dir", cl.getOptionValue("p")); } else { log.error("Project dir '{}' is inaccessible!", cl.getOptionValue("p")); break; } } generateAppfromXML(cl.getOptionValue("g")); break; } } catch (ParseException e) { log.error("ParseException occurred while parsing cmdline arguments!\n{}", e.getLocalizedMessage()); } }
From source file:org.voltdb.exportclient.ExportToFileClient.java
public static void main(String[] args) { String[] volt_servers = null; String user = null;//from ww w . ja v a 2s .com String password = null; String nonce = null; char delimiter = '\0'; File outdir = null; int firstfield = 0; int period = 60; char connect = ' '; // either ' ', 'c' or 'a' String dateformatString = "yyyyMMddHHmmss"; boolean batched = false; boolean withSchema = false; String fullDelimiters = null; int throughputMonitorPeriod = 0; boolean autodiscoverTopolgy = true; for (int ii = 0; ii < args.length; ii++) { String arg = args[ii]; if (arg.equals("--help")) { printHelpAndQuit(0); } else if (arg.equals("--discard")) { System.err.println("Option \"--discard\" is no longer supported."); System.err.println("Try org.voltdb.exportclient.DiscardingExportClient."); printHelpAndQuit(-1); } else if (arg.equals("--skipinternals")) { firstfield = 6; } else if (arg.equals("--connect")) { if (args.length < ii + 1) { System.err.println("Error: Not enough args following --connect"); printHelpAndQuit(-1); } String connectStr = args[ii + 1]; if (connectStr.equalsIgnoreCase("admin")) { connect = 'a'; } else if (connectStr.equalsIgnoreCase("client")) { connect = 'c'; } else { System.err.println("Error: --type must be one of \"admin\" or \"client\""); printHelpAndQuit(-1); } ii++; } else if (arg.equals("--servers")) { if (args.length < ii + 1) { System.err.println("Error: Not enough args following --servers"); printHelpAndQuit(-1); } volt_servers = args[ii + 1].split(","); ii++; } else if (arg.equals("--type")) { if (args.length < ii + 1) { System.err.println("Error: Not enough args following --type"); printHelpAndQuit(-1); } String type = args[ii + 1]; if (type.equalsIgnoreCase("csv")) { delimiter = ','; } else if (type.equalsIgnoreCase("tsv")) { delimiter = '\t'; } else { System.err.println("Error: --type must be one of CSV or TSV"); printHelpAndQuit(-1); } ii++; } else if (arg.equals("--outdir")) { if (args.length < ii + 1) { System.err.println("Error: Not enough args following --outdir"); printHelpAndQuit(-1); } boolean invalidDir = false; outdir = new File(args[ii + 1]); if (!outdir.exists()) { if (!outdir.mkdir()) { System.err.println("Error: " + outdir.getPath() + " cannot be created"); invalidDir = true; } } if (!outdir.canRead()) { System.err.println("Error: " + outdir.getPath() + " does not have read permission set"); invalidDir = true; } if (!outdir.canExecute()) { System.err.println("Error: " + outdir.getPath() + " does not have execute permission set"); invalidDir = true; } if (!outdir.canWrite()) { System.err.println("Error: " + outdir.getPath() + " does not have write permission set"); invalidDir = true; } if (invalidDir) { System.exit(-1); } ii++; } else if (arg.equals("--nonce")) { if (args.length < ii + 1) { System.err.println("Error: Not enough args following --nonce"); printHelpAndQuit(-1); } nonce = args[ii + 1]; ii++; } else if (arg.equals("--user")) { if (args.length < ii + 1) { System.err.println("Error: Not enough args following --user"); printHelpAndQuit(-1); } user = args[ii + 1]; ii++; } else if (arg.equals("--password")) { if (args.length < ii + 1) { System.err.println("Error: Not enough args following --password"); printHelpAndQuit(-1); } password = args[ii + 1]; ii++; } else if (arg.equals("--period")) { if (args.length < ii + 1) { System.err.println("Error: Not enough args following --period"); printHelpAndQuit(-1); } period = Integer.parseInt(args[ii + 1]); if (period < 1) { System.err.println("Error: Specified value for --period must be >= 1."); printHelpAndQuit(-1); } ii++; } else if (arg.equals("--dateformat")) { if (args.length < ii + 1) { System.err.println("Error: Not enough args following --dateformat"); printHelpAndQuit(-1); } dateformatString = args[ii + 1].trim(); ii++; } else if (arg.equals("--batched")) { batched = true; } else if (arg.equals("--with-schema")) { withSchema = true; } else if (arg.equals("--delimiters")) { if (args.length < ii + 1) { System.err.println("Error: Not enough args following --delimiters"); printHelpAndQuit(-1); } fullDelimiters = args[ii + 1].trim(); ii++; String charsAsStr = StringEscapeUtils.unescapeHtml4(fullDelimiters.trim()); if (charsAsStr.length() != 4) { System.err.println( "The delimiter set must contain exactly 4 characters (after any html escaping)."); printHelpAndQuit(-1); } } else if (arg.equals("--disable-topology-autodiscovery")) { autodiscoverTopolgy = false; } else if (arg.equals("--throughput-monitor-period")) { if (args.length < ii + 1) { System.err.println("Error: Not enough args following --throughput-monitor-period"); printHelpAndQuit(-1); } throughputMonitorPeriod = Integer.parseInt(args[ii + 1].trim()); ii++; } else { System.err.println("Unrecognized parameter " + arg); System.exit(-1); } } // Check args for validity if (volt_servers == null || volt_servers.length < 1) { System.err.println("ExportToFile: must provide at least one VoltDB server"); printHelpAndQuit(-1); } if (connect == ' ') { System.err.println( "ExportToFile: must specify connection type as admin or client using --connect argument"); printHelpAndQuit(-1); } assert ((connect == 'c') || (connect == 'a')); if (user == null) { user = ""; } if (password == null) { password = ""; } if (nonce == null) { System.err.println("ExportToFile: must provide a filename nonce"); printHelpAndQuit(-1); } if (outdir == null) { outdir = new File("."); } if (delimiter == '\0') { System.err.println("ExportToFile: must provide an output type"); printHelpAndQuit(-1); } // create the export to file client ExportToFileClient client = new ExportToFileClient(delimiter, nonce, outdir, period, dateformatString, fullDelimiters, firstfield, connect == 'a', batched, withSchema, throughputMonitorPeriod, autodiscoverTopolgy); // add all of the servers specified for (String server : volt_servers) { server = server.trim(); client.m_commandLineServerArgs.add(server); client.addServerInfo(server, connect == 'a'); } // add credentials (default blanks used if none specified) client.addCredentials(user, password); // main loop try { client.run(); } catch (ExportClientException e) { e.printStackTrace(); System.exit(-1); } }
From source file:org.eclipse.lsp4e.cpp.language.CPPLanguageServer.java
private static File getClangServerLocation() { String res = null;//from w w w . j a v a2s . co m String[] command = new String[] { "/bin/bash", "-c", "which " + CLANG_LANGUAGE_SERVER }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ if (Platform.getOS().equals(Platform.OS_WIN32)) { command = new String[] { "cmd", "/c", "where " + CLANG_LANGUAGE_SERVER }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } BufferedReader reader = null; try { Process p = Runtime.getRuntime().exec(command); reader = new BufferedReader(new InputStreamReader(p.getInputStream())); res = reader.readLine(); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(reader); } if (res == null) { return null; } File f = new File(res); if (f.canExecute()) { return f; } return null; }
From source file:eu.freme.eservices.epublishing.EPublishingService.java
private static boolean testTmp(final File tmpFolder) { return (tmpFolder.exists() && tmpFolder.isDirectory() && tmpFolder.canWrite() && tmpFolder.canExecute()); }
From source file:org.glite.security.voms.admin.util.AdminServiceContactUtil.java
public static List<AdminServiceContactInfo> getAdminServiceContactInfo(String configDir) { List<AdminServiceContactInfo> contacts = new ArrayList<AdminServiceContactInfo>(); File confDir = new File(configDir); if (confDir.exists() && confDir.isDirectory() && confDir.canExecute() && confDir.canRead()) { File[] voFiles = confDir.listFiles(new FileFilter() { @Override/* w ww . j av a2 s . c o m*/ public boolean accept(File pathname) { return pathname.isDirectory(); } }); for (File f : voFiles) { try { AdminServiceContactInfo info = parseContactInfo(f.getAbsolutePath()); contacts.add(info); } catch (IOException e) { log.error(e.getMessage(), e); continue; } } } return contacts; }
From source file:org.glite.security.voms.admin.util.AdminServiceContactUtil.java
private static AdminServiceContactInfo parseContactInfo(String voConfDirPath) throws IOException { String voName = voConfDirPath.substring(voConfDirPath.lastIndexOf('/') + 1); File voDir = new File(voConfDirPath); if (voDir.exists() && voDir.isDirectory() && voDir.canRead() && voDir.canExecute()) { File contactFile = new File(voDir.getAbsolutePath() + "/" + SERVICE_CONTACT_FILENAME); if (contactFile.exists() && contactFile.canRead()) { String contactString = FileUtils.readFileToString(contactFile); String[] parts = contactString.split(":"); AdminServiceContactInfo info = new AdminServiceContactInfo(voName, parts[0], Integer.parseInt(parts[1])); return info; }// www. j a va 2s .c o m } throw new IllegalArgumentException("VOMS Admin service configuration cannot be read from " + voConfDirPath); }
From source file:org.apache.maven.plugin.cxx.utils.ExecutorService.java
public static CommandLine getExecutablePath(String executableName, Properties enviro, File dir) { File execFile = new File(executableName); String exec = null;/*from w w w . jav a 2 s .c o m*/ if (execFile.exists() && execFile.isFile() && execFile.canExecute()) { //getLog().debug( "Toolchains are ignored, 'executable' parameter is set to " + execFile.getAbsolutePath() ); exec = execFile.getAbsolutePath(); } else { if (OS.isFamilyWindows()) { String ex = executableName.indexOf(".") < 0 ? executableName + ".bat" : executableName; File f = new File(dir, ex); if (f.exists()) { exec = ex; } else { // now try to figure the path from PATH, PATHEXT env vars // if bat file, wrap in cmd /c String path = (String) enviro.get("PATH"); if (path != null) { String[] elems = StringUtils.split(path, File.pathSeparator); for (int i = 0; i < elems.length; i++) { f = new File(new File(elems[i]), ex); if (f.exists()) { exec = ex; break; } } } } } } if (exec == null) { exec = executableName; } CommandLine toRet; if (OS.isFamilyWindows() && exec.toLowerCase(Locale.getDefault()).endsWith(".bat")) { toRet = new CommandLine("cmd"); toRet.addArgument("/c"); toRet.addArgument(exec); } else { toRet = new CommandLine(exec); } return toRet; }