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.adaptris.core.runtime.MessageDigestErrorEntryTest.java

@Test
public void testSetFilesystemLocation() throws Exception {
    MessageDigestErrorEntry entry = null;
    entry = new MessageDigestErrorEntry("123", "234");
    assertNull(entry.getFileSystemPath());
    assertNull(entry.getStackTrace());//  w ww  .ja  v  a 2  s . c  o  m
    File fsLocation = deleteLater(entry);
    File fsLocation2 = deleteLater(entry);
    entry.setFileSystemFile(fsLocation);
    assertEquals(fsLocation.getCanonicalPath(), entry.getFileSystemPath());
    entry.setFileSystemPath(fsLocation2.getCanonicalPath());
    assertEquals(fsLocation2.getCanonicalPath(), entry.getFileSystemPath());
}

From source file:io.wcm.devops.conga.tooling.maven.plugin.DefinitionPackageMojo.java

private String getPathForLog(File rootOutputDir, File file) throws IOException {
    String path = unifySlashes(file.getCanonicalPath());
    String rootPath = unifySlashes(rootOutputDir.getCanonicalPath()) + "/";
    return StringUtils.substringAfter(path, rootPath);
}

From source file:fr.acxio.tools.agia.tasks.ZipFilesTasklet.java

protected void zipResource(Resource sSourceResource, ZipArchiveOutputStream sZipArchiveOutputStream,
        StepContribution sContribution, ChunkContext sChunkContext) throws IOException, ZipFilesException {
    // TODO : use a queue to reduce the callstack overhead
    if (sSourceResource.exists()) {
        File aSourceFile = sSourceResource.getFile();
        String aSourcePath = aSourceFile.getCanonicalPath();

        if (!aSourcePath.startsWith(sourceBaseDirectoryPath)) {
            throw new ZipFilesException(
                    "Source file " + aSourcePath + " does not match base directory " + sourceBaseDirectoryPath);
        }/* w w w.jav  a  2s .  co  m*/

        if (sContribution != null) {
            sContribution.incrementReadCount();
        }
        String aZipEntryName = aSourcePath.substring(sourceBaseDirectoryPath.length() + 1);
        sZipArchiveOutputStream.putArchiveEntry(new ZipArchiveEntry(aZipEntryName));
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Zipping {} to {}", sSourceResource.getFile().getCanonicalPath(), aZipEntryName);
        }
        if (aSourceFile.isFile()) {
            InputStream aInputStream = sSourceResource.getInputStream();
            IOUtils.copy(aInputStream, sZipArchiveOutputStream);
            aInputStream.close();
            sZipArchiveOutputStream.closeArchiveEntry();
        } else {
            sZipArchiveOutputStream.closeArchiveEntry();
            for (File aFile : aSourceFile
                    .listFiles((FileFilter) (recursive ? TrueFileFilter.TRUE : FileFileFilter.FILE))) {
                zipResource(new FileSystemResource(aFile), sZipArchiveOutputStream, sContribution,
                        sChunkContext);
            }
        }
        if (sContribution != null) {
            sContribution.incrementWriteCount(1);
        }
    } else if (LOGGER.isInfoEnabled()) {
        LOGGER.info("{} does not exist", sSourceResource.getFilename());
    }
}

From source file:gallery.service.sitemap.SitemapServiceImpl.java

public void setPath(Resource res) {
    try {/*from  w  w  w .  j a  v a 2 s .co  m*/
        File f = res.getFile();
        if (f.exists() && f.isDirectory())
            path = f.getCanonicalPath() + "/";
        else
            throw new NullPointerException("xml path not found for Sitemap");
    } catch (IOException e) {
        path = null;
        throw new NullPointerException("xml path not found for Sitemap");
    }
    //System.out.println("----------------------------path = "+this.path);
}

From source file:com.linkedin.helix.tools.ZKDumper.java

public void upload(String zkPath, String fsPath) throws Exception {
    File file = new File(fsPath);
    System.out.println("Uploading " + file.getCanonicalPath() + " to " + zkPath);
    zkPath = zkPath.replaceAll("[/]+", "/");
    int index = -1;
    if (removeSuffix && (index = file.getName().indexOf(".")) > -1) {
        zkPath = zkPath.replaceAll(file.getName().substring(index), "");
    }/*from   w ww. j a v a 2s  .  c  o m*/
    if (file.isDirectory()) {
        File[] children = file.listFiles(filter);
        client.createPersistent(zkPath, true);
        if (children != null && children.length > 0) {

            for (File child : children) {
                upload(zkPath + "/" + child.getName(), fsPath + "/" + child.getName());
            }
        } else {

        }
    } else {
        BufferedReader bfr = null;
        try {
            bfr = new BufferedReader(new FileReader(file));
            StringBuilder sb = new StringBuilder();
            String line;
            String recordDelimiter = "";
            while ((line = bfr.readLine()) != null) {
                sb.append(recordDelimiter).append(line);
                recordDelimiter = "\n";
            }
            client.createPersistent(zkPath, sb.toString());
        } catch (Exception e) {
            throw e;
        } finally {
            if (bfr != null) {
                try {
                    bfr.close();
                } catch (IOException e) {
                }
            }
        }
    }
}

From source file:ddf.security.pdp.realm.xacml.processor.PollingPolicyFinderModule.java

public void onFileDelete(File deleteFile) {
    try {/*from   www .  jav a2  s.  c  o  m*/
        SecurityLogger.audit("File {} was deleted.", deleteFile.getCanonicalPath());
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    }

    reloadPolicies();
}

