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

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

Introduction

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

Prototype

public static String separatorsToUnix(String path) 

Source Link

Document

Converts all separators to the Unix separator of forward slash.

Usage

From source file:com.sonicle.webtop.vfs.VfsManager.java

public String createStoreFile(StoreFileType fileType, int storeId, String parentPath, String name)
        throws FileSystemException, WTException {
    FileObject tfo = null, ntfo = null;

    try {/*from   w w  w.ja  va  2  s. c  o m*/
        checkRightsOnStoreElements(storeId, "UPDATE"); // Rights check!

        tfo = getTargetFileObject(storeId, parentPath);
        if (!tfo.isFolder())
            throw new IllegalArgumentException("Please provide a valid parentPath");

        String newPath = FilenameUtils.separatorsToUnix(FilenameUtils.concat(parentPath, name));
        ntfo = getTargetFileObject(storeId, newPath);
        logger.debug("Creating store file [{}, {}]", storeId, newPath);
        if (fileType.equals(StoreFileType.FOLDER)) {
            ntfo.createFolder();
        } else {
            ntfo.createFile();
        }
        return newPath;

    } catch (Exception ex) {
        logger.warn("Error creating store file", ex);
        throw ex;
    } finally {
        IOUtils.closeQuietly(tfo);
        IOUtils.closeQuietly(ntfo);
    }
}

From source file:com.searchcode.app.jobs.IndexGitRepoJob.java

private RepositoryChanged updateGitRepository(String repoName, String repoRemoteLocation, String repoUserName,
        String repoPassword, String repoLocations, String branch, boolean useCredentials) {
    boolean changed = false;
    List<String> changedFiles = new ArrayList<>();
    List<String> deletedFiles = new ArrayList<>();
    Singleton.getLogger().info("Attempting to pull latest from " + repoRemoteLocation + " for " + repoName);

    try {/* w  w w .  j a va  2s . c  o m*/
        Repository localRepository = new FileRepository(new File(repoLocations + "/" + repoName + "/.git"));

        Ref head = localRepository.getRef("HEAD");

        Git git = new Git(localRepository);
        git.reset();
        git.clean();

        PullCommand pullCmd = git.pull();

        if (useCredentials) {
            pullCmd.setCredentialsProvider(new UsernamePasswordCredentialsProvider(repoUserName, repoPassword));
        }

        pullCmd.call();
        Ref newHEAD = localRepository.getRef("HEAD");

        if (!head.toString().equals(newHEAD.toString())) {
            changed = true;

            // Get the differences between the the heads which we updated at
            // and use these to just update the differences between them
            ObjectId oldHead = localRepository.resolve(head.getObjectId().getName() + "^{tree}");
            ObjectId newHead = localRepository.resolve(newHEAD.getObjectId().getName() + "^{tree}");

            ObjectReader reader = localRepository.newObjectReader();

            CanonicalTreeParser oldTreeIter = new CanonicalTreeParser();
            oldTreeIter.reset(reader, oldHead);

            CanonicalTreeParser newTreeIter = new CanonicalTreeParser();
            newTreeIter.reset(reader, newHead);

            List<DiffEntry> entries = git.diff().setNewTree(newTreeIter).setOldTree(oldTreeIter).call();

            for (DiffEntry entry : entries) {
                if ("DELETE".equals(entry.getChangeType().name())) {
                    deletedFiles.add(FilenameUtils.separatorsToUnix(entry.getOldPath()));
                } else {
                    changedFiles.add(FilenameUtils.separatorsToUnix(entry.getNewPath()));
                }
            }
        }

    } catch (IOException | GitAPIException | InvalidPathException ex) {
        changed = false;
        Singleton.getLogger().warning("ERROR - caught a " + ex.getClass() + " in " + this.getClass()
                + "\n with message: " + ex.getMessage());
    }

    return new RepositoryChanged(changed, changedFiles, deletedFiles);
}

From source file:MSUmpire.DIA.DIAPack.java

public void SetPepXMLPath() {
    iProphPepXMLs = new ArrayList<String>();
    String PepXMLPath1 = FilenameUtils
            .separatorsToUnix(FilenameUtils.getFullPath(Filename) + "interact-" + GetQ1Name() + ".pep.xml");
    String PepXMLPath2 = FilenameUtils
            .separatorsToUnix(FilenameUtils.getFullPath(Filename) + "interact-" + GetQ2Name() + ".pep.xml");
    String PepXMLPath3 = FilenameUtils
            .separatorsToUnix(FilenameUtils.getFullPath(Filename) + "interact-" + GetQ3Name() + ".pep.xml");
    iProphPepXMLs.add(PepXMLPath1);/*from  w  w  w  . j av  a  2  s.c  o  m*/
    iProphPepXMLs.add(PepXMLPath2);
    iProphPepXMLs.add(PepXMLPath3);
}

