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.gargoylesoftware.htmlunit.javascript.host.file.FileListTest.java

/**
 * @throws Exception if the test fails/*from w  w  w . j  a v  a 2s . co m*/
 */
@Test
@Alerts({ "1", "true" })
public void in() throws Exception {
    final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" + "<head><title>foo</title>\n"
            + "<script>\n" + "function test() {\n" + "  if (document.testForm.fileupload.files) {\n"
            + "    var files = document.testForm.fileupload.files;\n" + "    alert(files.length);\n"

            + "    alert(0 in files);\n" + "  }\n" + "}\n" + "</script>\n" + "</head>\n" + "<body>\n"
            + "  <form name='testForm'>\n" + "    <input type='file' id='fileupload' name='fileupload'>\n"
            + "  </form>\n" + "  <button id='testBtn' onclick='test()'>Tester</button>\n" + "</body>\n"
            + "</html>";

    final WebDriver driver = loadPage2(html);

    final File tstFile = File.createTempFile("HtmlUnitUploadTest", ".txt");
    try {
        FileUtils.writeStringToFile(tstFile, "Hello HtmlUnit", TextUtil.DEFAULT_CHARSET);

        final String path = tstFile.getCanonicalPath();
        driver.findElement(By.name("fileupload")).sendKeys(path);

        driver.findElement(By.id("testBtn")).click();
        verifyAlerts(driver, getExpectedAlerts());
    } finally {
        FileUtils.deleteQuietly(tstFile);
    }
}

From source file:io.wcm.devops.conga.plugins.aem.postprocessor.ContentPackagePostProcessor.java

@Override
public List<FileContext> apply(FileContext fileContext, PostProcessorContext context) {
    File file = fileContext.getFile();
    Logger logger = context.getLogger();
    Map<String, Object> options = context.getOptions();

    try {/*from   w  ww.j  a  va 2s  . co  m*/
        // extract file header
        FileHeaderContext fileHeader = extractFileHeader(fileContext, context);

        // create AEM content package with configurations
        File zipFile = new File(file.getParentFile(), FilenameUtils.getBaseName(file.getName()) + ".zip");
        logger.info("Generate " + zipFile.getCanonicalPath());

        String rootPath = ContentPackageUtil.getMandatoryProp(options, PROPERTY_PACKAGE_ROOT_PATH);

        ContentPackageBuilder builder = ContentPackageUtil.getContentPackageBuilder(options, fileHeader);
        try (ContentPackage contentPackage = builder.build(zipFile)) {

            // add content from JSON file
            ContentElement content = jsonContentLoader.load(fileContext.getFile());
            contentPackage.addContent(rootPath, content);

            // add additional binary files
            for (ContentPackageBinaryFile binaryFile : ContentPackageUtil.getFiles(options)) {
                String path = binaryFile.getPath();
                try (InputStream is = binaryFile.getInputStream(context.getUrlFileManager(),
                        fileContext.getTargetDir())) {
                    contentPackage.addFile(path, is);
                }
                binaryFile.deleteIfRequired(context.getUrlFileManager(), fileContext.getTargetDir());
            }

        }

        // delete provisioning file after transformation
        file.delete();

        // set force to true by default for CONGA-generated packages (but allow override from role definition)
        Map<String, Object> modelOptions = new HashMap<>();
        modelOptions.put("force", true);
        modelOptions.putAll(fileContext.getModelOptions());

        return ImmutableList.of(new FileContext().file(zipFile).modelOptions(modelOptions));
    } catch (IOException ex) {
        throw new GeneratorException(
                "Unable to post-process JSON data file: " + FileUtil.getCanonicalPath(file), ex);
    }
}

From source file:com.voodoowarez.alclassicist.CtDumpMojo.java

protected String fetchClassnameFromFile(final File file) throws MojoExecutionException {
    try {//from   ww  w .ja  va2s .  c  o  m
        final File parent = file.getParentFile();
        final String fullPath = file.getCanonicalPath();
        return fullPath.substring(parent.getCanonicalPath().length(), fullPath.length() - this.classTrim);
    } catch (IOException e) {
        throw new MojoExecutionException("Bad file", e);
    }
}

From source file:com.xiaomi.linden.common.EmbeddedZooKeeper.java

private File genZookeeperDataDir() {
    File zkDir = null;
    try {/*w w  w. j av a2  s.c  om*/
        zkDir = File.createTempFile("zoo", "data");
        if (!zkDir.delete())
            throw new IOException("Can't rm zkDir " + zkDir.getCanonicalPath());
        if (!zkDir.mkdir())
            throw new IOException("Can't mkdir zkDir " + zkDir.getCanonicalPath());
    } catch (IOException e) {
        LOGGER.error("Can't make zookeeper data dir");
    }
    return zkDir;
}

From source file:com.synopsys.integration.blackduck.service.model.pdf.RiskReportWriter.java

