Example usage for java.io File getAbsoluteFile

List of usage examples for java.io File getAbsoluteFile

Introduction

In this page you can find the example usage for java.io File getAbsoluteFile.

Prototype

public File getAbsoluteFile() 

Source Link

Document

Returns the absolute form of this abstract pathname.

Usage

From source file:com.bluexml.side.build.tools.reader.PluginReader.java

public Plugin read(File project) throws Exception {
    logger.debug("Read plugin :" + project.getName());
    // chemin vers le MANIFEST.MF

    File filePluginPath = new File(
            project.getAbsoluteFile() + File.separator + "META-INF" + File.separator + "MANIFEST.MF");

    FileInputStream fileInputStream;
    fileInputStream = new FileInputStream(filePluginPath);
    Manifest m = new Manifest(fileInputStream);

    String id = "";
    String version = "";
    String name = "";
    List<String> requiredBundle = new ArrayList<String>();

    for (Entry<Object, Object> ent : m.getMainAttributes().entrySet()) {
        String key = ent.getKey().toString();
        logger.debug("key :" + key);
        Object value = ent.getValue();
        logger.debug("* value :" + value);
        String string = value.toString();
        if (key.equals("Bundle-Version")) {
            version = string;//w w w  . j a v  a  2  s  . co m
        } else if (key.equals("Bundle-SymbolicName")) {
            if (string.indexOf(";") == -1) {
                id = string;
            } else {
                id = string.substring(0, string.indexOf(";"));
            }
        } else if (key.equals("Bundle-Name")) {
            name = string;
        } else if (key.equals("Require-Bundle")) {
            String[] split = string.split(",");
            CollectionUtils.addAll(requiredBundle, split);

        }
    }

    logger.debug("Plugin ID :" + id);
    if (name.equals("%pluginName")) {
        // must read plugin.properties
        logger.debug("plugin name must be read from properties file");
    } else {
        logger.debug("Plugin Name :" + name);
    }
    logger.debug("Plugin Version :" + version);
    logger.debug("Required Bundles :" + requiredBundle);

    fileInputStream.close();

    Plugin p = new Plugin();
    p.setId(id);
    p.setVersion(version);
    p.setName(name);

    if (registries.pluginsRegister.containsKey(p.getId())) {
        logger.debug("this plugin exist in registry so we stop reading now");
        // stop to prevent loops between PluginReader -> extPReader -> constraints -> plugin
        return registries.pluginsRegister.get(p.getId());
    }

    if (addExtensions) {

        // extension
        // search plugin.xml if any
        File filePluginXMLPath = new File(project, "plugin.xml");

        if (filePluginXMLPath.exists()) {
            logger.debug("extension found :" + filePluginXMLPath);
            BlxExtensionPointReader extR = new BlxExtensionPointReader(registries, props);
            List<LinkedWithModule> lext = extR.read(filePluginXMLPath, p.getId());
            p.setExtensions(lext);
            for (LinkedWithModule extension : lext) {
                Utils.add(registries.tree, p, extension);
            }
        } else {
            logger.debug("Plugin do not have extension :" + filePluginXMLPath);
        }
    }
    if (addRequiredBundle) {
        // add dependencies
        for (String reqIdString : requiredBundle) {
            String reqId = reqIdString;
            String reqVersion = null;
            int indexOfSep = reqIdString.indexOf(";");
            if (indexOfSep != -1) {
                reqId = reqIdString.substring(0, indexOfSep);
                reqVersion = reqIdString.substring(indexOfSep);
            }

            // get the Object
            Plugin reqP = null;
            boolean side = true;

            if (registries.pluginsRegister.containsKey(p.getId())) {
                logger.debug("this plugin exist in registry so we stop reading now");
                reqP = registries.pluginsRegister.get(p.getId());
            } else {
                // need to read from plugin definition if source are available
                logger.debug("requeried Bundle " + reqId + " is not in register, try to read from FS");
                File featureFolder = registries.getProjectFolder(reqId, id);
                if (featureFolder != null) {
                    reqP = read(featureFolder);
                } else {
                    // not found in repository, not SIDE
                    side = false;
                    reqP = new Plugin();
                    reqP.setId(reqId);
                    if (reqVersion != null) {
                        reqP.setVersion(reqVersion);
                    }
                }
            }

            if (side || addAll) {
                registries.pluginsRegister.put(reqId, reqP);
                Utils.add(registries.tree, p, reqP);
                p.getDependecies().add(reqP);
            }
        }
    }
    return p;
}

