Example usage for java.io File getCanonicalPath

List of usage examples for java.io File getCanonicalPath

Introduction

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

Prototype

public String getCanonicalPath() throws IOException 

Source Link

Document

Returns the canonical pathname string of this abstract pathname.

Usage

From source file:com.moviejukebox.reader.MovieJukeboxLibraryReader.java

public static Collection<MediaLibraryPath> parse(File libraryFile) {
    Collection<MediaLibraryPath> mlp = new ArrayList<>();

    if (!libraryFile.exists() || libraryFile.isDirectory()) {
        LOG.error("The moviejukebox library input file you specified is invalid: {}", libraryFile.getName());
        return mlp;
    }/*from   w  w w  .j av  a  2s  .c  o m*/

    try {
        XMLConfiguration c = new XMLConfiguration(libraryFile);

        List<HierarchicalConfiguration> fields = c.configurationsAt("library");
        for (HierarchicalConfiguration sub : fields) {
            // sub contains now all data about a single medialibrary node
            String path = sub.getString("path");
            String nmtpath = sub.getString("nmtpath"); // This should be depreciated
            String playerpath = sub.getString("playerpath");
            String description = sub.getString("description");
            boolean scrapeLibrary = true;

            String scrapeLibraryString = sub.getString("scrapeLibrary");
            if (StringTools.isValidString(scrapeLibraryString)) {
                try {
                    scrapeLibrary = sub.getBoolean("scrapeLibrary");
                } catch (Exception ignore) {
                    /* ignore */ }
            }

            long prebuf = -1;
            String prebufString = sub.getString("prebuf");
            if (prebufString != null && !prebufString.isEmpty()) {
                try {
                    prebuf = Long.parseLong(prebufString);
                } catch (NumberFormatException ignore) {
                    /* ignore */ }
            }

            // Note that the nmtpath should no longer be used in the library file and instead "playerpath" should be used.
            // Check that the nmtpath terminates with a "/" or "\"
            if (nmtpath != null) {
                if (!(nmtpath.endsWith("/") || nmtpath.endsWith("\\"))) {
                    // This is the NMTPATH so add the unix path separator rather than File.separator
                    nmtpath = nmtpath + "/";
                }
            }

            // Check that the playerpath terminates with a "/" or "\"
            if (playerpath != null) {
                if (!(playerpath.endsWith("/") || playerpath.endsWith("\\"))) {
                    // This is the PlayerPath so add the Unix path separator rather than File.separator
                    playerpath = playerpath + "/";
                }
            }

            List<Object> excludes = sub.getList("exclude[@name]");
            File medialibfile = new File(path);
            if (medialibfile.exists()) {
                MediaLibraryPath medlib = new MediaLibraryPath();
                medlib.setPath(medialibfile.getCanonicalPath());
                if (playerpath == null || StringUtils.isBlank(playerpath)) {
                    medlib.setPlayerRootPath(nmtpath);
                } else {
                    medlib.setPlayerRootPath(playerpath);
                }
                medlib.setExcludes(excludes);
                medlib.setDescription(description);
                medlib.setScrapeLibrary(scrapeLibrary);
                medlib.setPrebuf(prebuf);
                mlp.add(medlib);

                if (description != null && !description.isEmpty()) {
                    LOG.info("Found media library: {}", description);
                } else {
                    LOG.info("Found media library: {}", path);
                }
                // Save the media library to the log file for reference.
                LOG.debug("Media library: {}", medlib);

            } else {
                LOG.info("Skipped invalid media library: {}", path);
            }
        }
    } catch (ConfigurationException | IOException ex) {
        LOG.error("Failed parsing moviejukebox library input file: {}", libraryFile.getName());
        LOG.error(SystemTools.getStackTrace(ex));
    }
    return mlp;
}

From source file:com.liferay.ide.project.core.modules.BladeCLI.java

private static IPath _getBladeJarFromBundle() throws IOException {
    Bundle bundle = ProjectCore.getDefault().getBundle();

    File bladeJarBundleFile = new File(
            FileLocator.toFileURL(bundle.getEntry("lib/" + BLADE_JAR_FILE_NAME)).getFile());

    return new Path(bladeJarBundleFile.getCanonicalPath());
}

From source file:eu.eubrazilcc.lvl.service.io.DatasetWriter.java

private static File writeFastaSequence(final File inFile, final File outDir, final String compression)
        throws IOException {
    final File outFile = new File(outDir,
            getBaseName(inFile.getCanonicalPath()) + ".fasta" + (compression.equals(GZIP) ? ".gz" : ""));
    LOGGER.trace("Writing FASTA sequence from '" + inFile.getCanonicalPath() + "' to '"
            + outFile.getCanonicalPath());
    toFasta(inFile, outFile.getCanonicalPath(), compression.equals(GZIP));
    return outFile;
}

From source file:com.googlecode.t7mp.util.ZipUtil.java

