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.ibm.liberty.starter.service.swagger.api.v1.it.TestApplication.java

@Test
public void testPrepareDynamicPackages() throws Exception {
    String serverOutputDir = new File("./build/test/wlp/servers/StarterServer").getCanonicalPath().replace('\\',
            '/');
    System.out.println("serverOutputDir=" + serverOutputDir);
    String uuid = UUID.randomUUID().toString();
    String swaggerTechDirPath = serverOutputDir + "/workarea/appAccelerator/" + uuid + "/swagger";
    File swaggerFile = new File(swaggerTechDirPath + "/server/src/sampleSwagger.json");
    createSampleSwagger(swaggerFile);//  w ww. java2 s . c  o m
    assertTrue("Swagger file doesn't exist : " + swaggerFile.getCanonicalPath(), swaggerFile.exists());
    String actual = testEndpoint(
            "/api/v1/provider/packages/prepare?path=" + swaggerTechDirPath + "&options=server");
    assertNotNull("No response from API for packages/prepare", actual);
    assertEquals("Response doesn't match : " + actual, "success", actual);
    String packagedFilePath = swaggerTechDirPath + "/package/src/sampleSwagger.json";
    assertTrue("Swagger file was not packaged successfully : " + packagedFilePath,
            new File(packagedFilePath).exists());
}

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

public void onDirectoryChange(File changedDir) {
    try {//  w ww. j  av a 2  s .co  m
        LOGGER.debug("Directory " + changedDir.getCanonicalPath() + " changed.");
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    }

    reloadPolicies();
}

From source file:eu.eubrazilcc.lvl.core.FileCompressorTest.java

@Test
public void test() {
    System.out.println("FileCompressorTest.test()");
    try {/*from   w ww.j  a v a2 s .  c o m*/
        // test create tarball from directory
        final String filenameNoPath = "bundle.tar.gz";
        final File tarGzipFile = new File(TEST_OUTPUT_DIR, filenameNoPath);
        final String tarGzipFilename = tarGzipFile.getCanonicalPath();
        final String sourceDir = concat(TEST_RESOURCES_PATH, GB_SEQUENCES_FOLDER);
        System.out.println(" >> Will compress directory " + sourceDir + " to TARBALL " + tarGzipFilename);
        tarGzipDir(sourceDir, tarGzipFilename);
        assertThat("tar.gz file exists", tarGzipFile.exists(), equalTo(true));
        assertThat("tar.gz file is not empty", tarGzipFile.length() > 0l, equalTo(true));

        // test tarball uncompress
        final String uncompressedDirname = tarGzipFilename + "_uncompressed";
        final File uncompressedDir = new File(uncompressedDirname);
        System.out.println(
                " >> Will uncompress TARBALL " + tarGzipFilename + " to directory " + uncompressedDirname);
        final List<String> uncompressedFiles = unGzipUnTar(tarGzipFilename, uncompressedDirname);
        assertThat("tar.gz uncompressed directory exists", uncompressedDir.exists(), equalTo(true));
        final int numberOfFiles = listFiles(new File(sourceDir), null, true).size();
        assertThat("number of uncompressed files coincides with expected", uncompressedFiles.size(),
                equalTo(numberOfFiles));
        for (final String uncompressedFile : uncompressedFiles) {
            assertThat("uncompressed file exists: " + uncompressedFile, new File(uncompressedFile).exists(),
                    equalTo(true));
            assertThat("uncompressed file is not empty: " + uncompressedFile,
                    new File(uncompressedFile).length() > 0l, equalTo(true));
            checkFile(new File(sourceDir, getName(uncompressedFile)), new File(uncompressedFile));
        }

        // test compress file with GZIP
        final List<File> files = newArrayList(getGBSeqXMLFiles());
        shuffle(files);
        final File srcFile = files.get(0);
        final String srcFilename = srcFile.getCanonicalPath();
        System.out.println(" >> Will compress file " + srcFilename + " with GZIP");
        final String outFilename = gzip(srcFilename);
        assertThat("output GZIP filename is not null", outFilename, notNullValue());
        assertThat("output GZIP filename is not empty", isNotEmpty(outFilename), equalTo(true));
        final File outFile = new File(outFilename);
        assertThat("output GZIP file exists", outFile.exists(), equalTo(true));
        assertThat("output GZIP file is not empty", outFile.length() > 0l, equalTo(true));

        // test uncompress GZIP compressed file
        final File uncompressedFile = new File(TEST_OUTPUT_DIR, srcFile.getName());
        final String uncompressedFilename = uncompressedFile.getCanonicalPath();
        gunzip(outFilename, uncompressedFilename);
        assertThat("file uncompressed from GZIP exists: " + uncompressedFilename, uncompressedFile.exists(),
                equalTo(true));
        assertThat("file uncompressed from GZIP is not empty: " + uncompressedFilename,
                uncompressedFile.length() > 0l, equalTo(true));
        checkFile(srcFile, uncompressedFile);

    } catch (Exception e) {
        e.printStackTrace(System.err);
        fail("FileCompressorTest.test() failed: " + e.getMessage());
    } finally {
        System.out.println("FileCompressorTest.test() has finished");
    }
}

