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:org.cloudfoundry.client.lib.SampleProjects.java

/**
 * Returns the spring travel MVC reference application.
 *
 * @return the spring travel reference WAR file
 * @throws IOException/*from   w  ww.  ja va 2  s.  c o m*/
 */
public static File springTravel() throws IOException {
    File file = new File(TEST_APP_DIR + "/travelapp/swf-booking-mvc.war");
    assertTrue("Expected test app at " + file.getCanonicalPath(), file.exists());
    return file;
}

From source file:eu.eubrazilcc.lvl.oauth2.AllJUnitTests.java

@BeforeClass
public static void setup() {
    System.out.println("AllJUnitTests.setup()");
    final URL anchorURL = AllJUnitTests.class.getClassLoader().getResource(ANCHOR_FILENAME);
    File anchorFile = null;//from  www . ja v  a  2s  . com
    try {
        anchorFile = new File(anchorURL.toURI());
    } catch (Exception e) {
        anchorFile = new File(System.getProperty("user.dir"));
    }
    TEST_RESOURCES_PATH = concat(anchorFile.getParent(), "files");
    final File resDir = new File(TEST_RESOURCES_PATH);
    if (resDir != null && resDir.isDirectory() && resDir.canRead()) {
        try {
            TEST_RESOURCES_PATH = resDir.getCanonicalPath();
        } catch (IOException e) {
            // nothing to do
        }
    } else {
        throw new IllegalStateException("Invalid test resources pathname: " + TEST_RESOURCES_PATH);
    }
    System.out.println("Test resources pathname: " + TEST_RESOURCES_PATH);
    // load logging bridges
    LOG_MANAGER.preload();
    // system pre-loading
    LIGHT_CLOSER_SERVICE_MOCK.preload();
}

From source file:eu.eubrazilcc.lvl.storage.AllJUnitTests.java

@BeforeClass
public static void setup() {
    System.out.println("AllJUnitTests.setup()");
    final URL anchorURL = AllIntegrationTests.class.getClassLoader().getResource(ANCHOR_FILENAME);
    File anchorFile = null;//w  w w  .j  a v a  2s .  c  om
    try {
        anchorFile = new File(anchorURL.toURI());
    } catch (Exception e) {
        anchorFile = new File(System.getProperty("user.dir"));
    }
    TEST_RESOURCES_PATH = concat(anchorFile.getParent(), "files");
    final File resDir = new File(TEST_RESOURCES_PATH);
    if (resDir != null && resDir.isDirectory() && resDir.canRead()) {
        try {
            TEST_RESOURCES_PATH = resDir.getCanonicalPath();
        } catch (IOException e) {
            // nothing to do
        }
    } else {
        throw new IllegalStateException("Invalid test resources pathname: " + TEST_RESOURCES_PATH);
    }
    System.out.println("Test resources pathname: " + TEST_RESOURCES_PATH);
    // load logging bridges
    LOG_MANAGER.preload();
    // system pre-loading
    LIGHT_CLOSER_SERVICE_MOCK.preload();
}

From source file:eu.eubrazilcc.lvl.storage.AllIntegrationTests.java

@BeforeClass
public static void setup() {
    System.out.println("AllIntegrationTests.setup()");
    final URL anchorURL = AllIntegrationTests.class.getClassLoader().getResource(ANCHOR_FILENAME);
    File anchorFile = null;/*from w  w  w .j  av a 2s.co  m*/
    try {
        anchorFile = new File(anchorURL.toURI());
    } catch (Exception e) {
        anchorFile = new File(System.getProperty("user.dir"));
    }
    TEST_RESOURCES_PATH = concat(anchorFile.getParent(), "files");
    final File resDir = new File(TEST_RESOURCES_PATH);
    if (resDir != null && resDir.isDirectory() && resDir.canRead()) {
        try {
            TEST_RESOURCES_PATH = resDir.getCanonicalPath();
        } catch (IOException e) {
            // nothing to do
        }
    } else {
        throw new IllegalStateException("Invalid test resources pathname: " + TEST_RESOURCES_PATH);
    }
    System.out.println("Test resources pathname: " + TEST_RESOURCES_PATH);
    // load logging bridges
    LOG_MANAGER.preload();
    // system pre-loading
    CLOSER_SERVICE_MOCK.preload();
}

From source file:com.amazonaws.codepipeline.jenkinsplugin.ExtractionTools.java