public static void unzip(InputStream warInputStream, File destination) {
    try {/*www. j a va2 s.com*/
        ZipArchiveInputStream in = null;
        try {
            in = new ZipArchiveInputStream(warInputStream);

            ZipArchiveEntry entry = null;
            while ((entry = in.getNextZipEntry()) != null) {
                File outfile = new File(destination.getCanonicalPath() + "/" + entry.getName());
                outfile.getParentFile().mkdirs();
                if (entry.isDirectory()) {
                    outfile.mkdir();
                    continue;
                }
                OutputStream o = new FileOutputStream(outfile);
                try {
                    IOUtils.copy(in, o);
                } finally {
                    o.close();
                }
            }
        } finally {
            if (in != null) {
                in.close();
            }
        }
        warInputStream.close();
    } catch (FileNotFoundException e) {
        throw new TomcatSetupException(e.getMessage(), e);
    } catch (IOException e) {
        throw new TomcatSetupException(e.getMessage(), e);
    }
}

From source file:com.seitenbau.jenkins.plugins.dynamicparameter.config.DynamicParameterManagement.java

private static File getRebasedFile(String path) throws IOException {
    String basePath = getBaseDirectoryPath();
    File file = new File(path);
    if (!file.isAbsolute()) {
        file = new File(basePath, path);
    }/*from  ww  w .j av a2 s .  c  o m*/

    String canonicalFilePath = file.getCanonicalPath();
    if (FileUtils.isDescendant(basePath, canonicalFilePath)) {
        return file;
    } else {
        // don't leave the base directory
        String fileName = new File(canonicalFilePath).getName();
        if (fileName.length() == 0) {
            // don't return the base directory in any case
            fileName = DEFAULT_NAME;
        }
        File rebasedFile = new File(basePath, fileName);
        return rebasedFile;
    }
}

From source file:com.izforge.izpack.util.file.FileUtils.java

/**
 * Checks whether a given file is a symbolic link.
 * <p/>/*from   w w w . ja  va2s . com*/
 * <p>It doesn't really test for symbolic links but whether the
 * canonical and absolute paths of the file are identical--this
 * may lead to false positives on some platforms.</p>
 *
 * @param parent the parent directory of the file to test
 * @param name   the name of the file to test.
 * @return true if the file is a symbolic link.
 * @throws IOException on error.
 */
public static boolean isSymbolicLink(File parent, String name) throws IOException {
    if (parent == null) {
        File f = new File(name);
        parent = f.getParentFile();
        name = f.getName();
    }
    File toTest = new File(parent.getCanonicalPath(), name);
    return org.apache.commons.io.FileUtils.isSymlink(toTest);
}

From source file:ezbake.deployer.impl.Files.java

public static File relativize(File base, File target) {
    String[] baseComponents;/*from  w w  w  .ja  v a  2  s.c  o m*/
    String[] targetComponents;
    try {
        baseComponents = base.getCanonicalPath().split(Pattern.quote(File.separator));
        targetComponents = target.getCanonicalPath().split(Pattern.quote(File.separator));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    // skip common components
    int index = 0;
    for (; index < targetComponents.length && index < baseComponents.length; ++index) {
        if (!targetComponents[index].equals(baseComponents[index]))
            break;
    }

    StringBuilder result = new StringBuilder();
    if (index != baseComponents.length) {
        // backtrack to base directory
        for (int i = index; i < baseComponents.length; ++i)
            result.append("..").append(File.separator);
    }
    for (; index < targetComponents.length; ++index)
        result.append(targetComponents[index]).append(File.separator);
    if (!target.getPath().endsWith("/") && !target.getPath().endsWith("\\")) {
        // remove final path separator
        result.delete(result.length() - File.separator.length(), result.length());
    }
    return new File(result.toString());
}

From source file:de.unisb.cs.st.javalanche.mutation.run.task.MutationTaskCreator.java

private static File writeListToFile(List<Long> list, int taskId, int totalNumberOfTasks) throws IOException {
    File resultFile = getFileName(taskId, totalNumberOfTasks);
    List<String> lines = new ArrayList<String>();
    for (Long l : list) {
        lines.add(l + "");
    }//  w w  w.jav  a  2 s  .c o m
    FileUtils.writeLines(resultFile, lines);
    System.out.println("Task created: " + resultFile.getCanonicalPath());
    return resultFile;
}

From source file:edu.kit.dama.staging.util.StagingUtils.java

/**
 * Get the temporary directory all transfers. This directory is located in the
 * user home directory under ~/.lsdf/. Within the temporary directory the
 * transfer can store status information or checkpoint data to be able to
 * resume failed transfers./*from  w w w.  java 2  s. c  o  m*/
 *
 * @return The transfers temporary directory
 *
 * @throws IOException If there was not set any TID for this transfer or if
 * there are problems getting the user's home directory
 */
public static String getTempDir() throws IOException {
    File userHome = SystemUtils.getUserHome();
    if (userHome == null || !userHome.isDirectory() || !userHome.canRead() || !userHome.canWrite()) {
        throw new IOException("Invalid user home directory '" + userHome + "'");
    }
    return FilenameUtils.concat(userHome.getCanonicalPath(), ".lsdf");
}

From source file:com.cedarsoft.io.LinkUtils.java

/**
 * Returns whether the given file is a link
 *
 * @param file a File object.//  w ww  . j  ava2s.  co  m
 * @return whether the given file is a sym link
 *
 * @throws IOException if any.
 */
public static boolean isLink(@Nonnull File file) throws IOException {
    if (!file.exists()) {
        throw new FileNotFoundException(file.getAbsolutePath());
    }

    @Nonnull
    String canonicalPath = file.getCanonicalPath();
    @Nonnull
    String absolutePath = file.getAbsolutePath();
    return !absolutePath.equals(canonicalPath);
}