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.espertech.esperio.db.EsperIODBAdapterPlugin.java

private URL resolveURL(String config) throws Exception {
    URL url = this.getClass().getClassLoader().getResource(config);
    if (url != null) {
        return url;
    }/* w  ww.j  a  v a 2 s  . co  m*/

    url = Thread.currentThread().getContextClassLoader().getResource(config);
    if (url != null) {
        return url;
    }

    File file = new File(config);
    if (!file.isAbsolute()) {
        String espereeBase = System.getProperty("esperee.base");
        file = new File(espereeBase, config);
    }
    if (file.exists()) {
        return file.toURI().toURL();
    }

    return new URL(config);
}

From source file:org.dita.dost.ant.types.JobMapper.java

public void setProject(Project project) {
    File tempDir = new File(project.getProperty(ANT_TEMP_DIR));
    if (!tempDir.isAbsolute()) {
        tempDir = new File(project.getBaseDir(), tempDir.getPath());
    }//  w ww.  ja  v a2s  .c o  m
    job = ExtensibleAntInvoker.getJob(tempDir, project);
}

From source file:org.datacleaner.util.FileResolver.java

public File toFile(String filename) {
    if (filename == null) {
        return null;
    }//from  w w  w  .j  av a 2  s  .  c  o m

    final File file;
    final File nonParentCandidate = new File(filename);
    if (nonParentCandidate.isAbsolute()) {
        file = nonParentCandidate;
    } else {
        if (_baseDir == null || ".".equals(_baseDir.getPath())) {
            file = nonParentCandidate;
        } else {
            file = new File(_baseDir, filename);
        }
    }
    return file;
}

From source file:com.pablissimo.sonar.TsCoverageSensorImpl.java

public File getIOFile(File baseDir, String path) {
    File file = new File(path);
    if (!file.isAbsolute()) {
        file = new File(baseDir, path);
    }//from   www.j a  va 2  s  . c o m

    return file;
}

From source file:org.alfresco.util.OpenOfficeVariant.java

public File findExecutable(String executableName) {
    File file = new File(executableName);
    if (file.isAbsolute()) {
        file = canExecute(file);// ww w .  j  a v a2 s .  co  m
    } else {
        file = findExecutableOnPath(executableName);
    }
    return file;
}

From source file:info.varden.irclinqed.dcc.FileReceiveThread.java

public FileReceiveThread(DCCRequestPacket packet) {
    this.packet = packet;
    this.host = packet.getIPAddress();
    this.port = packet.getPort();
    String dccParts[] = packet.getMessage().replace("\u0001", "").split(" ");
    File f = new File(packet.getArg());
    if (f.isAbsolute()) {
        this.file = f;
    } else {//w  ww .  j  ava2s  . c  om
        this.file = new File(new File(Minecraft.getMinecraft().mcDataDir, "dccfiles"), packet.getArg());
    }
    this.filesize = Long.parseLong(dccParts[5 + packet.getArg().split(" ").length - 1]);
    this.thread = packet.thread;
    this.il = packet.il;
}

From source file:it.geosolutions.geobatch.imagemosaic.ImageMosaicUpdater.java

/**
 * Try to update the datastore using the passed command and the
 * mosaicDescriptor as data and/*from   w w w.j a  v  a 2 s  . co  m*/
 * 
 * @param mosaicProp
 * @param dataStoreProp
 * @param mosaicDescriptor
 * @param cmd
 * @return boolean representing the operation success (true) or failure
 *         (false)
 * @throws IOException 
 * @throws ClassNotFoundException 
 * @throws IllegalAccessException 
 * @throws InstantiationException 
 * @throws IllegalArgumentException 
 */