public void createHtmlReportFiles(final Gson gson, final File outputDirectory, final ReportData reportData)
        throws RiskReportException {
    try {//from   w ww.  j a va  2  s  . co  m
        final RiskReportResourceCopier copier = new RiskReportResourceCopier(
                outputDirectory.getCanonicalPath());
        File htmlFile = null;
        try {
            final List<File> writtenFiles = copier.copy();
            for (final File file : writtenFiles) {
                if (file.getName().equals(RiskReportResourceCopier.RISK_REPORT_HTML_FILE_NAME)) {
                    htmlFile = file;
                    break;
                }
            }
        } catch (final URISyntaxException e) {
            throw new RiskReportException("Couldn't create the report: " + e.getMessage(), e);
        }
        if (htmlFile == null) {
            throw new RiskReportException(
                    "Could not find the file : " + RiskReportResourceCopier.RISK_REPORT_HTML_FILE_NAME
                            + ", the report files must not have been copied into the report directory.");
        }
        String htmlFileString = FileUtils.readFileToString(htmlFile, "UTF-8");
        final String reportString = gson.toJson(reportData);
        htmlFileString = htmlFileString.replace(RiskReportResourceCopier.JSON_TOKEN_TO_REPLACE, reportString);
        FileUtils.writeStringToFile(htmlFile, htmlFileString, "UTF-8");
    } catch (final IOException e) {
        throw new RiskReportException("Couldn't create the report: " + e.getMessage(), e);
    }
}

From source file:drat.proteus.DratStartForm.java

private void parseAsVersionControlledRepo(String path, String command, boolean downloadPhase)
        throws IOException {
    if (!downloadPhase) {
        startDrat(path, command);//from   ww w.  j a v  a2  s  . c o m
        return;
    }

    String projectName = null;
    boolean git = path.endsWith(".git");
    File tmpDir = new File(System.getProperty("java.io.tmpdir"));
    String tmpDirPath = tmpDir.getCanonicalPath();
    String line = null;
    if (git) {
        projectName = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf("."));
        line = "git clone --depth 1 --branch master " + path;
    } else {
        projectName = path.substring(path.lastIndexOf("/") + 1);
        line = "svn export " + path;
    }
    String clonePath = tmpDirPath + File.separator + projectName;
    File cloneDir = new File(clonePath);
    if (cloneDir.isDirectory() && cloneDir.exists()) {
        LOG.info("Git / SVN clone: [" + clonePath + "] already exists, removing it.");
        FileUtils.removeDir(cloneDir);
    }
    LOG.info("Cloning Git / SVN project: [" + projectName + "] remote repo: [" + path + "] into " + tmpDirPath);

    CommandLine cmdLine = CommandLine.parse(line);
    DefaultExecutor executor = new DefaultExecutor();
    executor.setWorkingDirectory(tmpDir);
    int exitValue = executor.execute(cmdLine);

    if (git) {
        String gitHiddenDirPath = clonePath + File.separator + ".git";
        File gitHiddenDir = new File(gitHiddenDirPath);
        LOG.info("Removing .git directory from " + gitHiddenDirPath);
        FileUtils.removeDir(gitHiddenDir);
    }

    startDrat(clonePath, command);

}

From source file:com.ormanli.duplicatefinder.main.Worker.java

@Override
public void run() {
    try {//from w w w .j  ava 2 s  . c o m
        List<File> fileList = fileUtil.getEntryList();

        if (fileList != null) {
            logger.info("Worker " + this.hashCode() + " list length " + fileList.size());
            for (File filePath : fileList) {
                String fileHash = fileUtil.getFileHash(filePath);
                logger.info("File: " + filePath + " Hash: " + fileHash);
                SQLExecuter.getInstance().insertToTables(fileHash, filePath.getCanonicalPath());
            }
        }
    } catch (Exception e) {
        logger.error(StringUtils.EMPTY, e);
    }
}

From source file:com.bazaarvoice.jsonpps.PrettyPrintJson.java

private boolean caseInsensitiveContains(Collection<File> srcs, File dest) throws IOException {
    for (File src : srcs) {
        if (!STDINOUT.equals(src) && src.getCanonicalPath().equalsIgnoreCase(dest.getCanonicalPath())) {
            return true;
        }/*from  w w  w  .ja va  2 s . c om*/
    }
    return false;
}

From source file:it.polimi.diceH2020.SPACE4CloudWS.fileManagement.FileUtility.java

public String createInputSubFolder(@NotNull String folderName) throws IOException {
    File folder = new File(settings.getInputDirectory(), folderName);
    if (folder.mkdirs()) {
        policy.markForDeletion(folder);/*from  w  w  w  . j  av  a  2 s.  c om*/
    }
    return folder.getCanonicalPath();
}

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

public void onFileDelete(File deleteFile) {
    try {//from www  . ja  v a2 s .c  om
        LOGGER.debug("File " + deleteFile.getCanonicalPath() + " was deleted.");
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    }

    reloadPolicies();
}