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.dbgl.util.FileUtils.java

private static File canonicalTo(final File base, final String path) {
    File file = new File(path);
    if (file.isAbsolute()) {
        try {// w w w .j a  v  a2 s .  c o m
            return file.getCanonicalFile();
        } catch (IOException e) {
            return file.getAbsoluteFile();
        }
    } else {
        try {
            return new File(base, file.getPath()).getCanonicalFile();
        } catch (IOException e) {
            return new File(base, file.getPath()).getAbsoluteFile();
        }
    }
}

From source file:org.openvpms.report.tools.TemplateLoader.java

/**
 * Creates a new {@link Document} from a template.
 *
 * @param template the template descriptor
 * @param dir      the directory to locate relative paths
 * @return a new document containing the serialized template
 * @throws DocumentException for any error
 *///ww w.jav a  2s  .c  o  m
private Document getDocument(Template template, File dir) {
    File file = new File(template.getPath());
    if (!file.isAbsolute()) {
        file = new File(dir, template.getPath());
    }
    return DocumentHelper.create(file, template.getDocType(), template.getMimeType(), handlers);
}

From source file:com.cisco.step.jenkins.plugins.jenkow.JenkowWorkflowRepository.java

File getWorkflowFile(String wfName) {
    File f = new File(wfName);
    if (!f.isAbsolute() || !f.exists()) {
        String relName = mkWfPath(wfName);
        f = new File(getRepositoryDir(), relName);
    }// w  w  w  . ja  v a 2  s. c  o  m
    return f;
}

From source file:com.google.gwt.dev.resource.impl.ZipFileClassPathEntry.java

private ZipFileClassPathEntry(File zipFile) throws IOException {
    assert zipFile.isAbsolute();
    this.lastModified = zipFile.lastModified();
    this.zipFile = new ZipFile(zipFile);
    this.location = zipFile.toURI().toString();
}

From source file:cc.creativecomputing.io.CCIOUtil.java

/**
 * Return a full path to an item in the data folder as a File object. 
 * See the {@linkplain #dataPath(String)} method for more information.
 * @param thePath source path for query/*from w ww. j  a va  2 s .c  o  m*/
 * @return full path to an item in the data folder as a File object
 */
static public File dataFile(String thePath) {
    // isAbsolute() could throw an access exception, but so will writing
    // to the local disk using the sketch path, so this is safe here.
    File myFile = new File(thePath);
    if (myFile.isAbsolute())
        return myFile;

    String myJarPath = CCIOUtil.class.getProtectionDomain().getCodeSource().getLocation().getPath()
            .replaceAll("%20", " ");
    if (myJarPath.contains("Contents/Resources/Java/")) {
        File containingFolder = new File(myJarPath).getParentFile();
        File dataFolder = new File(containingFolder, "data");
        return new File(dataFolder, thePath);
    }

    for (String myAssetPath : optionalAssetPaths) {
        myFile = new File(myAssetPath + File.separator + thePath);
        if (myFile.exists())
            return myFile;
    }

    // Windows, Linux, or when not using a Mac OS X .app file
    return new File(CCSystem.applicationPath + File.separator + "data" + File.separator + thePath);
}

From source file:eu.arthepsy.sonar.plugins.scapegoat.rule.ScapegoatReportSensor.java

@Override
public void execute(SensorContext context) {
    String reportPath = context.settings().getString(ScapegoatConfiguration.REPORT_PATH_PROPERTY_KEY);
    if (StringUtils.isNotBlank(reportPath)) {
        File report = new File(reportPath);
        if (!report.isAbsolute()) {
            report = new File(context.fileSystem().baseDir(), reportPath);
        }//from  w  ww.j  a v  a2 s  .  c  o  m
        if (report != null && report.isFile()) {
            LOG.info(LOG_PREFIX + "analyzing report: " + reportPath);
            this.parseReport(context, report);
            return;
        }
    }
    LOG.warn(LOG_PREFIX + "report not found: " + String.valueOf(reportPath));
}

From source file:org.gradle.api.internal.file.FileNormaliser.java

