List of usage examples for java.io File getCanonicalPath
public String getCanonicalPath() throws IOException
From source file:cc.osint.graphd.script.GScriptEngine.java
public Object evalScript(String fn) throws Exception { File file = new File(fn); return engine.eval(TextFile.get(file.getCanonicalPath())); }
From source file:net.orpiske.ssps.common.groovy.GroovyClasspathHelper.java
/** * Adds a file or directory to the classpath * @param file the file object pointing to the file or directory */// w w w.j a va2s . c o m public void addClasspath(final File file) throws IOException { if (file.exists()) { loader.addClasspath(file.getCanonicalPath()); } }
From source file:com.codecrate.shard.system.DataSourceConfiguration.java
public DataSourceConfiguration(File applicationWorkingDirectory) throws IOException { File databaseDirectory = new AutoCreateDirectoriesFile(applicationWorkingDirectory, "data"); dataSourceUrl = DATASOURCE_PREFIX + databaseDirectory.getCanonicalPath() + "/" + "db"; LOG.info("Using datasource: " + dataSourceUrl); }
From source file:com.btisystems.pronx.ems.AppIntegrationTest.java
/** * Integration test to verify the generated code is as expected. A previous * known good baseline is used and generated code compared to that. * * @throws Exception/*ww w.j a va 2s . c om*/ */ @Test public void shouldGenerateExpectedModel() throws Exception { Collection<File> files = FileUtils.listFiles(new File(GENERATED_DIRECTORY), new String[] { "java", "xml" }, true); for (final File file : files) { try { if (file.getCanonicalPath().endsWith("xml")) { trimNotificationMeta(file); } FileAssert.assertEquals(new File(file.getCanonicalPath().replaceFirst("generated", "baseline")), file); } catch (ComparisonFailure fail) { System.out.println("Failure when comparing: " + file.getCanonicalPath()); failed = true; throw fail; } } }
From source file:com.zimbra.cs.store.external.SimpleStoreManager.java
@Override public List<String> getAllBlobPaths(Mailbox mbox) throws IOException { File dir = new File(dirName(mbox)); if (dir.exists()) { File[] files = dir.listFiles((FileFilter) FileFileFilter.FILE); List<String> locators = new ArrayList<String>(); for (File file : files) { locators.add(file.getCanonicalPath()); }//from ww w . j a v a 2s .c om return locators; } else { return new ArrayList<String>(); } }
From source file:com.jsquant.util.FileCache.java
public String get(String key) throws IOException { String value = memCache.get(key); if (value == null) { File f = new File(cacheDir, key); if (f.exists()) { log.info("reading cachePath=" + f.getCanonicalPath()); value = FileUtils.readFile(f); //value = Files.toString(f, Charsets.UTF_8); memCache.put(key, value);/* w w w. ja v a 2 s . c om*/ } } return value; }
From source file:jag.sftp.VirtualFileSystem.java
/** * * * @param path/*w ww . jav a 2s.c om*/ * @param securemount * * @return * * @throws FileNotFoundException */ public static String translateCanonicalPath(String path, String securemount) throws FileNotFoundException { try { log.debug("Translating for canonical path " + path + " against secure mount " + securemount); File f = new File(path); String canonical = f.getCanonicalPath().replace('\\', '/'); File f2 = new File(securemount); String canonical2 = f2.getCanonicalPath().replace('\\', '/'); // Verify that the canonical path does not exit out of the mount if (canonical.startsWith(canonical2)) { return canonical; } else { throw new FileNotFoundException(path + " could not be found"); } } catch (IOException ex) { throw new FileNotFoundException(path + " could not be found"); } }
From source file:gov.nih.nci.ncicb.tcga.dcc.common.util.FileUtil.java
public static boolean copyFile(final String sourceFilename, final String destFilename) { boolean success = false; FileChannel source = null;// w w w . j a va 2s .co m FileChannel destination = null; FileInputStream sourceStream = null; FileOutputStream destinationStream = null; final File destFile = new File(destFilename); final File sourceFile = new File(sourceFilename); try { final long size = sourceFile.length(); sourceStream = new FileInputStream(sourceFile); destinationStream = new FileOutputStream(destFile); source = sourceStream.getChannel(); destination = destinationStream.getChannel(); long toTransfer = size; while (toTransfer > 0) { toTransfer -= source.transferTo(size - toTransfer, toTransfer, destination); } success = true; } catch (IOException iox) { try { logger.error( "Unable to copy " + sourceFile.getCanonicalPath() + " to " + destFile.getCanonicalPath(), iox); } catch (IOException iox2) { logger.error("Unable to copy " + sourceFile.getName() + " OR get the canonical name", iox2); } } finally { try { if (source != null) { source.close(); source = null; } if (destination != null) { destination.close(); destination = null; } if (sourceStream != null) { sourceStream.close(); sourceStream = null; } if (destinationStream != null) { destinationStream.close(); destinationStream = null; } } catch (IOException iox3) { logger.error("Unable to close stream?!?", iox3); } } return success; }
From source file:edu.ku.brc.specify.toycode.UpdatesApp.java
/** * @param file//w ww .j av a 2s. c o m * @return */ protected static UpdateDescriptor read(final File file) { XStream xstream = new XStream(); UpdateDescriptor.config(xstream); UpdateEntry.config(xstream); if (file.exists()) { try { UpdateDescriptor update = (UpdateDescriptor) xstream.fromXML(FileUtils.readFileToString(file)); return update; } catch (IOException ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(UpdatesApp.class, ex); ex.printStackTrace(); } } else { try { System.err.println("File: " + file.getCanonicalPath() + " doesn't exist."); } catch (IOException ex) { ex.printStackTrace(); } } return null; }
From source file:com.netflix.lipstick.Main.java
private static String validateLogFile(String logFileName, String scriptName) { String strippedDownScriptName = null; if (scriptName != null) { File scriptFile = new File(scriptName); if (!scriptFile.isDirectory()) { String scriptFileAbsPath; try { scriptFileAbsPath = scriptFile.getCanonicalPath(); strippedDownScriptName = getFileFromCanonicalPath(scriptFileAbsPath); } catch (IOException ioe) { log.warn("Could not compute canonical path to the script file " + ioe.getMessage()); strippedDownScriptName = null; }//from w ww .j a v a 2 s.c o m } } String defaultLogFileName = (strippedDownScriptName == null ? "pig_" : strippedDownScriptName) + new Date().getTime() + ".log"; File logFile; if (logFileName != null) { logFile = new File(logFileName); // Check if the file name is a directory // append the default file name to the file if (logFile.isDirectory()) { if (logFile.canWrite()) { try { logFileName = logFile.getCanonicalPath() + File.separator + defaultLogFileName; } catch (IOException ioe) { log.warn("Could not compute canonical path to the log file " + ioe.getMessage()); return null; } return logFileName; } else { log.warn("Need write permission in the directory: " + logFileName + " to create log file."); return null; } } else { // we have a relative path or an absolute path to the log file // check if we can write to the directory where this file // is/will be stored if (logFile.exists()) { if (logFile.canWrite()) { try { logFileName = new File(logFileName).getCanonicalPath(); } catch (IOException ioe) { log.warn("Could not compute canonical path to the log file " + ioe.getMessage()); return null; } return logFileName; } else { // do not have write permissions for the log file // bail out with an error message log.warn("Cannot write to file: " + logFileName + ". Need write permission."); return logFileName; } } else { logFile = logFile.getParentFile(); if (logFile != null) { // if the directory is writable we are good to go if (logFile.canWrite()) { try { logFileName = new File(logFileName).getCanonicalPath(); } catch (IOException ioe) { log.warn("Could not compute canonical path to the log file " + ioe.getMessage()); return null; } return logFileName; } else { log.warn("Need write permission in the directory: " + logFile + " to create log file."); return logFileName; } } // end if logFile != null else is the default in fall // through } // end else part of logFile.exists() } // end else part of logFile.isDirectory() } // end if logFileName != null // file name is null or its in the current working directory // revert to the current working directory String currDir = System.getProperty("user.dir"); logFile = new File(currDir); logFileName = currDir + File.separator + (logFileName == null ? defaultLogFileName : logFileName); if (logFile.canWrite()) { return logFileName; } log.warn("Cannot write to log file: " + logFileName); return null; }