Example usage for org.apache.commons.io FilenameUtils getFullPath

List of usage examples for org.apache.commons.io FilenameUtils getFullPath

Introduction

In this page you can find the example usage for org.apache.commons.io FilenameUtils getFullPath.

Prototype

public static String getFullPath(String filename) 

Source Link

Document

Gets the full path from a full filename, which is the prefix + path.

Usage

From source file:de.thischwa.pmcms.tool.file.FileComparator.java

@Override
public int compare(final File f1, final File f2) {
    if (f1.getAbsolutePath().equals(f2.getAbsolutePath()))
        return 0;

    String path1 = FilenameUtils.getFullPath(f1.getAbsolutePath());
    String path2 = FilenameUtils.getFullPath(f2.getAbsolutePath());
    String name1 = FilenameUtils.getName(f1.getAbsolutePath());
    String name2 = FilenameUtils.getName(f2.getAbsolutePath());
    if (path1.equals(path2) || (StringUtils.isBlank(path1) && StringUtils.isBlank(path2)))
        return name1.compareTo(name2);
    String[] pathParts1 = StringUtils.split(FilenameUtils.getFullPathNoEndSeparator(path1), File.separatorChar);
    String[] pathParts2 = StringUtils.split(FilenameUtils.getFullPathNoEndSeparator(path2), File.separatorChar);

    if (pathParts1.length < pathParts2.length)
        return -1;
    if (pathParts1.length > pathParts2.length)
        return +1;

    int i = 0;//from w  w w  .j  a v  a 2s  .  c  o  m
    while (i < pathParts1.length && i < pathParts2.length) {
        if (!pathParts1[i].equals(pathParts2[i]))
            return pathParts1[i].compareTo(pathParts2[i]);
        i++;
    }
    return 0;
}

From source file:jodtemplate.pptx.Presentation.java

public Presentation(final String xmlPath) {
    this.xmlPath = xmlPath;
    this.fullPath = FilenameUtils.getFullPath(xmlPath);
    this.xmlRelsPath = Utils.getRelsPath(xmlPath);
}

From source file:MSUmpire.Utility.MSConvert.java