From source file:com.enjoyxstudy.selenium.htmlsuite.HTMLSuiteLauncher.java

/**
 * Launches a single HTML Selenium test suite.
 *
 * @param browser - the browserString ("*firefox", "*iexplore" or an executable path)
 * @param browserURL - the start URL for the browser
 * @param suiteFile - a file containing the HTML suite to run
 * @param resultFile - The file to which we'll output the HTML results
 * @param timeoutInSeconds - the amount of time (in seconds) to wait for the browser to finish
 * @param multiWindow// w ww.j a  v a 2 s  .  c  om
 * @return result
 * @throws IOException if we can't read the write file
 */
public boolean runHTMLSuiteResult(String browser, String browserURL, File suiteFile, File resultFile,
        long timeoutInSeconds, boolean multiWindow) throws IOException {

    log.info("HTML Suite Start. suite[" + suiteFile + "] browser[" + browser + "]");

    processResults(null); // init result

    if (!suiteFile.isAbsolute()) {
        suiteFile = suiteFile.getAbsoluteFile();
    }

    boolean isResultTemprary = false;
    if (resultFile == null) {
        resultFile = File.createTempFile(TEMP_RESULT_FILE_PREFIX, null);
        isResultTemprary = true;
    }

    String resultString;
    try {
        resultString = runHTMLSuite(browser, browserURL, suiteFile, resultFile, timeoutInSeconds, multiWindow);
    } finally {
        if (isResultTemprary) {
            resultFile.delete();
        }
    }

    boolean result = resultString.equals(RESULT_PASSED);

    String endMessage = "HTML Suite End. result[" + resultString + "] suite[" + suiteFile + "] browser["
            + browser + "]";

    if (result) {
        log.info(endMessage);
    } else {
        log.warn(endMessage);
    }
    return result;
}

From source file:dk.netarkivet.common.distribute.ExtendedFTPRemoteFile.java

@Override
public void copyTo(File destFile) {
    ArgumentNotValid.checkNotNull(destFile, "File destFile");
    destFile = destFile.getAbsoluteFile();
    if ((!destFile.isFile() || !destFile.canWrite())
            && (!destFile.getParentFile().isDirectory() || !destFile.getParentFile().canWrite())) {
        throw new ArgumentNotValid("Destfile '" + destFile + "' does not point to a writable file for "
                + "remote file '" + toString() + "'");
    }//ww w.j  av a 2 s.c  om
    if (log.isDebugEnabled()) {
        log.debug("Writing {} to {}", toString(), destFile.getAbsolutePath());
    }
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(destFile);
        appendTo(fos);
    } catch (Exception e) {
        FileUtils.remove(destFile);
        throw new IOFailure("IO trouble transferring file", e);
    } finally {
        IOUtils.closeQuietly(fos);
    }
}

From source file:org.openscore.lang.tools.verifier.SlangContentVerifier.java

private void validateExecutableName(File slangFile, Executable executable) {
    // Validate executable name is the same as the file name
    String[] splitName = slangFile.getName().split("\\Q.");
    String fileNameNoExtension = splitName[0];
    String executableNameErrorMessage = "Error validating Slang file: \'" + slangFile.getAbsoluteFile()
            + "\'. Name of flow or operation: \'" + executable.getName()
            + "\' is invalid.\nIt should be identical to the file name: \'" + fileNameNoExtension + "\'";
    Validate.isTrue(fileNameNoExtension.equals(executable.getName()), executableNameErrorMessage);
}

