List of usage examples for java.io File canRead
public boolean canRead()
From source file:com.genericworkflownodes.knime.nodes.io.outputfiles.OutputFilesNodeModel.java
@Override protected PortObject[] execute(PortObject[] inObjects, ExecutionContext exec) throws Exception { IURIPortObject obj = (IURIPortObject) inObjects[0]; List<URIContent> uris = obj.getURIContents(); if (uris.size() == 0) { throw new Exception("There were no URIs in the supplied IURIPortObject"); }// www .j a v a2 s. c o m int idx = 1; for (URIContent uri : uris) { File in = new File(uri.getURI()); if (!in.canRead()) { throw new Exception("Cannot read file to export: " + in.getAbsolutePath()); } String outfilename = insertIndex(m_filename.getStringValue(), obj.getSpec().getFileExtensions().get(0), idx++); File out = new File(outfilename); if (out.exists() && !out.canWrite()) { throw new Exception("Cannot write to file: " + out.getAbsolutePath()); } else if (!out.getParentFile().canWrite()) { throw new Exception( "Cannot write to containing directoy: " + out.getParentFile().getAbsolutePath()); } FileUtils.copyFile(in, out); } return null; }
From source file:com.uzhnu.reedmuller.api.JsonFileCache.java
public synchronized JSONObject get(String key) { File cacheFile = getCacheFile(getCacheFilename(key)); if (cacheFile.exists() && cacheFile.isFile() && cacheFile.canRead()) { try {/* www.ja va 2 s. c om*/ FileInputStream fis = new FileInputStream(cacheFile); JSONObject jo = new JSONObject(readAll(fis)); fis.close(); return jo; } catch (FileNotFoundException e) { return null; } catch (JSONException e) { return null; } catch (IOException e) { return null; } } return null; }
From source file:pt.lsts.neptus.util.bathymetry.TidCachedData.java
@Override public void loadFile(File f) throws Exception { cachedData = new TreeSet<>(); if (f == null || !f.canRead()) { NeptusLog.pub().error(new Exception("Tides file is not valid: " + f)); return;/*w ww . j a v a 2 s .c om*/ } BufferedReader br = new BufferedReader(new FileReader(f)); TidReader tidReader = new TidReader(br); Data data = tidReader.readData(); while (data != null) { long unixTimeMillis = data.timeMillis; double height = data.height; Date d = new Date(unixTimeMillis); cachedData.add(new TidePeak(d, height)); data = tidReader.readData(); } name = tidReader.getHarbor(); br.close(); }
From source file:com.thoughtworks.go.server.GoServer.java
private List<File> getAddonJarFiles() { File addonsPath = new File(systemEnvironment.get(SystemEnvironment.ADDONS_PATH)); if (!addonsPath.exists() || !addonsPath.canRead()) { return new ArrayList<>(); }/*from w w w . j a v a2 s . c o m*/ return new ArrayList<>(FileUtils.listFiles(addonsPath, new SuffixFileFilter("jar", IOCase.INSENSITIVE), FalseFileFilter.INSTANCE)); }
From source file:es.emergya.tools.ExtensionClassLoader.java
@Override public InputStream getResourceAsStream(String name) { InputStream resourceIS;//from w w w . j a v a 2 s . c o m File jar = JarSearcher.getJar(ExtensionClassLoader.class); if (jar != null) { if (jar.getPath().startsWith("file:")) { ExtensionClassLoader.LOG.debug("Eliminando 'file:' de " + jar.getAbsolutePath()); jar = new File(jar.getPath().substring(5)); } else ExtensionClassLoader.LOG.debug("La ruta no comienza por 'file:' " + jar.getPath()); File dir = jar.getParentFile(); if (dir == null) { ExtensionClassLoader.LOG.debug("Entrando por super.getResouceAsStream(" + name + ")"); return super.getResourceAsStream(name); } String path = dir.getPath(); ExtensionClassLoader.LOG.debug("Directorio con el jar: " + dir.getPath()); if (!name.startsWith("/")) path = path + "/"; path += name; String osDependentPath = path.replaceAll("/", java.util.regex.Matcher.quoteReplacement(File.separator)); ExtensionClassLoader.LOG.debug("Se busca el fichero " + osDependentPath); if (System.getProperty("os.name").indexOf("Windows") >= 0) osDependentPath = osDependentPath.replaceAll("%20", " "); File resource = new File(osDependentPath); if (resource.exists() && resource.canRead()) try { resourceIS = new FileInputStream(osDependentPath); } catch (FileNotFoundException e) { ExtensionClassLoader.LOG.error("Couln't open requested (" + name + "resource"); resourceIS = null; } else resourceIS = super.getResourceAsStream(name); } else resourceIS = super.getResourceAsStream(name); return resourceIS; }
From source file:se.inera.axel.shs.broker.messagestore.internal.FileMessageStoreServiceIT.java
@Test(groups = "largeTests") @DirtiesContext/*from www . java2 s .co m*/ public void saveAndDeleteMessage() { ShsMessageEntry entry = make(a(ShsMessageEntryMaker.ShsMessageEntry)); se.inera.axel.shs.mime.ShsMessage shsMessage = make(a(ShsMessage)); File f = new File(baseDir, entry.getId()); entry = messageStore.save(entry, shsMessage); assertTrue(f.exists()); assertTrue(f.canRead()); messageStore.delete(entry); Assert.assertFalse(f.exists()); }
From source file:klapersuite.prismanalysis.linux.PrismRunner.java
public Process launch(File pmFile, File pctlFile, int resultDecimalDigitsPrecision) throws IOException { if (!pmFile.canRead()) throw new IOException("pmFile is not accessible (" + pmFile.toString() + ")"); if (!pctlFile.canRead()) throw new IOException("pctlFile is not accessible (" + pctlFile.toString() + ")"); Process prismProcess = launchPrism(new String[] { "-cuddmaxmem", String.valueOf(Math.max(IN_KB_512MB, new SystemMemory().availableRam(IN_KB_512MB))), "-maxiters", "200000", "-e", "1e-" + resultDecimalDigitsPrecision, pmFile.toString(), pctlFile.toString() }); if (prismProcess == null) throw new IOException("Prism solver doesn't run properly"); if (exitValueAfterTermination(prismProcess) != 0) throw new IOException("Prism solver doesn't work properly"); return prismProcess; }
From source file:com.ikon.util.cl.FilesystemClassLoader.java
/** * Get main class name//w w w . jav a2s. c o m */ @Override public String getMainClassName() throws IOException { log.debug("getMainClassName()"); File mf = new File(file, "META-INF/MANIFEST.MF"); FileInputStream fis = null; try { if (mf.exists() && mf.canRead()) { fis = new FileInputStream(mf); Manifest manif = new Manifest(fis); Attributes attr = manif.getMainAttributes(); return attr != null ? attr.getValue(Attributes.Name.MAIN_CLASS) : null; } } finally { IOUtils.closeQuietly(fis); } return null; }
From source file:com.linkedin.restli.tools.idlgen.TestRestLiResourceModelExporter.java
private String readFile(String fileName) throws IOException { File file = new File(fileName); assertTrue(file.exists() && file.canRead(), "Cannot find file: " + fileName); BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file))); StringBuilder sb = new StringBuilder(); String line = null;//from w w w . j a va 2s . com try { while ((line = reader.readLine()) != null) { sb.append(line); } } finally { reader.close(); } return sb.toString(); }
From source file:de.vandermeer.skb.commons.utils.Json2Collections.java
/** * Reads the given JSON file and logs errors. * @param file JSON file// w ww. j ava 2 s . c o m * @return a map with information from the JSON file or null in case of errors */ public Object read(File file) { if (file != null && file.canRead()) { try { return this.read(new Scanner(file)); } catch (Exception ignore) { } } return null; }