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:com.boundlessgeo.geoserver.api.controllers.IO.java

private static String source(File file, GeoServerDataDirectory dataDir) {
    File baseDirectory = dataDir.getResourceLoader().getBaseDirectory();
    return file.isAbsolute() ? file.toString() : Paths.convert(baseDirectory, file);
}

From source file:nl.b3p.catalog.config.CatalogAppConfig.java

public void contextInitialized(ServletContextEvent sce) {

    String configParam = sce.getServletContext().getInitParameter("config");

    if (configParam == null) {
        throw new IllegalArgumentException("No config file specified in \"config\" context init parameter");
    }/*from  w w w  .  j  a  va 2s. c  om*/

    File f = new File(configParam);
    if (!f.isAbsolute()) {
        String catalinaBase = System.getProperty("catalina.base");
        if (catalinaBase != null) {
            f = new File(catalinaBase, configParam);
        } else {
            // just use current directory whatever that may be
        }
    }
    String canonicalPath = null;
    try {
        canonicalPath = f.getCanonicalPath();
    } catch (IOException e) {
        canonicalPath = "[IOException: " + e.getMessage() + "]";
    }
    log.info("Loading configuration from file " + canonicalPath);

    if (!f.exists() || !f.canRead()) {
        throw new IllegalArgumentException(String.format(
                "Config file specified in \"config\" context init parameter with value \"%s\" (canonical path \"%s\") does not exist or cannot be read",
                configParam, canonicalPath));
    }

    try {
        config = loadFromFile(f);
        log.debug("Configuration loaded; marshalling for log");

        JAXBContext ctx = JAXBContext.newInstance(CatalogAppConfig.class);
        Marshaller m = ctx.createMarshaller();
        m.setProperty("jaxb.formatted.output", Boolean.TRUE);

        StringWriter sw = new StringWriter();
        m.marshal(config, sw);
        log.info("Parsed configuration: \n" + sw.toString());

        if (!CURRENT_VERSION.equals(config.getVersion())) {
            throw new Exception(String.format("Wrong configuration file version: %s, must be %s",
                    config.getVersion(), CURRENT_VERSION));
        }
    } catch (Exception e) {
        log.error("Error loading configuration", e);
        throw new IllegalArgumentException("Error loading configuration from file \"" + canonicalPath + '"', e);
    }

    if (log.isDebugEnabled()) {
        for (Root r : config.getRoots()) {
            log.debug(String.format("Role access list for root %s: %s", r.getName(),
                    r.getRoleAccessList().toString()));
        }
    }
}

From source file:org.apache.jmeter.protocol.http.control.HeaderManager.java

/**
 * Save the header data to a file.//from  w ww .  j a  v a  2 s  .c om
 *
 * @param headFile
 *            name of the file to store headers into. If name is relative
 *            the system property <code>user.dir</code> will be prepended
 * @throws IOException
 *             if writing the headers fails
 */
public void save(String headFile) throws IOException {
    File file = new File(headFile);
    if (!file.isAbsolute()) {
        file = new File(System.getProperty("user.dir")// $NON-NLS-1$
                + File.separator + headFile);
    }
    PrintWriter writer = new PrintWriter(new FileWriter(file)); // TODO Charset ?
    writer.println("# JMeter generated Header file");// $NON-NLS-1$
    final CollectionProperty hdrs = getHeaders();
    for (int i = 0; i < hdrs.size(); i++) {
        final JMeterProperty hdr = hdrs.get(i);
        Header head = (Header) hdr.getObjectValue();
        writer.println(head.toString());
    }
    writer.flush();
    writer.close();
}

From source file:com.npower.unicom.sync.AbstractExportDaemonPlugIn.java

/**
 * @param dir/* w w w. j a v a 2 s  .c  o m*/
 * @return
 */
private File getRequestDir() {
    File dir = new File(this.getDirectory());
    if (!dir.isAbsolute()) {
        dir = new File(System.getProperty("otas.dm.home"), this.getDirectory());
    }
    File requestDir = new File(dir, "request");
    if (!requestDir.exists()) {
        log.info("create directory: " + requestDir.getAbsolutePath());
        requestDir.mkdirs();
    }
    return requestDir;
}

