List of usage examples for java.io File canRead
public boolean canRead()
From source file:com.github.maven_nar.NarUtil.java
public static void makeExecutable(final File file, final Log log) throws MojoExecutionException, MojoFailureException { if (!file.exists()) { return;/*ww w. jav a2s . c o m*/ } if (file.isDirectory()) { final File[] files = file.listFiles(); for (final File file2 : files) { makeExecutable(file2, log); } } if (file.isFile() && file.canRead() && file.canWrite() && !file.isHidden()) { // chmod +x file final int result = runCommand("chmod", new String[] { "+x", file.getPath() }, null, null, log); if (result != 0) { throw new MojoExecutionException("Failed to execute 'chmod +x " + file.getPath() + "'" + " return code: \'" + result + "\'."); } } }
From source file:com.github.maven_nar.NarUtil.java
public static void makeLink(final File file, final Log log) throws MojoExecutionException, MojoFailureException { if (!file.exists()) { return;//from ww w .j av a2 s . c o m } if (file.isDirectory()) { final File[] files = file.listFiles(); for (final File file2 : files) { makeLink(file2, log); } } if (file.isFile() && file.canRead() && file.canWrite() && !file.isHidden() && file.getName().matches(".*\\.so(\\.\\d+)+$")) { final File sofile = new File(file.getParent(), file.getName().substring(0, file.getName().indexOf(".so") + 3)); if (!sofile.exists()) { // ln -s lib.so.xx lib.so final int result = runCommand("ln", new String[] { "-s", file.getName(), sofile.getPath() }, null, null, log); if (result != 0) { throw new MojoExecutionException("Failed to execute 'ln -s " + file.getName() + " " + sofile.getPath() + "'" + " return code: \'" + result + "\'."); } } } }
From source file:com.sforce.dataset.DatasetUtilMain.java
public static File validateInputFile(String inputFile, String action) { File temp = null; if (inputFile != null) { temp = new File(inputFile); if (!temp.exists() && !temp.canRead()) { System.out.println("\nERROR: inputFile {" + temp + "} not found"); return null; }// ww w. j a va 2 s. c om String ext = FilenameUtils.getExtension(temp.getName()); if (ext == null || !(ext.equalsIgnoreCase("csv") || ext.equalsIgnoreCase("txt") || ext.equalsIgnoreCase("bin") || ext.equalsIgnoreCase("gz") || ext.equalsIgnoreCase("json"))) { System.out.println("\nERROR: inputFile does not have valid extension"); return null; } if (action.equalsIgnoreCase("load")) { byte[] binHeader = new byte[5]; if (ext.equalsIgnoreCase("bin") || ext.equalsIgnoreCase("gz")) { try { InputStream fis = new FileInputStream(temp); if (ext.equalsIgnoreCase("gz")) fis = new GzipCompressorInputStream(new FileInputStream(temp)); int cnt = fis.read(binHeader); if (fis != null) { IOUtils.closeQuietly(fis); } if (cnt < 5) { System.out.println("\nERROR: inputFile {" + temp + "} in not valid"); return null; } } catch (FileNotFoundException e) { e.printStackTrace(); System.out.println("\nERROR: inputFile {" + temp + "} not found"); return null; } catch (IOException e) { e.printStackTrace(); System.out.println("\nERROR: inputFile {" + temp + "} in not valid"); return null; } if (!EbinFormatWriter.isValidBin(binHeader)) { if (ext.equalsIgnoreCase("bin")) { System.out.println("\nERROR: inputFile {" + temp + "} in not valid binary file"); return null; } } } } if (ext.equalsIgnoreCase("json")) { try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.readValue(temp, Object.class); } catch (Throwable t) { System.out.println( "\nERROR: inputFile {" + temp + "} is not valid json, Error: " + t.getMessage()); return null; } } } return temp; }
From source file:edu.stanford.epadd.launcher.Splash.java
/** sets up SETTINGS_DIR by reading epadd.properties in home dir if required, also sets up IS_DISCOVERY_MODE. * out and err streams are expected to be available. * call this before setting up logging because it can affect the location of the log file *///from w ww. ja va 2 s. c o m private static void readConfigFile() { // compute settings_DIR, which is also used as logging_dir. so it should be called before logging is set up. // Important: this logic should be the same as in EpaddInitializer inside the webapp (which calls muse/Config.java) { String DEFAULT_SETTINGS_DIR = System.getProperty("user.home") + File.separator + "epadd-settings"; Properties props = new Properties(); File f = new File(EPADD_PROPS_FILE); if (f.exists() && f.canRead()) { out.println("Reading configuration from: " + EPADD_PROPS_FILE); try { InputStream is = new FileInputStream(EPADD_PROPS_FILE); props.load(is); } catch (Exception e) { err.println("Error reading epadd properties file " + EPADD_PROPS_FILE + " " + e); } } else { err.println("ePADD properties file " + EPADD_PROPS_FILE + " does not exist or is not readable"); } // set up settings_dir SETTINGS_DIR = System.getProperty("epadd.settings.dir"); if (SETTINGS_DIR == null || SETTINGS_DIR.length() == 0) SETTINGS_DIR = props.getProperty("epadd.settings.dir"); if (SETTINGS_DIR == null || SETTINGS_DIR.length() == 0) SETTINGS_DIR = DEFAULT_SETTINGS_DIR; if (System.getProperty("epadd.mode.discovery") != null || "discovery".equalsIgnoreCase((String) props.get("epadd.mode"))) IS_DISCOVERY_MODE = true; } }
From source file:File.TXT.ReadFile.java
public ArrayList read_all_files(String path) { FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".txt"); }/*from w w w . j a v a2s .com*/ }; ArrayList hasil = new ArrayList(); File folder = new File(path); File[] listOfFiles = folder.listFiles(filter); for (int i = 0; i < listOfFiles.length; i++) { File file = listOfFiles[i]; try { if (file.canRead()) { String content = FileUtils.readFileToString(file); hasil.add(content); } else { hasil.add("kosong"); } } catch (IOException ex) { Logger.getLogger(ReadFile.class.getName()).log(Level.SEVERE, null, ex); } } return hasil; }
From source file:net.sf.zekr.engine.template.ZekrFileResourceLoader.java
public long getLastModified(Resource resource) { File file = new File(resource.getName()); return file.canRead() ? file.lastModified() : 0; }
From source file:com.github.riccardove.easyjasub.EasyJaSubInputFromCommand.java
private static void checkDirectory(String fileName, File file) throws EasyJaSubException { if (!file.isDirectory()) { throw new EasyJaSubException(fileName + " is not a directory"); }/*w w w . j ava 2 s.c om*/ if (!file.canRead()) { throw new EasyJaSubException("Directory " + fileName + " can not be read"); } if (!file.canWrite()) { throw new EasyJaSubException("Directory " + fileName + " can not be written"); } }
From source file:persistence.DefaultModelSerializer.java
@Override public GroceryLists deserialize(File sourceFile) { try {//from w w w.j av a 2 s . co m if (sourceFile.canRead()) return mapper.readValue(sourceFile, GroceryLists.class); else return new GroceryLists(); } catch (IOException e) { throw new IllegalArgumentException("Invalid JSON", e); } }
From source file:com.cisco.step.jenkins.plugins.jenkow.WfUtil.java
private static FormValidation checkFile(String value, File f) { if (!StringUtils.isEmpty(value)) { if (!f.exists()) { String url = "descriptorByName/" + JenkowBuilder.class.getName() + "/createWorkflow?wfn=" + value; String msg = "Workflow " + value + " does not exist. " + "<button type=\"button\"" + " onclick=\"javascript:" + "var e=this;" + "new Ajax.Request" + "(" + "'" + url + "'," + "{onSuccess:function(x)" + "{notificationBar.show('Workflow created.',notificationBar.OK);" + "fireEvent($(e).up('TR.validation-error-area').previous().down('INPUT'),'change');" + "}" + "}" + ")" + "\"" + ">" + "Create it now" + "</button>"; return FormValidation.errorWithMarkup(msg); }/* w w w .j a v a 2 s . c o m*/ if (!f.canRead()) return FormValidation.warning("Workflow " + value + " is not readable."); } return FormValidation.ok(); }
From source file:cz.incad.kramerius.k5indexer.FieldsConfig.java
public FieldsConfig() throws IOException, JSONException { String path = Constants.WORKING_DIR + File.separator + "k5indexer" + File.separator + "fields.json"; File f = new File(path); if (!f.exists() || !f.canRead()) { f = FileUtils// w w w.ja va2 s. com .toFile(KrameriusDocument.class.getResource("/cz/incad/kramerius/k5indexer/res/fields.json")); } String json = FileUtils.readFileToString(f, "UTF-8"); fieldsConfig = new JSONObject(json); mappings = fieldsConfig.getJSONObject("mappings"); streams = fieldsConfig.getJSONObject("datastreams"); }