From source file:com.webcohesion.enunciate.EnunciateConfiguration.java

public File resolveFile(String filePath) {
    if (File.separatorChar != '/') {
        filePath = filePath.replace('/', File.separatorChar); //normalize on the forward slash...
    }/*from   w w w. j  a v a  2 s .co m*/

    File downloadFile = new File(filePath);

    if (!downloadFile.isAbsolute()) {
        //try to relativize this file to the directory of the config file.
        File base = this.base;
        if (base == null) {
            File configFile = getSource().getFile();
            if (configFile != null) {
                base = configFile.getAbsoluteFile().getParentFile();
            }
        }

        if (base != null) {
            downloadFile = new File(base, filePath);
        }
    }
    return downloadFile;
}

From source file:com.sangupta.httpd.HttpdHandler.java

/**
 * Send directory listing back to client
 * //w w  w  . ja  v  a  2 s . com
 * @param response
 * @param dir
 * @throws IOException
 */
private void showDirectoryListing(HttpServletResponse response, File dir) throws IOException {
    StringBuilder buf = new StringBuilder();
    String dirName = dir.getAbsoluteFile().getName();
    if (AssertUtils.isEmpty(dirName)) {
        dirName = dir.getAbsoluteFile().getParentFile().getName();
    }

    buf.append("<!DOCTYPE html>\r\n");
    buf.append("<html><head><title>");
    buf.append("Listing of: ");
    buf.append(dirName);
    buf.append("</title></head><body>\r\n");

    buf.append("<h3>Listing of: ");
    buf.append(dirName);
    buf.append("</h3>\r\n");

    buf.append("<ul>");
    buf.append("<li><a href=\"../\">..</a></li>\r\n");

    for (File f : dir.listFiles()) {
        if (f.isHidden() || !f.canRead()) {
            continue;
        }

        String name = f.getName();
        if (!ALLOWED_FILE_NAME.matcher(name).matches()) {
            continue;
        }

        buf.append("<li><a href=\"");
        buf.append(name);
        buf.append("\">");
        buf.append(name);
        buf.append("</a></li>\r\n");
    }

    buf.append("</ul></body></html>\r\n");

    byte[] bytes = buf.toString().getBytes(StringUtils.CHARSET_UTF8);

    response.setHeader("Content-Type", "text/html; charset=UTF-8");
    response.setCharacterEncoding("UTF-8");
    response.setContentLength(bytes.length);
    response.getOutputStream().write(bytes);
}

From source file:edu.stolaf.cs.wmrserver.testjob.TestJobTask.java

protected TestJobResult.TransformResult runTransform(long id, File executable, File workingDir,
        InputStream input) throws IOException {
    // Create the result object
    TestJobResult.TransformResult result = new TestJobResult.TransformResult();

    CountingOutputStream output = null;//from   w  ww  .  j a  v a2s .co  m
    CountingOutputStream error = null;
    try {
        // Create and open temporary file for standard output
        File outputFile = File.createTempFile("job-" + Long.toString(_id), "-output", _tempDir);
        output = new CountingOutputStream(new FileOutputStream(outputFile));

        // Create and open temporary file for standard error
        File errorFile = File.createTempFile("job-" + Long.toString(_id), "-error", _tempDir);
        error = new CountingOutputStream(new FileOutputStream(errorFile));

        // If executable is relative, try to resolve in working directory
        // (This emulates the behavior of Streaming)
        if (!executable.isAbsolute()) {
            File resolvedExecutable = new File(workingDir, executable.toString());
            if (resolvedExecutable.isFile()) {
                resolvedExecutable.setExecutable(true);
                executable = resolvedExecutable.getAbsoluteFile();
            }
        }

        // Run the transform

        CommandLine command;
        if (_switchUserCommand == null)
            command = new CommandLine(executable);
        else {
            command = CommandLine.parse(_switchUserCommand);
            HashMap<String, String> substitutionMap = new HashMap<String, String>();
            substitutionMap.put("cmd", executable.toString());
            command.setSubstitutionMap(substitutionMap);
        }

        DefaultExecutor executor = new DefaultExecutor();
        ExecuteWatchdog dog = new ExecuteWatchdog(EXECUTABLE_TIMEOUT);
        PumpStreamHandler pump = new PumpStreamHandler(output, error, input);
        executor.setWorkingDirectory(workingDir);
        executor.setWatchdog(dog);
        executor.setStreamHandler(pump);
        executor.setExitValues(null);

        int exitCode = executor.execute(command);

        result.setExitCode(exitCode);

        // Check whether it produced any output
        if (output.getByteCount() == 0) {
            output.close();
            outputFile.delete();
        } else
            result.setOutputFile(outputFile);

        // Check whether it produced any error output
        if (error.getByteCount() == 0) {
            error.close();
            errorFile.delete();
        } else
            result.setErrorFile(errorFile);
    } finally {
        IOUtils.closeQuietly(output);
        IOUtils.closeQuietly(error);
    }

    return result;
}

