Example usage for java.io File isAbsolute

List of usage examples for java.io File isAbsolute

Introduction

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

Prototype

public boolean isAbsolute() 

Source Link

Document

Tests whether this abstract pathname is absolute.

Usage

From source file:org.eclipse.jubula.client.core.businessprocess.importfilter.ExcelImportFilter.java

/**
 * Open a data file for reading/*from ww  w . j  a  va2 s  .co m*/
 * @param dataDir the data directory
 * @param file the filename
 * @return an opened FIleInputStream for the filename
 * @throws FileNotFoundException guess when!
 */
private FileInputStream findDataFile(File dataDir, String file) throws FileNotFoundException {
    File dataFile = new File(file);
    File infile;
    if (dataFile.isAbsolute()) {
        infile = dataFile;
    } else {
        infile = new File(dataDir, file);
    }
    return new FileInputStream(infile);
}

From source file:org.apache.velocity.test.TemplateTestSuite.java

protected String getFileName(final String dir, final String base, final String ext, final boolean mustExist)
        throws IOException {
    StringBuffer buf = new StringBuffer();
    File baseFile = new File(base);
    if (dir != null) {
        if (!baseFile.isAbsolute()) {
            baseFile = new File(dir, base);
        }/*from w ww  . jav a2  s.co  m*/

        buf.append(baseFile.getCanonicalPath());
    } else {
        buf.append(baseFile.getPath());
    }

    if (org.apache.commons.lang.StringUtils.isNotEmpty(ext)) {
        buf.append('.').append(ext);
    }

    if (mustExist) {
        File testFile = new File(buf.toString());
        //                File testFile = new File( this.getClass().getResource( buf.toString() ).getFile() );

        if (!testFile.exists()) {
            String msg = "getFileName() result " + testFile.getPath() + " does not exist!";
            throw new FileNotFoundException(msg);
        }

        if (!testFile.isFile()) {
            String msg = "getFileName() result " + testFile.getPath() + " is not a file!";
            throw new FileNotFoundException(msg);
        }
    }

    return buf.toString();
}

From source file:com.teotigraphix.caustk.project.ProjectManager.java

private File toProjectFile(File file) {
    if (file.isAbsolute())
        return file;
    return new File(projectDirectory, file.getPath());
}

From source file:com.teotigraphix.caustk.project.ProjectManager.java

@Override
public boolean isProject(File file) {
    if (file.isAbsolute())
        return file.exists();
    return toProjectFile(file).exists();
}

From source file:it.geosolutions.geobatch.flow.file.FileBasedFlowManager.java

public static File initConfigDir(FileBasedFlowConfiguration flowCfg, File geoBatchConfigDir)
        throws FileNotFoundException {

    // set config dir
    File ret = null;/*from w w w  .j a  v a  2 s  .  c  o m*/
    File ovrCfgDir = flowCfg.getOverrideConfigDir();
    if (ovrCfgDir == null) {
        ret = new File(geoBatchConfigDir, flowCfg.getId());
        if (!ret.exists()) {
            if (LOGGER.isDebugEnabled())
                LOGGER.debug("Default config dir does not exist: " + ret);
        }
    } else {
        if (!ovrCfgDir.isAbsolute()) {
            ret = new File(geoBatchConfigDir, ovrCfgDir.getPath());
        } else {
            ret = ovrCfgDir;
        }
        if (!ret.isDirectory() || !ret.canRead()) {
            throw new FileNotFoundException("Unable to locate the overriden configDir: " + ret);
        }
    }

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Flow: " + flowCfg.getId() + " - conf dir is now set to -> " + ret);
    }
    return ret;
}

From source file:org.apache.tapestry5.test.Jetty7Runner.java

/**
 * Needed inside Maven multi-projects to expand a path relative to the module to a complete
 * path. If the path already is absolute and points to an existing directory, it will be used
 * unchanged./*from   w ww  . j  a  v  a 2 s  .c  o m*/
 *
 * @param moduleLocalPath
 * @return expanded path
 * @see TapestryRunnerConstants#MODULE_BASE_DIR
 */
protected String expand(String moduleLocalPath) {
    File path = new File(moduleLocalPath);

    // Don't expand if the path provided already exists.
    if (path.isAbsolute() && path.isDirectory())
        return moduleLocalPath;

    return new File(TapestryRunnerConstants.MODULE_BASE_DIR, moduleLocalPath).getPath();
}

From source file:de.micromata.genome.tpsb.builder.ScenarioLoaderContext.java

protected File resolveBaseDir() {
    File relpathFile = new File(relPath);
    if (relpathFile.isAbsolute() == true) {
        return relpathFile;
    }/*from  w  w w .  ja  va 2 s .  c  o m*/
    String genomeHome = LocalSettings.get().getGenomeHome();
    if (StringUtils.isBlank(genomeHome) == true) {
        genomeHome = ".";
    }
    File tbaseDir = new File(new File(genomeHome).getAbsoluteFile(), relPath);
    return tbaseDir;
}

From source file:com.solutions.it.exemplar.KarmaJunitReporterJsTestDriverSensor.java

/**
 * Returns a java.io.File for the given path.
 * If path is not absolute, returns a File with project base directory as parent path.
 *//*from  www  .  j a v a2s.  c om*/
protected File getIOFile(final String path) {
    File file = new File(path);
    if (!file.isAbsolute()) {
        file = new File(fileSystem.baseDir(), path);
    }

    return file;
}

From source file:edu.harvard.med.screensaver.ui.arch.util.servlet.ImageProviderServlet.java

/**
 * Factor the getImage method out so that clients may invoke this method directly,
 * instead of only through the service method (via HTTP).
 *//*from   w w w  .  ja v a 2 s  . c o  m*/
public File getImage(String servletContextPath, String pathInfo) {

    String temp = _imagesFileSystemPath;
    // make a relative path if its not absolute, this is not uber-useful, 
    // but it allows a *default* screensaver.properties to specify a valid system file path 
    // as simply a relative one, the actual deployment should specify absolute system paths, however.
    File file = new File(temp);
    if (!file.isAbsolute()) {
        temp = servletContextPath + temp;
        file = new File(temp);
    }

    if (_urlEncrypter != null) {
        Pattern filenamePattern = Pattern.compile(
                "(.*)" + _urlEncrypter.getDelimiter() + "(.*)" + _urlEncrypter.getDelimiter() + "(.*)");
        String name = pathInfo;
        Matcher m = filenamePattern.matcher(pathInfo);
        if (m.matches()) {
            if (log.isDebugEnabled())
                log.debug("path: " + m.group(1) + ", filename: " + m.group(2) + ", ext: " + m.group(3));
            name = m.group(1) + _urlEncrypter.decryptUrl(m.group(2));
            name += m.group(3);
        } else {
            name = _urlEncrypter.decryptUrl(name);
        }
        if (log.isDebugEnabled())
            log.info("pathInfo decrypted from: " + pathInfo + " to " + name);
        pathInfo = name;
    }

    return new File(file, pathInfo);
}

From source file:com.boundlessgeo.geoserver.api.controllers.IO.java

private static String sourceFile(String file, GeoServerDataDirectory dataDir) {
    File baseDirectory = dataDir.getResourceLoader().getBaseDirectory();

    File f = new File(file);
    return f.isAbsolute() ? file : Paths.convert(baseDirectory, f);
}