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.sun.grizzly.http.jk.common.ChannelUn.java

public void init() throws IOException {
    if (file == null) {
        LoggerUtils.getLogger().log(Level.FINEST, "No file, disabling unix channel");
        return;/*w  w w . j av a2 s .c o m*/
        //throw new IOException( "No file for the unix socket channel");
    }
    if (wEnv != null && wEnv.getLocalId() != 0) {
        localId = wEnv.getLocalId();
    }

    if (localId != 0) {
        file = file + localId;
    }
    File socketFile = new File(file);
    if (!socketFile.isAbsolute()) {
        String home = wEnv.getJkHome();
        if (home == null) {
            LoggerUtils.getLogger().log(Level.FINEST, "No jkhome");
        } else {
            File homef = new File(home);
            socketFile = new File(homef, file);
            LoggerUtils.getLogger().log(Level.FINEST, "Making the file absolute " + socketFile);
        }
    }

    if (!socketFile.exists()) {
        try {
            FileOutputStream fos = new FileOutputStream(socketFile);
            fos.write(1);
            fos.close();
        } catch (Throwable t) {
            LoggerUtils.getLogger().log(Level.SEVERE,
                    "Attempting to create the file failed, disabling channel" + socketFile);
            return;
        }
    }
    // The socket file cannot be removed ...
    if (!socketFile.delete()) {
        LoggerUtils.getLogger().log(Level.SEVERE, "Can't remove socket file " + socketFile);
        return;
    }

    super.initNative("channel.un:" + file);

    if (apr == null || !apr.isLoaded()) {
        LoggerUtils.getLogger().log(Level.FINEST, "Apr is not available, disabling unix channel ");
        apr = null;
        return;
    }

    // Set properties and call init.
    setNativeAttribute("file", file);
    // unixListenSocket=apr.unSocketListen( file, 10 );

    setNativeAttribute("listen", "10");
    // setNativeAttribute( "debug", "10" );

    // Initialize the thread pool and execution chain
    if (next == null && wEnv != null) {
        if (nextName != null) {
            setNext(wEnv.getHandler(nextName));
        }
        if (next == null) {
            next = wEnv.getHandler("dispatch");
        }
        if (next == null) {
            next = wEnv.getHandler("request");
        }
    }

    super.initJkComponent();
    JMXRequestNote = wEnv.getNoteId(WorkerEnv.ENDPOINT_NOTE, "requestNote");
    // Run a thread that will accept connections.
    if (this.domain != null) {
        try {
            tpOName = new ObjectName(domain + ":type=ThreadPool,name=" + getChannelName());

            Registry.getRegistry(null, null).registerComponent(tp, tpOName, null);

            rgOName = new ObjectName(domain + ":type=GlobalRequestProcessor,name=" + getChannelName());
            Registry.getRegistry(null, null).registerComponent(global, rgOName, null);
        } catch (Exception e) {
            LoggerUtils.getLogger().log(Level.SEVERE, "Can't register threadpool");
        }
    }
    tp.start();
    AprAcceptor acceptAjp = new AprAcceptor(this);
    tp.runIt(acceptAjp);
    LoggerUtils.getLogger().info("JK: listening on unix socket: " + file);

}

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

/**
 * Add cookie data from a file./*from  w  ww  . ja v  a  2  s  .  co m*/
 */
