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.polyvi.xface.extension.capture.MediaType.java

/**
 *  Audio  Video .//ww  w. ja va2s .c o m
 *
 * @param mediaFileUri  media  Uri
 * @return JSONObject    image  JSONObject
 */
private JSONObject createAudioVideoFile(Uri mediaFileUri) {
    XPathResolver pathResolver = new XPathResolver(mediaFileUri.toString(), null, getContext());
    String mediaStorePath = pathResolver.resolve();
    File fp = new File(mediaStorePath);
    JSONObject obj = computeFileProp(fp);

    try {
        // ".3gp"  ".3gpp" ??? type
        // getMimeType?
        if (fp.getAbsoluteFile().toString().endsWith(".3gp")
                || fp.getAbsoluteFile().toString().endsWith(".3gpp")) {
            if (mediaFileUri.toString().contains("/audio/")) {
                obj.put(PROP_TYPE, AUDIO_3GPP);
            } else {
                obj.put(PROP_TYPE, VIDEO_3GPP);
            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return obj;
}

From source file:dk.netarkivet.common.utils.FileUtils.java

/**
 * @param theFile// www  .j a v  a 2s .  co  m
 *            A file to make relative
 * @param theDir
 *            A directory
 * @return the filepath of the theFile relative to theDir. null, if
 *         theFile is not relative to theDir. null, if theDir is not a
 *         directory.
 */
public static String relativeTo(File theFile, File theDir) {
    ArgumentNotValid.checkNotNull(theFile, "File theFile");
    ArgumentNotValid.checkNotNull(theDir, "File theDir");
    if (!theDir.isDirectory()) {
        log.trace("The File '" + theDir.getAbsolutePath() + "' does not represent a directory. Null returned");
        return null;
    }

    List<String> filePathList = new ArrayList<String>();
    List<String> theDirPath = new ArrayList<String>();
    File tempFile = theFile.getAbsoluteFile();

    filePathList.add(tempFile.getName());
    while ((tempFile = tempFile.getParentFile()) != null) {
        filePathList.add(tempFile.getName());
    }

    tempFile = theDir.getAbsoluteFile();
    theDirPath.add(tempFile.getName());
    while ((tempFile = tempFile.getParentFile()) != null) {
        theDirPath.add(tempFile.getName());
    }

    // check, at the path prefix is the same
    List<String> sublist = filePathList.subList(theDirPath.size() - 2, filePathList.size());
    if (!theDirPath.equals(sublist)) {
        log.trace("The file '" + theFile.getAbsolutePath() + "' is not relative to the directory '"
                + theDir.getAbsolutePath() + "'. Null returned");
        return null;
    }

    List<String> relativeList = filePathList.subList(0, theDirPath.size() - 2);

    StringBuffer sb = new StringBuffer();
    Collections.reverse(relativeList);
    for (String aRelativeList : relativeList) {
        sb.append(aRelativeList);
        sb.append(File.separatorChar);
    }
    sb.deleteCharAt(sb.length() - 1); // remove last separatorChar
    return sb.toString();

}

From source file:ch.unibas.fittingwizard.application.tools.FitOutputParser.java

public double parseRmseValue(File outputFile) {
    List<String> lines;
    try {//from  w  w  w. j av a  2  s  .  c  om
        lines = FileUtils.readLines(outputFile);
    } catch (IOException e) {
        throw new RuntimeException("Could not read output file.", e);
    }

    boolean lineWithRmseContained = false;
    Double rmse = null;
    for (String line : lines) {
        lineWithRmseContained = line.contains("RMSE:");
        if (lineWithRmseContained) {
            rmse = Double.parseDouble(getRmseString(line));
            break;
        }
    }

    if (!lineWithRmseContained) {
        throw new RuntimeException(
                String.format("The output file %s did not contain a RMSE line.", outputFile.getAbsoluteFile()));
    }

    return rmse;
}

From source file:com.qspin.qtaste.testsuite.impl.JythonTestScript.java

public static List<String> getAdditionalPythonPath(File file) {
    List<String> pythonlibs = new ArrayList<>();
    //add librairies references by the environment variable
    for (String additionnalPath : StaticConfiguration.JYTHON_LIB.split(File.pathSeparator)) {
        File directory = new File(additionnalPath);
        pythonlibs.add(directory.toString());
    }/*from   w w w. j a va  2  s .  c o  m*/

    if (!file.getAbsolutePath().contains("TestSuites")) {
        return pythonlibs;
    }
    try {
        File directory = file.getAbsoluteFile().getCanonicalFile();
        while (!directory.getName().equals("TestSuites")) {
            //File testSuitesDirectory = new File("TestSuites").getAbsoluteFile().getCanonicalFile();
            //do {
            directory = directory.getParentFile();
            pythonlibs.add(directory + File.separator + "pythonlib");
        } //while (!directory.equals(testSuitesDirectory));
    } catch (IOException e) {
        logger.error("Error while getting pythonlib directories: " + e.getMessage());
    }
    return pythonlibs;
}

From source file:gov.nih.nci.cacis.nav.AbstractSendMail.java

/**
 * Traverse a directory and get all files, and add the file into fileList
 * /*  www. j a va2 s.c o  m*/
 * @param node file or directory
 */
public List<String> generateFileList(File node) {
    //        LOG.info("Temp Zip File location: "+node.getAbsolutePath());
    // add file only
    if (node.isFile()) {
        //            LOG.info("File name: "+node.getName());
        fileList.add(generateZipEntry(node.getAbsoluteFile().toString()));
    }
    if (node.isDirectory()) {
        String[] subNote = node.list();
        for (String filename : subNote) {
            generateFileList(new File(node, filename));
        }
    }
    return fileList;
}

From source file:de.sitewaerts.cordova.documentviewer.DocumentViewerPlugin.java

private void deleteRecursive(File f, boolean self) {
    if (!f.exists())
        return;//from w  ww. j  av  a 2 s.c  om

    if (f.isDirectory()) {
        File[] files = f.listFiles();
        for (File file : files)
            deleteRecursive(file, true);
    }

    if (self && !f.delete())
        Log.e(TAG, "Failed to delete file " + f.getAbsoluteFile());

}

From source file:com.generalbioinformatics.rdf.gui.ProjectManager.java

public void loadProject(File projectFile) throws JDOMException, IOException {
    InputStream is = new FileInputStream(projectFile);
    loadProject(is);//w w  w.  j  av  a 2s .  co  m

    // remove all occurrences of this file so it can be reinsert at the top
    Iterator<RecentItem> it = recentItems.iterator();
    while (it.hasNext()) {
        RecentItem i = it.next();
        if (i.file == null || i.file.getAbsoluteFile().equals(projectFile.getAbsoluteFile())) {
            it.remove();
        }
    }

    recentItems.add(0, new RecentItem(projectFile, getProject().getTitle()));
    if (recentItems.size() > MarrsPreference.RECENT_FILE_NUM)
        recentItems.remove(recentItems.size() - 1);

    refreshRecentFilesMenu();

    for (int i = 0; i < MarrsPreference.RECENT_FILE_NUM; ++i) {
        prefs.setFile(MarrsPreference.RECENT_FILE_ARRAY[i],
                (i >= recentItems.size()) ? null : recentItems.get(i).file);
        prefs.set(MarrsPreference.RECENT_FILE_TITLE_ARRAY[i],
                (i >= recentItems.size()) ? null : recentItems.get(i).title);
    }
}

From source file:interactivespaces.launcher.bootstrap.InteractiveSpacesFrameworkBootstrap.java

/**
 * Start all bundles.//from ww  w .j av  a  2  s.  c o m
 *
 * @param jars
 *          the jars to start as OSGi bundles
 *
 * @throws BundleException
 *           something happened while starting bundles that could not be recovered from
 */
private void startBundles(List<File> jars) throws BundleException {
    for (File bundleFile : jars) {
        String bundleUri = bundleFile.getAbsoluteFile().toURI().toString();

        try {
            Bundle bundle = rootBundleContext.installBundle(bundleUri);

            String symbolicName = bundle.getSymbolicName();
            if (symbolicName != null) {
                InteractiveSpacesStartLevel startLevel = InteractiveSpacesStartLevel.STARTUP_LEVEL_DEFAULT;
                if (symbolicName.equals("interactivespaces.master.webapp")) {
                    startLevel = InteractiveSpacesStartLevel.STARTUP_LEVEL_LAST;
                } else if (symbolicName.equals("interactivespaces.master")) {
                    startLevel = InteractiveSpacesStartLevel.STARTUP_LEVEL_PENULTIMATE;
                } else {
                    String interactiveSpacesStartLevel = bundle.getHeaders()
                            .get(BUNDLE_MANIFEST_START_LEVEL_HEADER);
                    if (interactiveSpacesStartLevel != null) {
                        startLevel = InteractiveSpacesStartLevel.valueOf(interactiveSpacesStartLevel);
                    }
                }

                if (startLevel != InteractiveSpacesStartLevel.STARTUP_LEVEL_DEFAULT) {
                    bundle.adapt(BundleStartLevel.class).setStartLevel(startLevel.getStartLevel());
                }

                bundles.add(bundle);
            } else {
                logBadBundle(bundleUri, new Exception("No symbolic name"));
            }
        } catch (Exception e) {
            logBadBundle(bundleUri, e);
        }
    }

    // Start all installed non-fragment bundles.
    for (final Bundle bundle : bundles) {
        if (!isFragment(bundle)) {
            // TODO(keith): See if way to start up shell from property
            // since we may want it for remote access.
            String symbolicName = bundle.getSymbolicName();
            if (symbolicName.equals("org.apache.felix.gogo.shell") && !needShell) {
                continue;
            }

            startBundle(bundle);
        }
    }
}

From source file:android.databinding.tool.DataBindingBuilder.java

private List<String> readGeneratedClasses(File generatedClassListFile) {
    Preconditions.checkNotNull(generatedClassListFile,
            "Data binding exclude generated task" + " is not configured properly");
    Preconditions.check(generatedClassListFile.exists(), "Generated class list does not exist %s",
            generatedClassListFile.getAbsolutePath());
    FileInputStream fis = null;//  w  ww  .  j  ava 2  s. co m
    try {
        fis = new FileInputStream(generatedClassListFile);
        return IOUtils.readLines(fis);
    } catch (FileNotFoundException e) {
        L.e(e, "Unable to read generated class list from %s", generatedClassListFile.getAbsoluteFile());
    } catch (IOException e) {
        L.e(e, "Unexpected exception while reading %s", generatedClassListFile.getAbsoluteFile());
    } finally {
        IOUtils.closeQuietly(fis);
    }
    L.e("Could not read data binding generated class list");
    return null;
}