private static File getDestinationFile(final File basedir, final String file) throws IOException {
    final File destination = new File(basedir, file);
    final String canonicalDestination = destination.getCanonicalPath();
    final String canonicalBasedir = basedir.getCanonicalPath();

    if (canonicalDestination.startsWith(canonicalBasedir + File.separator)
            || canonicalDestination.equals(canonicalBasedir)) {
        return destination;
    }/* w w  w . j  a va 2s  .c o m*/

    throw new IOException("The compressed input file contains files targeting an invalid destination: " + file);
}

From source file:com.moz.fiji.mapreduce.DistributedCacheJars.java

/**
 * Adds the jars from a directory into the distributed cache of a job.
 *
 * @param job The job to configure.//ww  w . j  a va  2  s.c om
 * @param jarDirectory A path to a directory of jar files.
 * @throws IOException on I/O error.
 */
public static void addJarsToDistributedCache(Job job, File jarDirectory) throws IOException {
    addJarsToDistributedCache(job, new Path("file:" + jarDirectory.getCanonicalPath()));
}

From source file:com.cedarsoft.codegen.AbstractGenerator.java

@Nonnull
protected static String calculateRelativePath(@Nonnull File dir, @Nonnull File serializerFile)
        throws IOException {
    return serializerFile.getCanonicalPath().substring(dir.getCanonicalPath().length() + 1);
}

From source file:gov.nih.nci.cagrid.introduce.servicetools.FilePersistenceHelper.java

public static File getDefaultStorageDirectory(File baseDir, Class beanClass) throws IOException {
    if (beanClass == null) {
        return null;
    }//from w  ww. j a  v  a2s .com
    String fullClassName = beanClass.getName();
    String className = fullClassName;
    int pos = className.lastIndexOf('.');
    if (pos != -1) {
        className = className.substring(pos + 1);
    }

    String dir = baseDir.getAbsolutePath() + File.separatorChar + className;

    File storageDir = new File(dir);
    if (!storageDir.getCanonicalPath().startsWith(baseDir.getCanonicalPath())) {
        throw new IOException("invalidStorageDir: " + dir);
    }

    return storageDir;
}

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

@BeforeClass
public static void setup() {
    System.out.println("AllTests.setup()");
    final URL anchorURL = AllTests.class.getClassLoader().getResource(ANCHOR_FILENAME);
    File anchorFile = null;/*w w w  .  ja  v  a2s  .c o m*/
    try {
        anchorFile = new File(anchorURL.toURI());
    } catch (Exception e) {
        anchorFile = new File(System.getProperty("user.dir"));
    }
    TEST_RESOURCES_PATH = concat(anchorFile.getParent(), "files");
    final File resDir = new File(TEST_RESOURCES_PATH);
    if (resDir != null && resDir.isDirectory() && resDir.canRead()) {
        try {
            TEST_RESOURCES_PATH = resDir.getCanonicalPath();
        } catch (IOException e) {
            // nothing to do
        }
    } else {
        throw new IllegalStateException("Invalid test resources pathname: " + TEST_RESOURCES_PATH);
    }
    System.out.println("Test resources pathname: " + TEST_RESOURCES_PATH);
    // load logging bridges
    LOG_MANAGER.preload();
    // system pre-loading
    CLOSER_SERVICE_MOCK.preload();
}

From source file:Main.java

public static Document openXmlFile(File file, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware)
        throws IOException, SAXParseException, SAXException {
    final String fname = file.getCanonicalPath();
    DocumentBuilder builder = newDocumentBuilder(schema, isNamespaceAware, isXIncludeAware);
    Document docu;/*from w ww .j av a 2s .  c  om*/

    builder.setErrorHandler(new org.xml.sax.ErrorHandler() {
        @Override
        public void error(SAXParseException exception) throws SAXParseException {
            //System.err.println("Parse Error in file " + fname + ", line " + exception.getLineNumber() + ": " + exception.getMessage());
            throw new SAXParseException("Parse Error in file " + fname + ", line " + exception.getLineNumber()
                    + ": " + exception.getMessage(), "", fname, exception.getLineNumber(), 0);
        }

        @Override
        public void fatalError(SAXParseException exception) throws SAXParseException {
            //System.err.println("Parse Fatal Error: " + exception.getMessage() + exception.getLineNumber());
            throw new SAXParseException("Parse Error in file " + fname + ", line " + exception.getLineNumber()
                    + ": " + exception.getMessage(), "", fname, exception.getLineNumber(), 0);
        }

        @Override
        public void warning(SAXParseException exception) {
            System.err.println("Parse Warning: " + exception.getMessage() + exception.getLineNumber());
        }
    });

    docu = builder.parse(file);
    return docu;
}