public void addFile(String cookieFile) throws IOException {
    File file = new File(cookieFile);
    if (!file.isAbsolute()) {
        file = new File(System.getProperty("user.dir") // $NON-NLS-1$
                + File.separator + cookieFile);
    }
    BufferedReader reader = null;
    if (file.canRead()) {
        reader = new BufferedReader(new FileReader(file));
    } else {
        throw new IOException("The file you specified cannot be read.");
    }

    // N.B. this must agree with the save() and cookieToString() methods
    String line;
    try {
        final CollectionProperty cookies = getCookies();
        while ((line = reader.readLine()) != null) {
            try {
                if (line.startsWith("#") || line.trim().length() == 0) {//$NON-NLS-1$
                    continue;
                }
                String[] st = JOrphanUtils.split(line, TAB, false);

                final int _domain = 0;
                //final int _ignored = 1;
                final int _path = 2;
                final int _secure = 3;
                final int _expires = 4;
                final int _name = 5;
                final int _value = 6;
                final int _fields = 7;
                if (st.length != _fields) {
                    throw new IOException(
                            "Expected " + _fields + " fields, found " + st.length + " in " + line);
                }

                if (st[_path].length() == 0) {
                    st[_path] = "/"; //$NON-NLS-1$
                }
                boolean secure = Boolean.valueOf(st[_secure]).booleanValue();
                long expires = new Long(st[_expires]).longValue();
                if (expires == Long.MAX_VALUE) {
                    expires = 0;
                }
                //long max was used to represent a non-expiring cookie, but that caused problems
                Cookie cookie = new Cookie(st[_name], st[_value], st[_domain], st[_path], secure, expires);
                cookies.addItem(cookie);
            } catch (NumberFormatException e) {
                throw new IOException("Error parsing cookie line\n\t'" + line + "'\n\t" + e);
            }
        }
    } finally {
        reader.close();
    }
}

From source file:org.apache.cocoon.transformation.LuceneIndexTransformer.java

private void openWriter() throws IOException {
    File indexDirectory = new File(queryConfiguration.indexDirectory);
    if (!indexDirectory.isAbsolute()) {
        indexDirectory = new File(workDir, queryConfiguration.indexDirectory);
    }/* w  ww . j a  v a2 s  .  co  m*/

    // If the index directory doesn't exist, then always create it.
    boolean indexExists = IndexReader.indexExists(indexDirectory);
    if (!indexExists) {
        createIndex = true;
    }

    // Get the index directory, creating it if necessary
    Directory directory = LuceneCocoonHelper.getDirectory(indexDirectory, createIndex);
    Analyzer analyzer = LuceneCocoonHelper.getAnalyzer(queryConfiguration.analyzerClassname);
    this.writer = new IndexWriter(directory, analyzer, createIndex);
    this.writer.mergeFactor = queryConfiguration.mergeFactor;
}

From source file:au.org.ala.delta.editor.model.EditorDataModel.java

@Override
public String getDataSetPath() {
    File name = new File(getName());
    String dataSetFolder = "";
    if (name.isAbsolute()) {
        dataSetFolder = name.getParent() + File.separator;
    }/*from  w  ww  . j av  a2  s  .  c o  m*/
    return dataSetFolder;
}

From source file:org.deegree.portal.portlet.modules.wfs.actions.portlets.WFSClientPortletPerform_BAK.java

/**
 * transforms the result of a WFS request using the XSLT script defined
 * by an init parameter/*from www  .  j ava2  s. c om*/
 * @param xml
 * @return
 * @throws PortalException
 */
private XMLFragment transform(XMLFragment xml) throws PortalException {
    String xslF = getInitParam(INIT_XSLT);
    File file = new File(xslF);
    if (!file.isAbsolute()) {
        file = new File(sc.getRealPath(xslF));
    }
    XSLTDocument xslt = new XSLTDocument();
    try {
        xslt.load(file.toURL());
        xml = xslt.transform(xml);
    } catch (Exception e) {
        LOG.logError(e.getMessage(), e);
        throw new PortalException("could not transform result of WFS request", e);
    }
    return xml;
}

From source file:it.greenvulcano.util.zip.ZipHelper.java

/**
 * Performs the uncompression of a <code>zip</code> file, whose name and
 * parent directory are passed as arguments, on the local filesystem. The
 * content of the <code>zip</code> file will be uncompressed within a
 * specified target directory.<br>
 *
 * @param srcDirectory// w  w  w  . j  a v a  2  s  .  c  o  m
 *            the source parent directory of the file/s to be unzipped. Must
 *            be an absolute pathname.
 * @param zipFilename
 *            the name of the file to be unzipped. Cannot contain wildcards.
 * @param targetDirectory
 *            the target directory in which the content of the
 *            <code>zip</code> file will be unzipped. Must be an absolute
 *            pathname.
 * @throws IOException
 *             If any error occurs during file uncompression.
 * @throws IllegalArgumentException
 *             if the arguments are invalid.
 */