protected static boolean updateDataStore(Properties mosaicProp, Properties dataStoreProp,
        ImageMosaicGranulesDescriptor mosaicDescriptor, ImageMosaicCommand cmd) throws IOException {

    if (mosaicProp == null) {
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error("Unable to get mosaic properties.");
        }
        return false;
    }

    DataStore dataStore = null;
    try {
        // create the datastore
        dataStore = getDataStore(dataStoreProp);

        boolean absolute = isTrue(mosaicProp.get(org.geotools.gce.imagemosaic.Utils.Prop.ABSOLUTE_PATH));
        // does the layer use absolute path?
        if (!absolute) {
            /*
             * if we have some absolute path into delFile list we have to
             * skip those files since the layer is relative and acceptable
             * (to deletion) passed path are to be relative
             */
            List<File> files = null;
            if ((files = cmd.getDelFiles()) != null) {
                for (File file : files) {
                    if (file.isAbsolute()) {
                        /*
                         * this file can still be acceptable since it can be
                         * child of the layer baseDir
                         */
                        final String path = file.getAbsolutePath();
                        if (!path.contains(cmd.getBaseDir().getAbsolutePath())) {
                            // the path is absolute AND the file is outside
                            // the layer baseDir!
                            // files.remove(file); // remove it
                            // TODO move into a recoverable path to
                            // rollback!
                            // log as warning
                            if (LOGGER.isWarnEnabled()) {
                                LOGGER.warn("Layer specify a relative pattern for files but the "
                                        + "incoming xml command file has an absolute AND outside the layer baseDir file into the "
                                        + "delFile list! This file will NOT be removed from the layer: "
                                        + file.getAbsolutePath());
                            }
                        }
                    }
                }
            }
        }

        // TODO check object cast
        // the attribute key location
        final String locationKey = (String) mosaicProp
                .get(org.geotools.gce.imagemosaic.Utils.Prop.LOCATION_ATTRIBUTE);
        final String store = mosaicDescriptor.getCoverageStoreId();

        final List<File> delList = cmd.getDelFiles();
        Filter delFilter = null;
        // query
        if (!CollectionUtils.isEmpty(delList)) {
            try {
                delFilter = getQuery(delList, absolute, locationKey);
            } catch (Exception e) {
                if (LOGGER.isErrorEnabled()) {
                    LOGGER.error("Unable to build a query. Message: " + e, e);
                }
                return false;
            }

            // REMOVE features
            if (!removeFeatures(dataStore, store, delFilter)) {
                if (LOGGER.isWarnEnabled()) {
                    LOGGER.warn("Failed to remove features.");
                }
            } else {

                //
                // should we remove the files for good? #81
                // do we want to back them up? #84
                //
                final File backUpDirectory = cmd.getBackupDirectory();
                if (cmd.isDeleteGranules()) {
                    boolean delete = true;
                    if (backUpDirectory != null) {
                        //if we don't manage to move, we try to cancel
                        delete = (!backUpGranulesFiles(cmd.getDelFiles(), backUpDirectory));
                    }

                    // delete 
                    if (delete) {
                        deleteGranulesFiles(cmd.getDelFiles());
                    }
                }
            }
        } else {
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("No items to delete");
            }
        }

        //========================================
        // Handle the addFiles list
        //========================================

        // if it's empty, we'll return anyway. The config is telling us if it's a problem or not.
        // Notice that a un/marshalled empty list willb e probabily set to null
        if (CollectionUtils.isEmpty(cmd.getAddFiles())) {
            if (cmd.isIgnoreEmptyAddList()) {
                if (LOGGER.isInfoEnabled()) {
                    LOGGER.info("No items to add");
                }
                return true;
            } else {
                if (LOGGER.isErrorEnabled()) {
                    LOGGER.error("addFiles list is empty.");
                }
                return false;
            }
        }

        // Remove from addList the granules already in the mosaic.
        // TODO remove (ALERT please remove existing file from destination
        // for the copyListFileToNFS()
        if (!purgeAddFileList(cmd.getAddFiles(), dataStore, store, locationKey, cmd.getBaseDir(), absolute)) {
            return false;
        }

        // //////////////////////////////////
        if (cmd.getAddFiles() == null) { // side effect in previous method call? should not happen.
            if (LOGGER.isErrorEnabled()) {
                LOGGER.error("Filtered addFiles list is null.");
            }
            return false;
        } else if (cmd.getAddFiles().isEmpty()) {
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("All requested files are already in the mosaic.");
            }
            return true;
        } else if (cmd.getAddFiles().size() > 0) {
            /*
             * copy purged addFiles list of files to the baseDir and replace
             * addFiles list with the new copied file list
             */
            // store copied file for rollback purpose
            List<File> addedFile = null;
            if (!absolute) {
                if (LOGGER.isInfoEnabled()) {
                    LOGGER.info("Starting file copy (" + cmd.getAddFiles().size() + " file/s)");
                }
                addedFile = Copy.copyListFileToNFS(cmd.getAddFiles(), cmd.getBaseDir(), false,
                        cmd.getNFSCopyWait());
            }
            if (!addFileToStore(addedFile, dataStore, store, locationKey, cmd.getBaseDir())) {
                if (LOGGER.isErrorEnabled())
                    LOGGER.error("Unable to update the new layer, removing copied files...");
                // if fails rollback the copied files
                if (addedFile != null) {
                    for (File file : addedFile) {
                        if (LOGGER.isWarnEnabled())
                            LOGGER.warn("ImageMosaicAction: DELETING -> " + file.getAbsolutePath());
                        // this is done since addedFiles are copied not moved
                        file.delete();
                    }
                }
            }
        } // addFiles size > 0

    } catch (Exception e) {

        if (LOGGER.isErrorEnabled()) {
            LOGGER.error(e.getLocalizedMessage(), e);
        }

        return false;

    } finally {
        if (dataStore != null) {
            try {
                dataStore.dispose();
            } catch (Throwable t) {
                if (LOGGER.isWarnEnabled()) {
                    LOGGER.warn(t.getLocalizedMessage(), t);
                }
            }
        }
    }
    return true;
}