public File normalise(File file) {
    try {//w w w . j  a v a 2 s.c  o  m
        if (!file.isAbsolute()) {
            throw new IllegalArgumentException(String.format("Cannot normalize a relative file: '%s'", file));
        }

        if (isWindowsOs) {
            // on Windows, File.getCanonicalFile() doesn't resolve symlinks
            return file.getCanonicalFile();
        }

        File candidate;
        String filePath = file.getPath();
        List<String> path = null;
        if (isNormalisingRequiredForAbsolutePath(filePath)) {
            path = splitAndNormalisePath(filePath);
            String resolvedPath = CollectionUtils.join(File.separator, path);
            boolean needLeadingSeparator = File.listRoots()[0].getPath().startsWith(File.separator);
            if (needLeadingSeparator) {
                resolvedPath = File.separator + resolvedPath;
            }
            candidate = new File(resolvedPath);
        } else {
            candidate = file;
        }

        // If the file system is case sensitive, we don't have to normalise it further
        if (fileSystem.isCaseSensitive()) {
            return candidate;
        }

        // Short-circuit the slower lookup method by using the canonical file
        File canonical = candidate.getCanonicalFile();
        if (candidate.getPath().equalsIgnoreCase(canonical.getPath())) {
            return canonical;
        }

        // Canonical path is different to what we expected (eg there is a link somewhere in there). Normalise a segment at a time
        // TODO - start resolving only from where the expected and canonical paths are different
        if (path == null) {
            path = splitAndNormalisePath(filePath);
        }
        return normaliseUnixPathIgnoringCase(path);
    } catch (IOException e) {
        throw new UncheckedIOException(String.format("Could not normalize path for file '%s'.", file), e);
    }
}

From source file:org.cloudifysource.dsl.internal.validators.ComputeTemplateValidator.java

private File findUploadDir(final DSLValidationContext context) throws DSLValidationException {
    final File relativeUploadDir = new File(this.entity.getLocalDirectory());
    if (relativeUploadDir.isAbsolute()) {
        throw new DSLValidationException("Upload directory of a cloud template must be a relative path, "
                + "relative to the cloud configuration directory");
    }//from   ww  w  .j a  v  a  2  s. c o m

    File dslDir = null;
    if (context.getFilePath() == null) {
        throw new IllegalStateException("The DSL File location is not set! Cannot validate!");
    } else {
        final File dslFile = new File(context.getFilePath());
        dslDir = dslFile.getParentFile();
    }

    final File uploadDir = new File(dslDir, entity.getLocalDirectory());
    if (!uploadDir.exists()) {
        throw new DSLValidationException("Could not find upload directory at: " + uploadDir);
    }

    if (!uploadDir.isDirectory()) {
        throw new DSLValidationException("Upload directory, set to: " + uploadDir + " is not a directory");
    }
    return uploadDir;
}

From source file:org.dbgl.util.FileUtils.java

public static File makeRelativeTo(final File file, final File basePath) {
    if (!file.isAbsolute()) {
        return file;
    }/* www.j  ava  2s .c  om*/
    if (file.equals(basePath)) {
        return new File(".");
    }
    File remainder = new File(file.getName());
    File parent = file.getParentFile();
    while (parent != null) {
        if (parent.equals(basePath)) {
            return remainder;
        }
        remainder = new File(parent.getName(), remainder.getPath());
        parent = parent.getParentFile();
    }
    return file;
}

From source file:org.apache.ofbiz.content.data.DataResourceWorker.java

public static void renderFile(String dataResourceTypeId, String objectInfo, String rootDir, Appendable out)
        throws GeneralException, IOException {
    // TODO: this method assumes the file is a text file, if it is an image we should respond differently, see the comment above for IMAGE_OBJECT type data resource

    if (dataResourceTypeId.equals("LOCAL_FILE") && UtilValidate.isNotEmpty(objectInfo)) {
        File file = FileUtil.getFile(objectInfo);
        if (!file.isAbsolute()) {
            throw new GeneralException("File (" + objectInfo + ") is not absolute");
        }/*from   w  ww . j  a v  a  2s . com*/
        FileReader in = new FileReader(file);
        UtilIO.copy(in, true, out);
    } else if (dataResourceTypeId.equals("OFBIZ_FILE") && UtilValidate.isNotEmpty(objectInfo)) {
        String prefix = System.getProperty("ofbiz.home");
        String sep = "";
        if (objectInfo.indexOf("/") != 0 && prefix.lastIndexOf("/") != (prefix.length() - 1)) {
            sep = "/";
        }
        File file = FileUtil.getFile(prefix + sep + objectInfo);
        FileReader in = new FileReader(file);
        UtilIO.copy(in, true, out);
    } else if (dataResourceTypeId.equals("CONTEXT_FILE") && UtilValidate.isNotEmpty(objectInfo)) {
        String prefix = rootDir;
        String sep = "";
        if (objectInfo.indexOf("/") != 0 && prefix.lastIndexOf("/") != (prefix.length() - 1)) {
            sep = "/";
        }
        File file = FileUtil.getFile(prefix + sep + objectInfo);
        FileReader in = null;
        try {
            in = new FileReader(file);
            String enc = in.getEncoding();
            if (Debug.infoOn())
                Debug.logInfo("in serveImage, encoding:" + enc, module);

        } catch (FileNotFoundException e) {
            Debug.logError(e, " in renderDataResourceAsHtml(CONTEXT_FILE), in FNFexception:", module);
            throw new GeneralException("Could not find context file to render", e);
        } catch (Exception e) {
            Debug.logError(" in renderDataResourceAsHtml(CONTEXT_FILE), got exception:" + e.getMessage(),
                    module);
        }
        UtilIO.copy(in, true, out);
    }
}