List of usage examples for java.io File canRead
public boolean canRead()
From source file:ffx.potential.parsers.XYZFileFilter.java
/** * <p>//from w ww . j ava 2s. c o m * acceptDeep</p> * * @param file a {@link java.io.File} object. * @return a boolean. */ public boolean acceptDeep(File file) { try { if (file == null || file.isDirectory() || !file.canRead()) { return false; } FileReader fr = new FileReader(file); BufferedReader br = new BufferedReader(fr); if (!br.ready()) { return false; } /** * If the first token is not an integer this file is not a TINKER * Cartesian Coordinate File. */ String rawdata = br.readLine(); String header[] = rawdata.trim().split(" +"); if (header == null || header.length == 0) { return false; } try { Integer.parseInt(header[0]); } catch (Exception e) { return false; } /** * If the the first Atom line does not begin with an integer and * contain at least six tokens, this is not a TINKER cartesian * coordinate file. * */ String firstAtom = br.readLine(); if (firstAtom == null) { return false; } br.close(); fr.close(); String data[] = firstAtom.trim().split(" +"); if (data == null || data.length < 6) { return false; } try { Integer.parseInt(data[0]); } catch (Exception e) { return false; } return true; } catch (Exception e) { return true; } }
From source file:it.drwolf.ridire.utility.CorpusPackager.java
private void processLine(String fileLine) throws IOException { this.strTokenizer.setIgnoreEmptyTokens(false); this.strTokenizer.reset(fileLine); String[] tokens = this.strTokenizer.getTokenArray(); if (tokens.length == 5) { Integer words = Integer.parseInt(tokens[0].trim()); String jobName = tokens[1].trim(); FileFilter fileFilter = new RegexFileFilter(jobName.replaceAll("_", "[_ ]")); String jobsDir = "/home/drwolf/heritrix-3.1.1-SNAPSHOT/jobs/"; File[] jobsDirs = new File(jobsDir).listFiles(fileFilter); File jobDirFile = null;//w w w. j a v a 2s.c o m if (jobsDirs.length > 0) { jobDirFile = jobsDirs[0]; } else { System.out.println(jobName + "\tnot found."); return; } String fileDigest = tokens[2].trim(); if (words < this.minValue || words >= this.maxValue) { System.out.println(jobName + "\t" + fileDigest + "\t skipped: out of range."); return; } String functional = tokens[3].trim(); String semantic = tokens[4].trim(); String dirname = functional.trim(); if (dirname.trim().length() < 1) { dirname = semantic.trim(); } if (dirname.trim().length() < 1) { dirname = "other"; } File destDir = new File(this.dirName + System.getProperty("file.separator") + dirname); File f = new File(jobDirFile.getAbsolutePath() + "/arcs/resources/" + fileDigest + ".txt"); if (!f.exists() || !f.canRead()) { f = new File("/home/drwolf/heritrix-3.1.1-SNAPSHOT/jobs/completed-" + jobName + "/arcs/resources/" + fileDigest + ".txt"); if (!f.exists() || !f.canRead()) { System.out.println(jobName + "\t" + fileDigest + "\tnot found."); return; } } FileUtils.copyFileToDirectory(f, destDir); } }
From source file:FileTable2.java
public void setFileStats(File dir) { String files[] = dir.list();//from ww w . j a v a 2 s . c o m data = new Object[files.length][titles.length]; for (int i = 0; i < files.length; i++) { File tmp = new File(files[i]); data[i][0] = new Boolean(tmp.isDirectory()); data[i][1] = tmp.getName(); data[i][2] = new Boolean(tmp.canRead()); data[i][3] = new Boolean(tmp.canWrite()); data[i][4] = new Long(tmp.length()); data[i][5] = new Date(tmp.lastModified()); } // Just in case anyone's listening... fireTableDataChanged(); }
From source file:es.bsc.demiurge.core.models.vms.Vm.java
public void setInitScript(String initScript) { // If a path for an loadConfiguration script was specified if (initScript != null && !initScript.equals("")) { // Check that the path is valid and the file can be read File f = new File(initScript); if (!f.isFile() || !f.canRead()) { throw new IllegalArgumentException("The path for the loadConfiguration script is not valid"); }/*from w w w .j a v a 2 s.c o m*/ this.initScript = initScript; } }
From source file:au.org.ala.layers.intersect.IntersectConfig.java
private static void isValidPath(String path, String desc) { File f = new File(path); if (!f.exists()) { logger.error("Config error. Property \"" + desc + "\" with value \"" + path + "\" is not a valid local file path. It does not exist."); } else if (!f.isDirectory()) { logger.error("Config error. Property \"" + desc + "\" with value \"" + path + "\" is not a valid local file path. It is not a directory."); } else if (!f.canRead()) { logger.error("Config error. Property \"" + desc + "\" with value \"" + path + "\" is not a valid local file path. Not permitted to READ."); } else if (!f.canWrite()) { logger.error("Config error. Property \"" + desc + "\" with value \"" + path + "\" is not a valid local file path. Not permitted to WRITE."); }/*from ww w . j a v a 2 s . co m*/ }
From source file:com.symbian.driver.core.cmdline.ConfigCmdLine.java
/** * Implements additional constraints on switches. * //from w w w. ja v a2 s.com * @param aCommandLine * {@inheritDoc} */ public void checkAdditionalConstraints(final CommandLine aCommandLine) { if (aCommandLine.hasOption("cert") != aCommandLine.hasOption("key")) { LOGGER.severe("Certificate and key should be specified as a pair or none."); } else if (aCommandLine.hasOption("cert")) { File lCert = new File(aCommandLine.getOptionValue("cert")); if (!lCert.isFile() || !lCert.canRead()) { LOGGER.severe("Certificate file is not accessible."); } File lKey = new File(aCommandLine.getOptionValue("key")); if (!lKey.isFile() || !lKey.canRead()) { LOGGER.severe("Key file is not accessible."); } } if (aCommandLine.hasOption("uid") && aCommandLine.getOptionValue("uid").indexOf(':') == -1) { LOGGER.severe("UID should be specified as a pair separated by a ':' 0xFIRST:0xLAST"); } }
From source file:de.torstenwalter.maven.plugins.SQLPlusMojo.java
private void checkFileIsReadable(File file) throws MojoFailureException { if (!file.exists() || !file.canRead() || !file.isFile()) { throw new MojoFailureException( file.getName() + "problem reading file '" + file.getAbsolutePath() + "'"); }/* w w w . j av a2s .com*/ }
From source file:edu.harvard.iq.dataverse.ingest.metadataextraction.impl.plugins.fits.FITSFileMetadataExtractorSpi.java
@Override public boolean canDecodeInput(File file) throws IOException { if (file == null) { throw new IllegalArgumentException("file == null!"); }//from w ww .j a va 2s . c om if (!file.canRead()) { throw new IOException("cannot read the input file"); } return true; }
From source file:com.at.lic.LicenseControl.java
private boolean validateLicense() { boolean isValid = false; File f = new File(licenseKeyFilepath); if (f.exists() && f.isFile() && f.canRead()) { Serializer serializer = new Persister(); License lic = null;//ww w.j a v a 2 s.com try { lic = serializer.read(License.class, f); } catch (Exception e) { log.error("License file reading failed.", e); isValid = false; return isValid; } String lic_checkCode = lic.getCheckCode(); String lic_code = lic.getLicenseCode(); String sign_code = lic.getSignCode(); String sign_date = lic.getSignDate(); String lcc = getLicenseCheckCode(); // get license check code if (!lcc.equals(lic_checkCode)) { log.error("License file is not for this machine."); isValid = false; return isValid; } StringBuilder sb = new StringBuilder(); sb.append(lcc); sb.append(lic_code); sb.append(sign_date); String text = sb.toString(); byte[] signature = Base64.decodeBase64(sign_code); try { isValid = RSAKeyManager.validSign(text, signature); } catch (Exception e) { log.error("Validate sign failed.", e); isValid = false; return isValid; } } return isValid; }
From source file:ffx.potential.parsers.PDBFileFilter.java
/** * <p>//from w w w .ja v a 2s . c o m * acceptDeep</p> Accepts a PDB file if it finds at least one parseable ATOM * line. * * @param file a {@link java.io.File} object. * @return Whether a valid PDB file. */ public boolean acceptDeep(File file) { try { if (file == null || file.isDirectory() || !file.canRead()) { return false; } try (BufferedReader br = new BufferedReader(new FileReader(file))) { if (!br.ready()) { return false; } String line = br.readLine(); if (line != null) { line = line.trim(); } else { return false; } boolean validAtomLine = false; boolean validTerLine = true; // Too many files lack even this. while (line != null) { line = line.trim(); if (!validAtomLine && line.startsWith("ATOM ")) { try { Integer.parseInt(line.substring(6, 11).trim()); Integer.parseInt(line.substring(22, 26).trim()); String coordOccTempVals[] = line.substring(30, 66).trim().split(" +"); for (String value : coordOccTempVals) { Double.parseDouble(value); } validAtomLine = true; } catch (NumberFormatException | StringIndexOutOfBoundsException ex) { // Do nothing. } } /* else if (line.startsWith("TER")) { try { /* In a perfect world, every PDB file which claims to be at the 3.3 standard * will actually be at the 3.3 standard. Integer.parseInt(line.substring(6, 11).trim()); Integer.parseInt(line.substring(22, 26).trim());*/ /*validTerLine = true; } catch (NumberFormatException | StringIndexOutOfBoundsException ex) { // Do nothing. } }*/ if (validAtomLine && validTerLine) { return true; } line = br.readLine(); } } } catch (IOException e) { return false; } return false; }