From source file:com.teotigraphix.caustk.sequencer.SongManager.java

public File toSongFile(File file) {
    if (file.isAbsolute())
        return file;
    return new File(songDirectory, file.getPath());
}

From source file:org.cloudifysource.usm.liveness.FileLivenessDetector.java

/**
 * isProcessAlive will sample the file defined in the groovy configuration file every second for the specified
 * timeout period looking for a regex in the log that confirms the process has loaded successfully and return true
 * if the regex was found./*  w ww. j  a  va 2  s.c  o m*/
 * 
 * @throws USMException .
 * 
 */
@Override
public boolean isProcessAlive() throws USMException {
    if (this.regex.isEmpty() || this.filePath.isEmpty()) {
        throw new USMException(
                "When using the FileLivnessDetector, both the file path and regex should be defined.");
    }
    File file = new File(this.filePath);
    if (!file.isAbsolute()) {
        file = new File(serviceDirectory, this.filePath);
    }
    final FileTailerListener listener = new FileTailerListener(this.regex);
    Tailer tailer = null;
    try {
        final long startTime = System.currentTimeMillis();
        while (System.currentTimeMillis() < startTime + TimeUnit.SECONDS.toMillis(timeoutInSeconds)) {
            if (file.exists()) {
                if (tailer == null) {
                    tailer = Tailer.create(file, listener, TIMEOUT_BETWEEN_FILE_QUERYING, false);
                }
                if (listener.isProcessUp()) {
                    logger.info("The regular expression " + this.regex + " was found in the process log");
                    return true;
                }
            }
            try {
                Thread.sleep(TIMEOUT_BETWEEN_FILE_QUERYING);
            } catch (final InterruptedException e) {
                e.printStackTrace();
            }
        }
    } finally {
        if (tailer != null) {
            tailer.stop();
        }
    }
    logger.info("The regular expression " + this.regex + " was NOT found in the process log");
    return false;

}

From source file:org.ebayopensource.turmeric.plugins.maven.stubs.SelfProjectStub.java

@SuppressWarnings("unchecked")
public SelfProjectStub() {
    File pom = new File(getBasedir(), "pom.xml");
    MavenXpp3Reader pomReader = new MavenXpp3Reader();
    Model model = null;/*  w w w .  j a  v a2 s .  c o  m*/

    try {
        model = pomReader.read(new FileReader(pom));
        setModel(model);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    setGroupId(model.getGroupId());
    setArtifactId(model.getArtifactId());
    setVersion(model.getVersion());
    setName(model.getName());
    setUrl(model.getUrl());
    setPackaging(model.getPackaging());
    setFile(pom);

    if (model.getDependencies() != null) {
        dependencies.addAll(model.getDependencies());
    }

    if (model.getBuild() != null) {
        setBuild(model.getBuild());
    } else {
        setBuild(new Build());
    }

    File srcDir = new File(getBasedir(), toOS("src/main/java"));
    getBuild().setSourceDirectory(srcDir.getAbsolutePath());

    File targetDir = new File(getBasedir(), "target");
    getBuild().setDirectory(targetDir.getAbsolutePath());

    File outputDir = new File(targetDir, "classes");
    getBuild().setOutputDirectory(outputDir.getAbsolutePath());

    List<Resource> resources = new ArrayList<Resource>();
    resources.addAll(getBuild().getResources());

    // Only add resource dir if none are defined.
    if (resources.isEmpty()) {
        resources = new ArrayList<Resource>();
        Resource resource = new Resource();
        File resourceDir = new File(getBasedir(), toOS("src/main/resources"));
        resource.setDirectory(resourceDir.getAbsolutePath());
        resources.add(resource);
    } else {
        // Fix any relative resource paths.
        for (Resource resource : resources) {
            String resDir = toOS(resource.getDirectory());
            File dir = new File(resDir);
            if (!dir.isAbsolute()) {
                dir = new File(getBasedir(), resDir);
                resource.setDirectory(dir.getAbsolutePath());
            }
        }
    }
    getBuild().setResources(resources);
}