From source file:architecture.ee.web.community.profile.DefaultProfileManager.java

protected File getThumbnailFromCacheIfExist(ProfileImage image, int width, int height) throws IOException {
    try {/* w  w  w.  jav a 2s  . com*/
        lock.lock();

        log.debug("thumbnail : " + width + " x " + height);
        File dir = getImageCacheDir();
        File file = new File(dir, toThumbnailFilename(image, width, height));
        File originalFile = getImageFromCacheIfExist(image);
        log.debug("orignal image source: " + originalFile.getAbsoluteFile() + ", " + originalFile.length()
                + " thumbnail:" + file.getAbsoluteFile() + " - " + file.exists());

        if (file.exists()) {
            log.debug(file.length());
            if (file.length() > 0) {
                image.setThumbnailSize((int) file.length());
                return file;
            } else {
            }
        }

        /**
         * TIP : ?  Thumbnail ? ???  ??   ?.
         */
        log.debug("create thumbnail : " + file.getAbsolutePath());
        if (Platform.current() == Platform.WINDOWS) {
            File tmp = getTemeFile();
            Thumbnails.of(originalFile).size(width, height).outputFormat("png")
                    .toOutputStream(new FileOutputStream(tmp));
            image.setThumbnailSize((int) tmp.length());
            FileUtils.copyFile(tmp, file);
        } else {
            try {
                Thumbnails.of(originalFile).allowOverwrite(true).size(width, height).outputFormat("png")
                        .toOutputStream(new FileOutputStream(file));
            } catch (Throwable e) {
                log.error(e);
            }
            image.setThumbnailSize((int) file.length());
        }

        return file;

    } finally {
        lock.unlock();
    }

}

From source file:adams.gui.tools.FileMonitorPanel.java

/**
 * Monitors the specified file./*from  ww  w.j a v a  2 s. c o  m*/
 *
 * @param file    the file to monitor
 */
protected void open(File file) {
    Listener listener;

    stopListening();
    listener = new Listener(this, file.getAbsolutePath());
    m_Tailer = Tailer.create(file.getAbsoluteFile(), listener, 100, true);
    m_RecentFilesHandler.addRecentItem(file);
    setCurrentFile(file);
}

From source file:com.github.thorqin.toolkit.web.utility.UploadManager.java

private String filePathToId(File file) {
    String path = file.getAbsoluteFile().getPath();
    String basePath = new File(uploadDir).getAbsoluteFile().getPath();
    if (!path.startsWith(basePath)) {
        return null;
    }//from   w  ww . ja  va  2  s  .c  o m
    path = path.substring(basePath.length());
    path = path.replaceAll("/|\\\\", "");
    if (path.endsWith(".data")) {
        path = path.substring(0, path.length() - 5);
    }
    return path;
}