From source file:com.blackducksoftware.integration.hub.detect.workflow.diagnostic.DiagnosticLogger.java

public void startLoggingExtraction(final ExtractionId extractionId) {
    logger.info("Diagnostics attempting to redirect extraction logs: " + extractionId.toUniqueString());
    final File logDir = new File(logDirectory, "extractions");
    logDir.mkdirs();//  www.j  av  a 2 s  . c  o  m
    final File logFile = new File(logDir, extractionId.toUniqueString() + ".txt");
    try {
        final String logFilePath = logFile.getCanonicalPath();
        extractionAppender = addAppender(logFilePath);
        logger.info("Redirected to file: " + logFilePath);
    } catch (final IOException e) {
        logger.info("Failed to redirect.", e);
    }

}

From source file:org.italiangrid.storm.webdav.fs.DefaultFSStrategy.java

@Override
public void cp(File source, File dest) {

    LOG.debug("cp: source={} target={}", source.getAbsolutePath(), dest.getAbsolutePath());

    try {/*from   w w  w.ja va 2  s .c  o  m*/

        if (source.getCanonicalPath().equals(dest.getCanonicalPath())) {
            throw new SameFileError("Source and destination files are the same");
        }

        if (source.isDirectory()) {

            FileUtils.copyDirectory(source, dest);

        } else {

            Files.copy(source, dest);

        }

    } catch (IOException e) {

        throw new StoRMWebDAVError(e.getMessage(), e);
    }
}

From source file:com.liferay.mobile.sdk.core.tests.MobileSDKCoreTests.java

private Collection<File> build(String server, String contextName, String filter, String packageName)
        throws IOException {
    final File newTempDir = MobileSDKCore.newTempDir();

    MobileSDKBuilder.build(server, contextName, packageName, filter, newTempDir.getCanonicalPath(),
            new NullProgressMonitor());

    return FileUtils.listFiles(newTempDir, null, true);
}

From source file:JarHelper.java

/**
 * Jars a given directory or single file into a JarOutputStream.
 *///from w ww  .  j  a  v a 2s. c  o  m
public void jarDir(File dirOrFile2Jar, File destJar) throws IOException {

    if (dirOrFile2Jar == null || destJar == null)
        throw new IllegalArgumentException();

    mDestJarName = destJar.getCanonicalPath();
    FileOutputStream fout = new FileOutputStream(destJar);
    JarOutputStream jout = new JarOutputStream(fout);
    // jout.setLevel(0);
    try {
        jarDir(dirOrFile2Jar, jout, null);
    } catch (IOException ioe) {
        throw ioe;
    } finally {
        jout.close();
        fout.close();
    }
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.URLTest.java

/**
 * @throws Exception if the test fails//from   w  w  w . ja  v a2  s  .c  o m
 */
@Test
@NotYetImplemented
public void createObjectURL() 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"

            + "    var url = window.URL.createObjectURL(files[0]);\n" + "    alert(url);\n"
            + "    window.URL.revokeObjectURL(url);\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();

        final String url = getCollectedAlerts(driver).get(0);
        Assert.assertTrue(url, url.startsWith("blob:"));
    } finally {
        FileUtils.deleteQuietly(tstFile);
    }
}

From source file:com.addthis.hydra.task.map.DataPurgeServiceImpl.java

private void delete(File file) {
    String name;/*from   ww w .ja  v a 2  s.c  om*/
    try {
        name = file.getCanonicalPath();
    } catch (IOException e) {
        name = "(unk-path)" + file.getName();
    }
    logger.debug("Deleting: " + name);
    try {
        if (file.isDirectory()) {
            FileUtils.deleteDirectory(file);
        } else {
            FileUtils.deleteQuietly(file);
        }
    } catch (IOException e) {
        logger.error("error purging : " + file, e);
    }
}