From source file:com.magnet.tools.tests.MagnetToolStepDefs.java

public static void runScript(String filePath, String content, ScenarioUtils.InstallerType type)
        throws Throwable {
    File f = ScenarioUtils.createFile(filePath, content);
    CommandLineEntry entry = new CommandLineEntry();
    String magnetToolHome = getTestEnvironment().get(MAGNET_TOOL_HOME);
    Assert.assertNotNull("MAGNET_TOOL_HOME not set, verify you installed the MAB", magnetToolHome);
    ScenarioUtils.log("\n====   SCRIPT   ====\n" + content + "\n==== END SCRIPT ====");
    String s;//from ww  w  . j ava 2 s  . co  m
    switch (type) {
    case MAB:
        s = "mab";
        break;
    case R2M:
        s = "r2m";
        break;
    case MAB_DEBUG_SUSPEND:
        s = "mab-debug-suspend";
        break;
    case R2M_DEBUG_SUSPEND:
        s = "r2m-debug-suspend";
        break;

    default:
        throw new IllegalArgumentException("Unknown executable type " + type);
    }
    entry.command = "bash bin/" + s + " run -v " + f.getCanonicalPath();
    I_run_under_working_directory_the_commands(magnetToolHome, Collections.singletonList(entry));
}

From source file:ddf.security.pdp.realm.xacml.processor.PollingPolicyFinderModule.java

public void onDirectoryChange(File changedDir) {
    try {//ww w.j  av  a2 s. com
        SecurityLogger.audit("Directory {} changed.", changedDir.getCanonicalPath());
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    }

    reloadPolicies();
}

From source file:madkitgroupextension.export.Export.java

public static void updateFTP(FTPClient ftpClient, String _directory_dst, File _directory_src,
        File _current_file_transfert) throws IOException, TransfertException {
    ftpClient.changeWorkingDirectory("./");
    FTPListParseEngine ftplpe = ftpClient.initiateListParsing(_directory_dst);
    FTPFile files[] = ftplpe.getFiles();

    File current_file_transfert = _current_file_transfert;

    try {/*from   w w  w. j  a  va  2s .  com*/
        for (File f : _directory_src.listFiles()) {
            if (f.isDirectory()) {
                if (!f.getName().equals("./") && !f.getName().equals("../")) {
                    if (_current_file_transfert != null) {
                        if (!_current_file_transfert.getCanonicalPath().startsWith(f.getCanonicalPath()))
                            continue;
                        else
                            _current_file_transfert = null;
                    }
                    boolean found = false;
                    for (FTPFile ff : files) {
                        if (f.getName().equals(ff.getName())) {
                            if (ff.isFile()) {
                                ftpClient.deleteFile(_directory_dst + ff.getName());
                            } else
                                found = true;
                            break;
                        }
                    }

                    if (!found) {
                        ftpClient.changeWorkingDirectory("./");
                        if (!ftpClient.makeDirectory(_directory_dst + f.getName() + "/"))
                            System.err.println(
                                    "Impossible to create directory " + _directory_dst + f.getName() + "/");
                    }
                    updateFTP(ftpClient, _directory_dst + f.getName() + "/", f, _current_file_transfert);
                }
            } else {
                if (_current_file_transfert != null) {
                    if (!_current_file_transfert.equals(f.getCanonicalPath()))
                        continue;
                    else
                        _current_file_transfert = null;
                }
                current_file_transfert = _current_file_transfert;
                FTPFile found = null;
                for (FTPFile ff : files) {
                    if (f.getName().equals(ff.getName())) {
                        if (ff.isDirectory()) {
                            FileTools.removeDirectory(ftpClient, _directory_dst + ff.getName());
                        } else
                            found = ff;
                        break;
                    }
                }
                if (found == null || (found.getTimestamp().getTimeInMillis() - f.lastModified()) < 0
                        || found.getSize() != f.length()) {
                    FileInputStream fis = new FileInputStream(f);
                    ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
                    if (!ftpClient.storeFile(_directory_dst + f.getName(), fis))
                        System.err.println("Impossible to send file: " + _directory_dst + f.getName());
                    fis.close();
                    for (FTPFile ff : ftplpe.getFiles()) {
                        if (f.getName().equals(ff.getName())) {
                            f.setLastModified(ff.getTimestamp().getTimeInMillis());
                            break;
                        }
                    }
                }
            }

        }
    } catch (IOException e) {
        throw new TransfertException(current_file_transfert, null, e);
    }
    for (FTPFile ff : files) {
        if (!ff.getName().equals(".") && !ff.getName().equals("..")) {
            boolean found = false;
            for (File f : _directory_src.listFiles()) {
                if (f.getName().equals(ff.getName()) && f.isDirectory() == ff.isDirectory()) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                if (ff.isDirectory()) {
                    FileTools.removeDirectory(ftpClient, _directory_dst + ff.getName());
                } else {
                    ftpClient.deleteFile(_directory_dst + ff.getName());
                }
            }
        }
    }
}

From source file:gallery.service.sitemap.SitemapServiceImpl.java

public void setPath_tmp(Resource res) {
    try {//from w w  w  .j av  a  2 s  .  co  m
        File f = res.getFile();
        if (f.exists() && f.isDirectory())
            path_tmp = f.getCanonicalPath() + "/";
        else
            throw new NullPointerException("xml path not found for Sitemap");
    } catch (IOException e) {
        path_tmp = null;
        throw new NullPointerException("xml path not found for Sitemap");
    }
    //System.out.println("----------------------------path = "+this.path);
}