From source file:edu.cornell.med.icb.learning.CrossValidation.java

/**
 * Report the area under the Receiver Operating Characteristic (ROC) curve. Estimates are
 * done with a leave one out evaluation.
 *
 * @param decisionValues   Decision values output by classifier. Larger values indicate more
 *                         confidence in prediction of a positive label.
 * @param labels           Correct label for item, can be 0 (negative class) or +1 (positive class).
 * @param rocCurvefilename Name of the file to plot the pdf image to
 *//*w ww .j a va2  s .c o  m*/
public static void plotRocCurveLOO(final double[] decisionValues, final double[] labels,
        final String rocCurvefilename) {
    assert decisionValues.length == labels.length : "number of predictions must match number of labels.";
    for (int i = 0; i < labels.length; i++) { // for each training example, leave it out:
        if (decisionValues[i] < 0) {
            decisionValues[i] = 0;
        }
        if (labels[i] < 0) {
            labels[i] = 0;
        }
    }

    // R server only understands unix style path. Convert windows to unix if needed:
    final String plotFilename = FilenameUtils.separatorsToUnix(rocCurvefilename);
    final File plotFile = new File(plotFilename);

    final RConnectionPool connectionPool = RConnectionPool.getInstance();
    RConnection connection = null;

    // CALL R ROC
    try {
        if (plotFile.exists()) {
            plotFile.delete();
        }

        connection = connectionPool.borrowConnection();
        connection.assign("predictions", decisionValues);
        connection.assign("labels", labels);
        final String cmd = " library(ROCR) \n" + "pred.svm <- prediction(predictions, labels)\n" + "pdf(\""
                + plotFilename + "\", height=5, width=5)\n"
                + "perf <- performance(pred.svm, measure = \"tpr\", x.measure = \"fpr\")\n" + "plot(perf)\n"
                + "dev.off()";

        final REXP expression = connection.eval(cmd); // attr(perf.rocOutAUC,"y.values")[[1]]
        final double valueROC_AUC = expression.asDouble();
        // System.out.println("result from R: " + valueROC_AUC);
    } catch (Exception e) {
        // connection error or otherwise
        LOG.warn("Cannot plot ROC curve to " + plotFilename + ".  Make sure Rserve (R server) "
                + "is configured and running and the owner of the Rserve process has permission "
                + "to write to the directory \"" + FilenameUtils.getFullPath(plotFile.getAbsolutePath()) + "\"",
                e);
    } finally {
        if (connection != null) {
            connectionPool.returnConnection(connection);
        }
    }
}

From source file:com.wlami.mibox.client.metadata.MetadataWorker.java

/**
 * @param appSettings//  w  w  w. ja v a2 s.  c  o m
 * @param filename
 * @return
 */
public String getRelativePath(AppSettings appSettings, String filename) {
    return StringUtils.substringAfter(FilenameUtils.separatorsToUnix(filename),
            appSettings.getWatchDirectory());
}

From source file:com.sonicle.webtop.vfs.VfsManager.java

private NewTargetFile getNewTargetFileObject(int storeId, String parentPath, String name, boolean overwrite)
        throws FileSystemException, WTException {
    String newPath = FilenameUtils.separatorsToUnix(FilenameUtils.concat(parentPath, name));

    if (overwrite) {
        return new NewTargetFile(newPath, getTargetFileObject(storeId, newPath));
    } else {//  w  ww .  j ava  2s. c om
        FileObject newFo = getTargetFileObject(storeId, newPath);
        if (!newFo.exists()) {
            return new NewTargetFile(newPath, newFo);
        } else {
            String ext = FilenameUtils.getExtension(name);
            String suffix = StringUtils.isBlank(ext) ? "" : "." + ext;
            String baseName = FilenameUtils.getBaseName(name);
            int i = 0;
            do {
                i++;
                final String newName = baseName + " (" + i + ")" + suffix;
                newPath = FilenameUtils.separatorsToUnix(FilenameUtils.concat(parentPath, newName));
                newFo = getTargetFileObject(storeId, newPath);
            } while (newFo.exists());
            return new NewTargetFile(newPath, newFo);
        }
    }
}

From source file:com.sonicle.webtop.vfs.VfsManager.java