From source file:de.jflex.plugin.maven.JFlexMojo.java

/**
 * Converts the specified path argument into an absolute path. If the path
 * is relative like "src/main/jflex", it is resolved against the base
 * directory of the project (in constrast, File.getAbsoluteFile() would
 * resolve against the current directory which may be different, especially
 * during a reactor build)./* www.  ja  v  a  2s .co m*/
 * 
 * @param path
 *            The path argument to convert, may be {@code null}.
 * @return The absolute path corresponding to the input argument.
 */
protected File getAbsolutePath(File path) {
    if (path == null || path.isAbsolute()) {
        return path;
    }
    return new File(this.project.getBasedir().getAbsolutePath(), path.getPath());
}

From source file:dtool.engine.modules.BundleModulesVisitor.java

protected void visitPotentialModuleFile(File potentialFile, File importFolder) {
    String relPath = importFolder.toURI().relativize(potentialFile.toURI()).getPath();
    ModuleFullName moduleFullName = ModuleNamingRules.getValidModuleNameOrNull(relPath);
    if (moduleFullName != null) {
        assertTrue(potentialFile.isAbsolute());
        addModuleEntry(moduleFullName, potentialFile);
    }/* w w  w .  j a  v a  2s. c o  m*/
}

From source file:org.freeplane.main.application.UserPropertiesUpdater.java

void importOldDefaultStyle() {
    final ModeController modeController = Controller.getCurrentController()
            .getModeController(MModeController.MODENAME);
    MFileManager fm = MFileManager.getController(modeController);
    final String standardTemplateName = fm.getStandardTemplateName();
    final File userDefault;
    final File absolute = new File(standardTemplateName);
    if (absolute.isAbsolute())
        userDefault = absolute;/*from  w w w.  ja  v  a2s .c o  m*/
    else {
        final File userTemplates = fm.defaultUserTemplateDir();
        userDefault = new File(userTemplates, standardTemplateName);
    }
    if (userDefault.exists()) {
        return;
    }
    userDefault.getParentFile().mkdirs();
    if (!userDefault.getParentFile().exists()) {
        return;
    }
    MapModel defaultStyleMap = new MapModel();
    final File allUserTemplates = fm.defaultStandardTemplateDir();
    final File standardTemplate = new File(allUserTemplates, "standard.mm");
    try {
        fm.loadCatchExceptions(standardTemplate.toURL(), defaultStyleMap);
    } catch (Exception e) {
        LogUtils.warn(e);
        try {
            fm.loadCatchExceptions(
                    ResourceController.getResourceController().getResource("/styles/viewer_standard.mm"),
                    defaultStyleMap);
        } catch (Exception e2) {
            defaultStyleMap.createNewRoot();
            LogUtils.severe(e);
        }
    }
    final NodeStyleController nodeStyleController = NodeStyleController.getController(modeController);
    updateDefaultStyle(nodeStyleController, defaultStyleMap);
    updateNoteStyle(nodeStyleController, defaultStyleMap);

    try {
        fm.writeToFile(defaultStyleMap, userDefault);
    } catch (IOException e) {
    }

}

From source file:org.apache.jmeter.protocol.http.control.AuthManager.java

/**
 * Add authentication data from a file.//from ww  w. j a  va2s .c  o m
 */
