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:oz.hadoop.yarn.api.utils.JarUtils.java

/**
 * Will create a JAR file frombase dir//from   ww  w  .j  a va 2 s  .  com
 *
 * @param source
 * @param jarName
 * @return
 */
public static File toJar(File source, String jarName) {
    if (!source.isAbsolute()) {
        throw new IllegalArgumentException("Source must be expressed through absolute path");
    }
    StringAssertUtils.assertNotEmptyAndNoSpacesAndEndsWith(jarName, ".jar");
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
    File jarFile = new File(jarName);
    try {
        JarOutputStream target = new JarOutputStream(new FileOutputStream(jarFile), manifest);
        add(source, source.getAbsolutePath().length(), target);
        target.close();
    } catch (Exception e) {
        throw new IllegalStateException(
                "Failed to create JAR file '" + jarName + "' from " + source.getAbsolutePath(), e);
    }
    return jarFile;
}

From source file:org.artifactory.storage.db.binstore.service.FileBinaryProviderBase.java

protected static File getDataFolder(File rootDataDir, StorageProperties storageProperties,
        StorageProperties.Key keyProperty, String defaultName) {
    String name = storageProperties.getProperty(keyProperty);
    if (StringUtils.isBlank(name)) {
        return new File(rootDataDir, defaultName);
    }//from  w  ww.  java  2s .co  m
    File currentFile = new File(name);
    if (currentFile.isAbsolute()) {
        return currentFile;
    }
    return new File(rootDataDir, name);
}

From source file:com.mentor.questa.jenkins.Util.java

/**
 * This method returns the possibly trimmed contents of the file. The file
 * can be relative to a workspace.//ww  w  . j a v a 2  s  . co  m
 *
 * @param keepLongStdio
 * @param workspace
 * @param filename
 * @return
 * @throws IOException
 */
public static String possiblyTrimStdio(boolean keepLongStdio, File workspace, String filename)
        throws IOException {
    File file = new File(filename);

    if (!file.isAbsolute()) {

        // A temporary workaround for VRM logfile bug
        String[] temp = filename.split(" ");

        FileSet fs = hudson.Util.createFileSet(workspace, temp[0]);
        DirectoryScanner ds = fs.getDirectoryScanner();

        String[] files = ds.getIncludedFiles();
        File baseDir = ds.getBasedir();
        // Ignore empty things for now... 
        if (files.length == 0) {
            return "";
        }

        file = new File(baseDir, files[0]);
    }

    return possiblyTrimStdio(keepLongStdio, file);
}

From source file:com.mgmtp.perfload.perfalyzer.util.PerfAlyzerFile.java

public static PerfAlyzerFile create(final File file) {
    checkState(!file.isAbsolute(), "File must not be absolute: %s", file);

    String fileName = file.getName();

    List<String> parts = newArrayListWithExpectedSize(3);
    List<String> partsWithBrackets = newArrayListWithExpectedSize(3);

    Matcher m = PATTERN_FILE_NAME_PARTS.matcher(fileName);
    while (m.find()) {
        partsWithBrackets.add(m.group());
        parts.add(m.group(1));/*from   w w w .j av a 2s  . com*/
    }
    m = PATTERN_MARKER.matcher(fileName);
    String marker = m.find() ? m.group(1) : null;

    return new PerfAlyzerFile(FilenameUtils.getPath(file.getPath()), getExtension(fileName), parts, marker);
}

From source file:com.c4om.autoconf.ulysses.configanalyzer.packager.CompressedFileConfigurationPackager.java

/**
 * This method returns a list of subpaths to all the files of a given directory (and its subdirectories).
 * If a file is provided, it returns a singleton list with the path to the file.
 * @param file the directory or file/*from   www .j  av a2 s . c  om*/
 * @return the list of subpaths
 */
protected static List<String> getSubPathsRecursive(File file, File baseFile) {
    if (!(file.isAbsolute())) {
        throw new IllegalArgumentException(
                "The provided File object must be absolute. The provided one +(" + file + ") is not.");
    }
    if (file.isDirectory()) {
        Collection<File> files = FileUtils.listFiles(file, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
        List<String> result = new ArrayList<>();
        for (File currentFile : files) {
            result.add(relativizeFile(currentFile, baseFile).getPath());
        }
        return result;
    } else {
        return Collections.singletonList(relativizeFile(file, baseFile).getPath());
    }
}

From source file:nl.opengeogroep.filesetsync.client.config.SyncConfig.java

public static void load(String basePath, String filename) throws JAXBException, IOException {
    InputStream in = new FileInputStream(filename);
    JAXBContext jaxb = JAXBContext.newInstance(SyncConfig.class);
    Unmarshaller um = jaxb.createUnmarshaller();
    try {/*from   w w w .j  a v  a 2 s.  com*/
        instance = (SyncConfig) um.unmarshal(in);
    } finally {
        in.close();
    }

    File f = new File(instance.varDir);
    if (!f.isAbsolute()) {
        instance.varDir = basePath + File.separator + instance.varDir;
    }
}

From source file:com.parasoft.xtest.reports.jenkins.util.FilePathUtil.java

/**
 * @param file// w  ww  .  j  ava  2 s.c  o m
 * @return true if file behind given object is absolute
 */
public static boolean isAbsolute(FilePath file) {
    boolean result = false;
    try {
        result = file.act(new FileCallable<Boolean>() {
            private static final long serialVersionUID = 1L;

            public Boolean invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
                return f.isAbsolute();
            }

            @Override
            public void checkRoles(RoleChecker arg0) throws SecurityException {
                // TODO Auto-generated method stub

            }
        });
    } catch (IOException e) {
        Logger.getLogger().errorTrace(e);
    } catch (InterruptedException e) {
        Logger.getLogger().errorTrace(e);
    }
    return result;
}

From source file:nl.armatiek.xslweb.utils.XSLWebUtils.java

public static File getSafeTempFile(String path) {
    if (StringUtils.isBlank(path)) {
        return null;
    }//from   ww  w . jav  a2 s  . co  m
    File file = new File(path);
    if (!file.isAbsolute()) {
        return null;
    }
    if (file.toPath().getNameCount() == 0) {
        return null;
    }
    return new File(path);
}

From source file:com.sonarsource.lits.IssuesChecker.java

private static File getFile(Settings settings, String property) {
    String path = settings.getString(property);
    if (path == null) {
        throw MessageException.of("Missing property '" + property + "'");
    }/*from w ww .j a  va  2 s  . co  m*/
    File file = new File(path);
    if (!file.isAbsolute()) {
        throw MessageException.of("Path must be absolute - check property '" + property + "'");
    }
    return file;
}

From source file:nl.b3p.catalog.filetree.FileListHelper.java

public static File getFileForPath(Root r, String path) throws FileNotFoundException {
    FileRoot root = (FileRoot) r;/*  w ww .ja  va  2 s  . co m*/
    path = Root.getPathPart(path);
    if (path.indexOf("..") != -1) {
        throw new IllegalArgumentException("Illegal path");
    }
    String osPath = path.replace(Root.SEPARATOR.charAt(0), File.separatorChar);

    File p = new File(osPath);
    if (p.isAbsolute()) {
        throw new IllegalArgumentException("Illegal path");
    }

    File f = new File(root.getPath(), osPath);

    //TODO CvL: file does not need to exists? use empty md then
    //        if(!FGDBHelperProxy.isFGDBDirOrInsideFGDBDir(f) && !f.exists()) {
    //            throw new FileNotFoundException("Path does not exist");
    //        }
    return f;
}