public void unzipFile(String srcDirectory, String zipFilename, String targetDirectory) throws IOException {

    File srcDir = new File(srcDirectory);

    if (!srcDir.isAbsolute()) {
        throw new IllegalArgumentException(
                "The pathname of the source parent directory is NOT absolute: " + srcDirectory);
    }

    if (!srcDir.exists()) {
        throw new IllegalArgumentException(
                "Source parent directory " + srcDirectory + " NOT found on local filesystem.");
    }

    if (!srcDir.isDirectory()) {
        throw new IllegalArgumentException("Source parent directory " + srcDirectory + " is NOT a directory.");
    }

    File srcZipFile = new File(srcDirectory, zipFilename);
    if (!srcZipFile.exists()) {
        throw new IllegalArgumentException(
                "File to be unzipped (" + srcZipFile.getAbsolutePath() + ") NOT found on local filesystem.");
    }

    ZipFile zipFile = null;
    try {
        zipFile = new ZipFile(srcZipFile);
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry currEntry = entries.nextElement();
            if (currEntry.isDirectory()) {
                String targetSubdirPathname = currEntry.getName();
                File dir = new File(targetDirectory, targetSubdirPathname);
                FileUtils.forceMkdir(dir);
                dir.setLastModified(currEntry.getTime());
            } else {
                InputStream is = null;
                OutputStream os = null;
                File file = null;
                try {
                    is = zipFile.getInputStream(currEntry);
                    FileUtils.forceMkdir(new File(targetDirectory, currEntry.getName()).getParentFile());
                    file = new File(targetDirectory, currEntry.getName());
                    os = new FileOutputStream(file);
                    IOUtils.copy(is, os);
                } finally {
                    try {
                        if (is != null) {
                            is.close();
                        }

                        if (os != null) {
                            os.close();
                        }
                    } catch (IOException exc) {
                        // Do nothing
                    }

                    if (file != null) {
                        file.setLastModified(currEntry.getTime());
                    }
                }
            }
        }
    } finally {
        try {
            if (zipFile != null) {
                zipFile.close();
            }
        } catch (Exception exc) {
            // do nothing
        }
    }
}

From source file:com.theoryinpractise.clojure.AbstractClojureCompilerMojo.java

protected boolean isExistingTestScriptFile(String path) {

    if (!Strings.isNullOrEmpty(path)) {
        File scriptFile = new File(path);
        if (scriptFile.isAbsolute()) {
            return scriptFile.exists();
        } else {//from ww  w . j a v a 2s  .  com
            return new File(baseDirectory, path).exists();
        }
    }

    return false;
}

From source file:catalina.realm.JAASMemoryLoginModule.java

/**
 * Load the contents of our configuration file.
 *///  www . j a v a  2  s .  c  o m
protected void load() {

    // Validate the existence of our configuration file
    File file = new File(pathname);
    if (!file.isAbsolute())
        file = new File(System.getProperty("catalina.base"), pathname);
    if (!file.exists() || !file.canRead()) {
        log("Cannot load configuration file " + file.getAbsolutePath());
        return;
    }

    // Load the contents of our configuration file
    Digester digester = new Digester();
    digester.setValidating(false);
    digester.addRuleSet(new MemoryRuleSet());
    try {
        digester.push(this);
        digester.parse(file);
    } catch (Exception e) {
        log("Error processing configuration file " + file.getAbsolutePath(), e);
        return;
    }

}

From source file:it.geosolutions.geobatch.actions.freemarker.FreeMarkerAction.java

private void initialize() throws IllegalArgumentException, IOException {
    File templateFile = null;
    if (conf.getInput() != null) {
        templateFile = new File(conf.getInput());
        if (!templateFile.isAbsolute()) {
            templateFile = Path.findLocation(templateFile, getConfigDir());
        }//from w  ww . jav  a  2  s  . co  m
    }

    if (templateFile == null)
        throw new IllegalArgumentException("Unable to resolve the template dir" + " (templatePath:"
                + conf.getInput() + " configDir:" + getConfigDir() + ")");

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("FreeMarker template dir is  " + templateFile);
        LOGGER.debug("FreeMarker config dir is    " + getConfigDir());
        LOGGER.debug("FreeMarker conf.getInput is " + conf.getInput());
    }

    processor = new FreeMarkerFilter(templateFile);
    initialized = true;
}