public void addFile(String authFile) throws IOException {
    File file = new File(authFile);
    if (!file.isAbsolute()) {
        file = new File(System.getProperty("user.dir") + File.separator + authFile);
    }
    if (!file.canRead()) {
        throw new IOException("The file you specified cannot be read.");
    }

    BufferedReader reader = null;
    boolean ok = true;
    try {
        reader = new BufferedReader(new FileReader(file));
        String line;
        while ((line = reader.readLine()) != null) {
            try {
                if (line.startsWith("#") || JOrphanUtils.isBlank(line)) { //$NON-NLS-1$
                    continue;
                }
                StringTokenizer st = new StringTokenizer(line, "\t"); //$NON-NLS-1$
                String url = st.nextToken();
                String user = st.nextToken();
                String pass = st.nextToken();
                String domain = "";
                String realm = "";
                if (st.hasMoreTokens()) {// Allow for old format file without the extra columnns
                    domain = st.nextToken();
                    realm = st.nextToken();
                }
                Authorization auth = new Authorization(url, user, pass, domain, realm);
                getAuthObjects().addItem(auth);
            } catch (NoSuchElementException e) {
                log.error("Error parsing auth line: '" + line + "'");
                ok = false;
            }
        }
    } finally {
        IOUtils.closeQuietly(reader);
    }
    if (!ok) {
        JMeterUtils.reportErrorToUser("One or more errors found when reading the Auth file - see the log file");
    }
}

From source file:org.apache.solr.core.ConfigSolrXmlOld.java

private void initCoreList() throws IOException {

    coreNodes = (NodeList) config.evaluate("solr/cores/core", XPathConstants.NODESET);
    // Check a couple of error conditions
    Set<String> names = new HashSet<>(); // for duplicate names
    Map<String, String> dirs = new HashMap<>(); // for duplicate
                                                // data dirs.

    for (int idx = 0; idx < coreNodes.getLength(); ++idx) {
        Node node = coreNodes.item(idx);
        String name = DOMUtil.getAttr(node, CoreDescriptor.CORE_NAME, null);

        String dataDir = DOMUtil.getAttr(node, CoreDescriptor.CORE_DATADIR, null);
        if (name != null) {
            if (!names.contains(name)) {
                names.add(name);//from w  ww.  j  ava  2s. c om
            } else {
                String msg = String.format(Locale.ROOT, "More than one core defined for core named %s", name);
                log.error(msg);
            }
        }

        String instDir = DOMUtil.getAttr(node, CoreDescriptor.CORE_INSTDIR, null);

        if (dataDir != null) {
            String absData = null;
            File dataFile = new File(dataDir);
            if (dataFile.isAbsolute()) {
                absData = dataFile.getCanonicalPath();
            } else if (instDir != null) {
                File instFile = new File(instDir);
                absData = new File(instFile, dataDir).getCanonicalPath();
            }
            if (absData != null) {
                if (!dirs.containsKey(absData)) {
                    dirs.put(absData, name);
                } else {
                    String msg = String.format(Locale.ROOT,
                            "More than one core points to data dir %s. They are in %s and %s", absData,
                            dirs.get(absData), name);
                    log.warn(msg);
                }
            }
        }
    }

}

From source file:org.apache.jmeter.protocol.http.control.HeaderManager.java

/**
 * Add header data from a file./*from  w w w  .j av  a 2 s  .c o m*/
 *
 * @param headerFile
 *            name of the file to read headers from. If name is relative the
 *            system property <code>user.dir</code> will be prepended
 * @throws IOException
 *             if reading headers fails
 */
public void addFile(String headerFile) throws IOException {
    File file = new File(headerFile);
    if (!file.isAbsolute()) {
        file = new File(System.getProperty("user.dir")// $NON-NLS-1$
                + File.separator + headerFile);
    }
    if (!file.canRead()) {
        throw new IOException("The file you specified cannot be read.");
    }

    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new FileReader(file)); // TODO Charset ?
        String line;
        while ((line = reader.readLine()) != null) {
            try {
                if (line.startsWith("#") || JOrphanUtils.isBlank(line)) {// $NON-NLS-1$
                    continue;
                }
                String[] st = JOrphanUtils.split(line, "\t", " ");// $NON-NLS-1$ $NON-NLS-2$
                int name = 0;
                int value = 1;
                Header header = new Header(st[name], st[value]);
                getHeaders().addItem(header);
            } catch (Exception e) {
                throw new IOException("Error parsing header line\n\t'" + line + "'\n\t" + e);
            }
        }
    } finally {
        IOUtils.closeQuietly(reader);
    }
}