private String doRenameStoreFile(int storeId, String path, String newName)
        throws FileSystemException, SQLException, DAOException, WTException {
    SharingLinkDAO dao = SharingLinkDAO.getInstance();
    FileObject tfo = null, ntfo = null;
    Connection con = null;//from   ww w. jav  a  2 s.  c o m

    try {
        tfo = getTargetFileObject(storeId, path);
        String newPath = FilenameUtils
                .separatorsToUnix(FilenameUtils.concat(FilenameUtils.getFullPath(path), newName));
        ntfo = getTargetFileObject(storeId, newPath);

        logger.debug("Renaming store file [{}, {} -> {}]", storeId, path, newPath);
        try {
            con = WT.getConnection(SERVICE_ID, false);

            dao.deleteByStorePath(con, storeId, path);
            tfo.moveTo(ntfo);
            DbUtils.commitQuietly(con);

        } catch (FileSystemException ex1) {
            DbUtils.rollbackQuietly(con);
            throw ex1;
        } finally {
            DbUtils.closeQuietly(con);
        }
        return newPath;

    } finally {
        IOUtils.closeQuietly(tfo);
        IOUtils.closeQuietly(ntfo);
    }
}

From source file:au.edu.usq.fascinator.harvester.ice2.Ice2Harvester.java

private DigitalObject createObject(File file, String itemType, boolean render)
        throws HarvesterException, StorageException {
    objectsCreated++;/*  w  w w . j a v  a  2  s.  c  o m*/
    filesProcessed++;

    if (testRun) {
        return null;
    }

    DigitalObject object = StorageUtils.storeFile(getStorage(), file, link);

    // update object metadata
    Properties props = object.getMetadata();
    props.setProperty("usq-course", course);
    props.setProperty("usq-semester", semester);
    props.setProperty("render-pending", "true");
    props.setProperty("file.path", FilenameUtils.separatorsToUnix(file.getAbsolutePath()));
    props.setProperty("item-type", itemType);

    if (render) {
        props.setProperty("harvestQueue", "aperture");
        props.setProperty("indexOnHarvest", "true");
        props.setProperty("renderQueue", "ffmpeg,ice2");
    } else {
        props.setProperty("harvestQueue", "");
        props.setProperty("indexOnHarvest", "false");
        props.setProperty("renderQueue", "aperture");
    }

    object.close();
    return object;
}

From source file:com.xyphos.vmtgen.GUI.java

private void lstFilesValueChanged(javax.swing.event.ListSelectionEvent evt) {// GEN-FIRST:event_lstFilesValueChanged
    if (!evt.getValueIsAdjusting() && (-1 != lstFiles.getSelectedIndex())) {
        String file = lstFiles.getSelectedValue().toString();

        // set keywords based on file name
        setKeywords(FilenameUtils.getBaseName(file).replace("_", ",").replace("-", ","));

        String path = FilenameUtils
                .separatorsToUnix(FilenameUtils.concat(basePath, FilenameUtils.getBaseName(file)))
                .replaceFirst("/", "");

        setBaseTexture1(path);// w  ww  .  ja  v a 2 s. c  o m

        // read the vtf header
        file = FilenameUtils.concat(workPath, file);
        File fileVTF = new File(file);

        try (LittleEndianDataInputStream in = new LittleEndianDataInputStream(new FileInputStream(fileVTF))) {

            int sig = in.readInt();
            if (SIGNATURE_VTF != sig) {
                throw new IOException("Not a VTF file");
            }

            if (0x10 != in.skipBytes(0x10)) {
                throw new IOException("skip failure");
            }

            int flags = in.readInt();
            frameCount = in.readShort();
            in.close(); // don't need any more information

            chkFlagNoLOD.setSelected(0 != (0x200 & flags));
            chkFlagTranslucent.setSelected(0 != (0x3000 & flags));

            if (animated = (1 < frameCount)) {
                setFrameRate(frameCount);
                ((SpinnerNumberModel) nudEnvMapFrame.getModel()).setMaximum(frameCount);
            }

            nudFrameRate.setEnabled(animated & !chkLockFrameRate.isSelected());
            nudEnvMapFrame.setEnabled(animated & !chkLockEnvMapFrame.isSelected());

            chkLockFrameRate.setEnabled(animated);
            chkLockEnvMapFrame.setEnabled(animated);

        } catch (FileNotFoundException ex) {
            logger.log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            logger.log(Level.SEVERE, null, ex);
        }
    }
}

From source file:com.xyphos.vmtgen.GUI.java

private String selectVTF() {
    JFileChooser fc = new JFileChooser(txtWorkFolder.getText());
    fc.setAcceptAllFileFilterUsed(false);
    fc.setFileFilter(new FileFilterVTF());
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);

    int result = fc.showOpenDialog(this);
    if (JFileChooser.APPROVE_OPTION == result) {
        String file = fc.getSelectedFile().getName();
        return FilenameUtils.separatorsToUnix(FilenameUtils.concat(basePath, FilenameUtils.getBaseName(file)))
                .replaceFirst("/", "");
    }//w w  w  .  java 2s . com

    return null;
}