public void Convert() {
    try {//  w ww.  j  av  a2  s  . co  m
        String[] msconvertcmd = { msconvertpath, "--mzXML", "--32", "-z", SpectrumPath, "-o",
                FilenameUtils.getFullPath(SpectrumPath) };
        Process p = Runtime.getRuntime().exec(msconvertcmd);
        Logger.getRootLogger().info("MGF file coversion by msconvert.exe...." + SpectrumPath);
        Logger.getRootLogger().debug("Command: " + Arrays.toString(msconvertcmd));
        PrintThread printThread = new PrintThread(p);
        printThread.start();
        p.waitFor();
        if (p.exitValue() != 0) {
            Logger.getRootLogger().info("msconvert : " + SpectrumPath + " failed");
            //PrintOutput(p);
            return;
        }
    } catch (IOException | InterruptedException ex) {
        java.util.logging.Logger.getLogger(MSConvert.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:net.shopxx.util.CompressUtils.java

public static void archive(File[] srcFiles, File destFile, String archiverName) {
    Assert.notNull(destFile);/*from  w  w  w.j  av  a  2s . c  o m*/
    Assert.state(!destFile.exists() || destFile.isFile());
    Assert.hasText(archiverName);

    File parentFile = destFile.getParentFile();
    if (parentFile != null) {
        parentFile.mkdirs();
    }
    ArchiveOutputStream archiveOutputStream = null;
    try {
        archiveOutputStream = new ArchiveStreamFactory().createArchiveOutputStream(archiverName,
                new BufferedOutputStream(new FileOutputStream(destFile)));
        if (ArrayUtils.isNotEmpty(srcFiles)) {
            for (File srcFile : srcFiles) {
                if (srcFile == null || !srcFile.exists()) {
                    continue;
                }
                Set<File> files = new HashSet<File>();
                if (srcFile.isFile()) {
                    files.add(srcFile);
                }
                if (srcFile.isDirectory()) {
                    files.addAll(FileUtils.listFilesAndDirs(srcFile, TrueFileFilter.INSTANCE,
                            TrueFileFilter.INSTANCE));
                }
                String basePath = FilenameUtils.getFullPath(srcFile.getCanonicalPath());
                for (File file : files) {
                    try {
                        String entryName = FilenameUtils.separatorsToUnix(
                                StringUtils.substring(file.getCanonicalPath(), basePath.length()));
                        ArchiveEntry archiveEntry = archiveOutputStream.createArchiveEntry(file, entryName);
                        archiveOutputStream.putArchiveEntry(archiveEntry);
                        if (file.isFile()) {
                            InputStream inputStream = null;
                            try {
                                inputStream = new BufferedInputStream(new FileInputStream(file));
                                IOUtils.copy(inputStream, archiveOutputStream);
                            } catch (FileNotFoundException e) {
                                throw new RuntimeException(e.getMessage(), e);
                            } catch (IOException e) {
                                throw new RuntimeException(e.getMessage(), e);
                            } finally {
                                IOUtils.closeQuietly(inputStream);
                            }
                        }
                    } catch (IOException e) {
                        throw new RuntimeException(e.getMessage(), e);
                    } finally {
                        archiveOutputStream.closeArchiveEntry();
                    }
                }
            }
        }
    } catch (ArchiveException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (FileNotFoundException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(archiveOutputStream);
    }
}

From source file:com.tao_harmony.fx2extend.journal.JournalUtil.java

/**
 * ?????./*from  www .j a  va 2 s .  com*/
 *
 * @param journals
 *            
 * @param fileName
 *            ?
 * @throws NoListException
 *             ?Null??????
 * @throws FileNameEmptyException
 *             ???Null??????
 * @throws IOException
 *             ???????
 */
public static void saveJournals(List<Journal> journals, String fileName)
        throws NoListException, FileNameEmptyException, IOException {
    // Null?
    if (journals == null) {
        throw new NoListException();
    }
    // ??
    if (journals.isEmpty()) {
        throw new NoListException();
    }
    // ????
    if (StringUtils.isBlank(fileName) || StringUtils.isBlank(FilenameUtils.getName(fileName))) {
        throw new FileNameEmptyException();
    }
    // ?.slp???
    String name = FilenameUtils.getFullPath(fileName) + FilenameUtils.getBaseName(fileName) + ".slp";
    // ?
    CsvManager csvManager = new CsvEntityManager();
    //CsvManager csvManager = CsvManagerFactory.newCsvManager();
    csvManager.save(journals, Journal.class).to(new File(name));

}

From source file:MSUmpire.BaseDataStructure.TandemParam.java

@Override
public void SetResultFilePath(String mzXMLfile) {
    SpectrumPath = FilenameUtils/*from   ww w .j  a  v  a 2  s. co  m*/
            .separatorsToUnix(FilenameUtils.getFullPath(mzXMLfile) + FilenameUtils.getName(mzXMLfile));
    PepXMLPath = FilenameUtils.separatorsToUnix(
            FilenameUtils.getFullPath(mzXMLfile) + FilenameUtils.getBaseName(mzXMLfile) + ".tandem.pep.xml");
    InteractPepXMLPath = FilenameUtils.separatorsToUnix(FilenameUtils.getFullPath(mzXMLfile) + "interact-"
            + FilenameUtils.getBaseName(mzXMLfile) + ".tandem.pep.xml");
    ProtXMLPath = InteractPepXMLPath.replace(".pep.xml", ".prot.xml");
    parameterPath = FilenameUtils.separatorsToUnix(
            FilenameUtils.getFullPath(mzXMLfile) + FilenameUtils.getBaseName(mzXMLfile) + ".tandem.param");
    RawSearchResult = FilenameUtils.separatorsToUnix(
            FilenameUtils.getFullPath(mzXMLfile) + FilenameUtils.getBaseName(mzXMLfile) + ".tandem");
}

From source file:com.seagate.kinetic.ForkedTestTarget.java

public ForkedTestTarget(boolean clearExistingDatabase, String serverRunnerPath, int port, int tlsPort)
        throws IOException, InterruptedException, KineticException {
    super("localhost", port, tlsPort);

    FinalizedProcessBuilder finalizedProcessBuilder = new FinalizedProcessBuilder("killall", "-9", "kineticd");
    finalizedProcessBuilder.start().waitFor(10 * 1000);
    Thread.sleep(500);//from   w  w w  .  jav  a 2s  . c  om

    // Since the cluster version is checked before performing an ISE we need to manually remove
    // the file used to store the cluster version
    if (clearExistingDatabase) {
        final String workingDirectory = FilenameUtils.getFullPath(serverRunnerPath);
        final String clusterStorePath = FilenameUtils.concat(workingDirectory, "cluster_version");
        FileUtils.deleteQuietly(new File(clusterStorePath));
    }

    finalizedProcessBuilder = new FinalizedProcessBuilder(serverRunnerPath);
    finalizedProcessBuilder.directory(new File("."));
    finalizedProcessBuilder.gobbleStreamsWithLogging(true);

    externalKineticServer = finalizedProcessBuilder.start();
    waitForServerReady();

    // The ForkedTestTarget only runs on x86. The x86 implementations' ISE is almost instant with small DBs so
    // it's OK to issue a kinetic ISE instead of using SSH
    if (clearExistingDatabase) {
        performISE();
    }
}

From source file:MSUmpire.SpectrumParser.DIA_Setting.java

public static DIA_Setting ReadDIASettingSerialization(String filepath) {
    if (!new File(FilenameUtils.getFullPath(filepath) + FilenameUtils.getBaseName(filepath) + "_diasetting.ser")
            .exists()) {/*from w  ww  .j a v a 2 s .c o m*/
        return null;
    }
    try {
        Logger.getRootLogger().debug("Reading DIA setting from file:" + FilenameUtils.getFullPath(filepath)
                + FilenameUtils.getBaseName(filepath) + "_diasetting.ser...");

        FileInputStream fileIn = new FileInputStream(
                FilenameUtils.getFullPath(filepath) + FilenameUtils.getBaseName(filepath) + "_diasetting.ser");
        ObjectInputStream in = new ObjectInputStream(fileIn);
        DIA_Setting setting = (DIA_Setting) in.readObject();
        in.close();
        fileIn.close();
        return setting;

    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        return null;
    }
}

From source file:ch.entwine.weblounge.tools.importer.ResourceImporterCallback.java

/**
 * This method is called if a resource file has been found.
 * //  w w w  .j av  a  2  s .  c  om
 * @see ch.entwine.weblounge.tools.importer.AbstractImporterCallback#fileImported(java.io.File)
 */
public boolean fileImported(File f) {
    // load collection information
    File collXml = new File(FilenameUtils.getFullPath(f.getPath()) + "repository.xml");
    if (!collXml.exists()) {
        System.err.println("No repository information (repository.xml) found for file: " + f.getName());
        return false;
    }

    // path relative to the src directory
    String relpath = f.getPath().replaceAll(this.srcDir.getAbsolutePath(), "");

    // Check if collXml contains information for this file
    XMLDocument repoXml = new XMLDocument(collXml);
    if (repoXml.getNode("/collection/entry[@id='" + relpath + "']") == null)
        return false;

    UUID uuid = UUID.randomUUID();
    File resourceXml = null;
    ImageInfo imageInfo = null;
    try {
        // create temporary resource descriptor file
        resourceXml = File.createTempFile(uuid.toString(), ".xml");

        // try loading file as image
        imageInfo = Sanselan.getImageInfo(f);
    } catch (IOException e) {
        System.err.println("Error processing file '" + relpath + "': " + e.getMessage());
        return false;
    } catch (ImageReadException e) {
        // file is not an image
    }

    ImporterState.getInstance().putUUID(relpath, uuid);

    String filename = "de.".concat(FilenameUtils.getExtension(f.getName()));

    // check, if file is an image resource
    String subfolder = null;
    if (imageInfo != null) {
        subfolder = "images";
        Source xsl = new StreamSource(this.getClass().getResourceAsStream("/xsl/convert-image.xsl"));
        // set the TransformFactory to use the Saxon TransformerFactoryImpl method
        System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl");
        TransformerFactory transFact = TransformerFactory.newInstance();
        Transformer trans;
        try {
            trans = transFact.newTransformer(xsl);
            trans.setParameter("fileid", relpath);
            trans.setParameter("uuid", uuid.toString());
            trans.setParameter("path", relpath);
            trans.setParameter("imgwidth", imageInfo.getWidth());
            trans.setParameter("imgheight", imageInfo.getHeight());
            this.transformXml(collXml, resourceXml, trans);
        } catch (TransformerConfigurationException e) {
            System.err.println(e.getMessage());
            return false;
        }
    } else {
        subfolder = "files";
        Source xsl = new StreamSource(this.getClass().getResourceAsStream("/xsl/convert-file.xsl"));
        TransformerFactory transFact = TransformerFactory.newInstance();
        Transformer trans;
        try {
            trans = transFact.newTransformer(xsl);
            trans.setParameter("fileid", relpath);
            trans.setParameter("uuid", uuid.toString());
            trans.setParameter("path", relpath);
            this.transformXml(collXml, resourceXml, trans);
        } catch (TransformerConfigurationException e) {
            System.err.println(e.getMessage());
            return false;
        }
    }

    this.storeFile(f, destDir, subfolder, filename, uuid, 0);
    this.storeFile(resourceXml, destDir, subfolder, "index.xml", uuid, 0);
    System.out.println("Imported resource " + f.getName());
    return true;
}

From source file:de.uzk.hki.da.grid.IrodsCopyExecutor.java

public boolean execute(CopyJob cj) {
    logger.debug("starting Syncing ... ");
    if (cj == null) {
        logger.error("CopyJob is null");
        return false;
    }/*from   ww w .  ja va 2 s  .c o m*/

    if (dirPrefix == null) {
        logger.error("dirPrefix is null");
        return false;
    }

    String targetFile = "/" + cj.getDest_name() + "/" + dirPrefix + cj.getAipGridPath();
    String targetDir = FilenameUtils.getFullPath(targetFile);
    if (!iclc.exists(targetDir)) {
        logger.info("Creating " + targetDir + " now");
        iclc.mkCollection(targetDir);
    }
    logger.debug("iRSYNC " + cj.getSource() + " & " + targetFile + " with " + cj.getParams());
    try {
        String out = iclc.rsync(cj.getSource(), targetFile, cj.getParams());
        logger.debug(out);
    } catch (RuntimeException irex) {
        logger.error(irex.getMessage());
        return false;
    }
    return true;
}