Example usage for java.io File getCanonicalPath

List of usage examples for java.io File getCanonicalPath

Introduction

In this page you can find the example usage for java.io File getCanonicalPath.

Prototype

public String getCanonicalPath() throws IOException 

Source Link

Document

Returns the canonical pathname string of this abstract pathname.

Usage

From source file:com.training.utils.FileLocator.java

public File find() {
    used = true; // this builder can't be used again
    File foundFile = null;/*from   www . jav a 2  s .c o m*/

    for (String location : locations) {
        File file = new File(location);
        String path;

        try {
            path = file.getCanonicalPath();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        if (file.exists()) {
            foundFile = file;
            break;
        } else {
            if (errorMessage.length() == 0) {
                errorMessage.append("File not found in ");
            } else {
                errorMessage.append(" or in ");
            }

            errorMessage.append("'").append(path).append("'");
        }
    }

    return foundFile;
}

From source file:com.flipkart.flux.MigrationUtil.MigrationsRunner.java

public void migrate(String dbName) {
    try {/*from w  ww . j  av  a  2  s  . c  o m*/
        Configuration configuration = yamlConfiguration.subset(dbName + ".Hibernate");
        Properties properties = new Properties();
        properties.put("user", configuration.getProperty("hibernate.connection.username"));
        properties.put("password", configuration.getProperty("hibernate.connection.password"));
        String url = (String) configuration.getProperty("hibernate.connection.url");
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        java.sql.Connection connection = DriverManager.getConnection(url, properties);
        Database database = DatabaseFactory.getInstance()
                .findCorrectDatabaseImplementation(new JdbcConnection(connection));
        ClassLoader classLoader = getClass().getClassLoader();
        File file = new File(classLoader.getResource(dbName + "/migrations.xml").getFile());
        Liquibase liquibase = new Liquibase(file.getCanonicalPath(), new FileSystemResourceAccessor(),
                database);
        liquibase.update(new Contexts());
    } catch (Exception e) {
        System.err.println("Unable to perform database migration.");
        e.printStackTrace();
    }
}

From source file:com.ariht.maven.plugins.config.io.FileInfo.java

public String getAllSources() throws IOException {
    final List<String> allFileNames = new LinkedList<String>();
    allFileNames.add(FilenameUtils.separatorsToUnix(relativeSubDirectory + "/" + getName()));
    if (this.externalFiles != null) {
        for (final File f : externalFiles) {
            allFileNames.add(FilenameUtils.separatorsToUnix(f.getCanonicalPath() + "/" + f.getName()));
        }//from  w w  w . ja  v a 2 s .c o  m
    }
    return "[" + Joiner.on(", ").join(allFileNames) + "]";
}

From source file:org.openmrs.module.filemanager.api.impl.FileManagerServiceImpl.java

public void saveAndTransferFileComplexObs(Obs obs, File tempFile) {

    try {/*from   ww w .ja v  a2s  .c  o m*/
        String mergedUrl = tempFile.getCanonicalPath();
        InputStream out1 = new FileInputStream(new File(mergedUrl));

        ComplexData complexData = new ComplexData(
                obs.getPerson().getId() + "-" + Math.random() + "-" + tempFile.getName(), out1);
        obs.setComplexData(complexData);

        Context.getObsService().saveObs(obs, null);
        tempFile.delete();

    } catch (Exception e) {
        log.error(e);
    }
}

From source file:com.intuit.cto.selfservice.service.ManagedProcessBuilder.java

public ManagedProcessBuilder addFileArgument(String arg, File file) throws IOException {
    return addArgument(arg + "=" + file.getCanonicalPath());
}

From source file:com.marvelution.bamboo.plugins.sonar.tasks.SonarRunnerConfig.java

/**
 * Get the path to the executable/*from   w w w .j a  v a  2  s .  c  o m*/
 * 
 * @param homePath the home directory of the Sonar Runner
 * @return the path to the Sonar Runner executable
 */
private String getSonarRunnerExecutable(String homePath) {
    String pathToExecutable = StringUtils.join(new String[] { homePath, "bin", SONAR_RUNNER_EXECUTABLE },
            File.separator);
    if (StringUtils.contains(pathToExecutable, " ")) {
        try {
            File f = new File(pathToExecutable);
            pathToExecutable = f.getCanonicalPath();
        } catch (IOException e) {
            LOGGER.warn("IO Exception trying to get executable", e);
        }
    }
    return pathToExecutable;
}

From source file:com.tunyk.mvn.plugins.htmlcompressor.FileTool.java

public Map<String, String> getFiles() throws IOException {
    Map<String, String> map = new HashMap<String, String>();
    File rootDir = new File(rootDirPath);
    // TODO: fix unchecked warning
    Collection<File> files = FileUtils.listFiles(rootDir, fileExt, recursive);
    int truncationIndex = 0;
    for (File file : files) {
        String normalizedFilePath = file.getCanonicalPath().replaceAll("\\\\", "/");
        if (truncationIndex == 0) {
            truncationIndex = normalizedFilePath.indexOf(rootDirPath) + rootDirPath.length() + 1;
        }//from ww  w . j a va 2s.  c  o m
        String key = normalizedFilePath.substring(truncationIndex);
        String value = FileUtils.readFileToString(file, fileEncoding);
        map.put(key, value);
    }
    return map;
}

From source file:net.hillsdon.reviki.configuration.TestDataDirImpl.java

@Override
protected void setUp() throws Exception {
    File baseDirFile = File.createTempFile(getClass().getSimpleName(), "baseDir");
    assertTrue(baseDirFile.delete());//from w  w w  .  j a  v a2 s . c  o m
    _baseDir = baseDirFile.getCanonicalPath();
    _servletContext = EasyMock.createMock(ServletContext.class);
    _dataDir = new DataDirImpl(_servletContext, _baseDir);
}

From source file:com.skcraft.launcher.creator.model.creator.Workspace.java

public boolean hasPack(File dir) {
    for (Pack pack : packs) {
        try {/*from   w  ww  . j  av a 2  s  . com*/
            if (pack.getDirectory().getCanonicalPath().equals(dir.getCanonicalPath())) {
                return true;
            }
        } catch (IOException ignored) {
        }
    }

    return false;
}

From source file:com.adaptris.core.services.ScriptingServiceTest.java

public void testService() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    msg.addMetadata(MY_METADATA_KEY, MY_METADATA_VALUE);
    ScriptingService service = createService();
    File script = writeScript(true);
    service.setScriptFilename(script.getCanonicalPath());
    execute(service, msg);/* w  ww.j  av a  2 s  .c o m*/
    assertTrue(msg.containsKey(MY_METADATA_KEY));
    assertNotSame(MY_METADATA_VALUE, msg.getMetadataValue(MY_METADATA_KEY));
    assertEquals(new StringBuffer(MY_METADATA_VALUE).reverse().toString(),
            msg.getMetadataValue(MY_METADATA_KEY));
    delete(script);
}