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

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

Introduction

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

Prototype

public static String getBaseName(String filename) 

Source Link

Document

Gets the base name, minus the full path and extension, from a full filename.

Usage

From source file:com.bt.download.android.gui.transfers.YouTubeDownload.java

private static File buildFile(File savePath, String name) {
    String baseName = FilenameUtils.getBaseName(name);
    String ext = FilenameUtils.getExtension(name);

    File f = new File(savePath, name);
    int i = 1;//from  w w  w.j  a v  a  2  s.c  om
    while (f.exists() && i < Integer.MAX_VALUE) {
        f = new File(savePath, baseName + " (" + i + ")." + ext);
        i++;
    }
    return f;
}

From source file:edu.cornell.med.icb.goby.algorithmic.algorithm.ExportSplicingEvents.java

public void process(final String filename) throws IOException {
    final AlignmentReader reader = new AlignmentReaderImpl(filename);
    reader.readHeader();/*w w  w  .  j ava  2s .  c om*/
    final IndexedIdentifier targetIds = reader.getTargetIdentifiers();
    reverseIds = new DoubleIndexedIdentifier(targetIds);
    sampleFilename = FilenameUtils.getBaseName(filename);
    lastTargetIndex = -1;

    for (final Alignments.AlignmentEntry entry : reader) {

        processEntry(eventMap, entry);
    }
    flushPreviousRef(null, eventMap);
    output.flush();
}

From source file:MSUmpire.DIA.RTAlignedPepIonMapping.java

public void GenerateModel() throws IOException {

    XYPointCollection points = new XYPointCollection();
    XYSeries series = new XYSeries("Peptide ions");
    XYSeriesCollection xySeriesCollection = new XYSeriesCollection();

    for (PepIonID pepA : LCMSA.GetPepIonList().values()) {
        if (LCMSB.GetPepIonList().containsKey(pepA.GetKey())) {
            PepIonID pepB = LCMSB.GetPepIonList().get(pepA.GetKey());
            points.AddPoint(pepA.GetRT(), pepB.GetRT());
            series.add(new XYDataItem(pepA.GetRT(), pepB.GetRT()));
        }//from   ww w  .  jav a 2s  .  c om
    }
    regression = new PiecewiseRegression(parameter.MaxCurveRTRange, parameter.MaxCurveRTRange);
    regression.SetData(points);
    float R2 = regression.GetR2();
    Logger.getRootLogger()
            .info("Retention time prediction model:(" + FilenameUtils.getBaseName(LCMSA.mzXMLFileName) + "-"
                    + FilenameUtils.getBaseName(LCMSB.mzXMLFileName) + ")..R2=" + R2
                    + "(No. of commonly identified peptide ions=" + points.PointCount() + ")");

    GenerateRTMapPNG(xySeriesCollection, series, R2);
}

From source file:androidGLUESigner.pdf.PDFSigner.java

/**
 * signs a PDF file/*from   ww w  . j  av  a 2  s .  co m*/
 * @param signInformation holds the reason, location, inputfilepath, ...
 * @param withTSA flag to decide if online TimeStamp should be received
 * @return the signed PDF File
 * @throws Exception
 */
public File signPDF(SignatureInfo signInformation, boolean withTSA) throws Exception {

    // input, temp and output PDF-files
    final String ORIGINAL = signInformation.getInputFilePath();
    final String TMP = signInformation.getInputFilePath() + ".tmp";
    final String RESULT;
    if (sigPath.equals("")) {
        RESULT = signInformation.getInputFilePath().split("\\.")[0] + SIGNED_SUFFIX;
    } else {
        RESULT = (sigPath + "/" + FilenameUtils.getBaseName(signInformation.getInputFilePath()))
                + SIGNED_SUFFIX;
    }

    // get the certificate-chain from the selected connection
    chain = connection.getCertificateChain();

    // initiate the Signer with the certificates and signature info
    PDFSignerEngine signer = new PDFSignerEngine();
    signer.setCertificateChain(chain);
    signer.setSiginfo(signInformation);

    if (withTSA) {
        // prepare the signature and get the digest
        byte[] digest = signer.prepareSign(new FileInputStream(ORIGINAL), new FileOutputStream(TMP));
        byte[] state = signer.getState();

        // sign the digest via connection
        byte[] signedHash = connection.sign(digest);

        // finalize the siganture by adding the signedHash into the signature
        PDFSignerEngine signer2 = new PDFSignerEngine();
        signer2.setTsaUrl(this.tsaUrl);
        signer2.setState(state);
        signer2.finalizeSign(signedHash, new FileInputStream(TMP), new FileOutputStream(RESULT));
    } else {
        signer.simpleSign(ORIGINAL, RESULT, connection);
    }
    //return null;
    return new File(RESULT);
}

From source file:com.textocat.textokit.commons.io.axml.AXML2XMI.java

private File getOutputFile(File inputFile) {
    String baseName = FilenameUtils.getBaseName(inputFile.getPath());
    return new File(outputDir, baseName + ".xmi");
}

From source file:ch.cyberduck.core.DownloadTransfer.java

@Override
protected void normalize() {
    log.debug("normalize");
    final List<Path> normalized = new Collection<Path>();
    for (Path download : this.getRoots()) {
        if (!this.check()) {
            return;
        }/*  ww w . j ava  2 s .  co  m*/
        this.getSession().message(
                MessageFormat.format(Locale.localizedString("Prepare {0}", "Status"), download.getName()));
        boolean duplicate = false;
        for (Iterator<Path> iter = normalized.iterator(); iter.hasNext();) {
            Path n = iter.next();
            if (download.isChild(n)) {
                // The selected file is a child of a directory already included
                duplicate = true;
                break;
            }
            if (n.isChild(download)) {
                iter.remove();
            }
            if (download.getLocal().equals(n.getLocal())) {
                // The selected file has the same name; if downloaded as a root element
                // it would overwrite the earlier
                final String parent = download.getLocal().getParent().getAbsolute();
                final String filename = download.getName();
                String proposal;
                int no = 0;
                do {
                    no++;
                    proposal = FilenameUtils.getBaseName(filename) + "-" + no;
                    if (StringUtils.isNotBlank(FilenameUtils.getExtension(filename))) {
                        proposal += "." + FilenameUtils.getExtension(filename);
                    }
                    download.setLocal(LocalFactory.createLocal(parent, proposal));
                } while (download.getLocal().exists());
                if (log.isInfoEnabled()) {
                    log.info("Changed local name to:" + download.getName());
                }
            }
        }
        // Prunes the list of selected files. Files which are a child of an already included directory
        // are removed from the returned list.
        if (!duplicate) {
            normalized.add(download);
        }
    }
    this.setRoots(normalized);
}

From source file:com.frostwire.search.tbp.TPBSearchResult.java

public TPBSearchResult(String domainName, SearchMatcher matcher) {
    /*/*from  w  w  w .jav a2s.  c  om*/
     * Matcher groups cheatsheet
     * 1 -> Category (useless)
     * 2 -> Torrent Details Page
     * 3 -> Title/Name
     * 4 -> .torrent URL
     * 5 -> infoHash
     * 6 -> MM-DD&nbsp;YYYY or Today&nbsp;HH:MM or Y-day&nbsp;HH:MM 
     * 7 -> SIZE&nbsp;(B|KiB|MiBGiB)
     * 8 -> seeds
     */
    this.detailsUrl = matcher.group(2);
    this.domainName = domainName;
    String temp = HtmlManipulator.replaceHtmlEntities(matcher.group(3));
    temp = HtmlManipulator.replaceHtmlEntities(temp); // because of input
    this.filename = buildFilename(temp);
    this.displayName = FilenameUtils.getBaseName(filename);
    this.torrentUrl = matcher.group(4); //let's assign the magnet to this for now.
    this.infoHash = torrentUrl.substring(20, 60);
    this.creationTime = parseCreationTime(matcher.group(5));
    this.size = parseSize(matcher.group(6));
    this.seeds = parseSeeds(matcher.group(7));
}

From source file:MSUmpire.DIA.TargetHitPepXMLWriter.java

public void write() throws IOException, XmlPullParserException {

    Logger.getRootLogger().info("Writing " + Filename);
    int minlength = Integer.MAX_VALUE;
    int maxlength = 0;
    int maxmiss = 0;

    for (UmpireSpecLibMatch match : Tscoring.libTargetMatches) {
        PepIonID pepIonID = match.pepIonID;
        if (pepIonID.Sequence.length() > maxlength) {
            maxlength = pepIonID.Sequence.length();
        }//from   w  w w  .  j av  a  2 s .  c o  m
        if (pepIonID.Sequence.length() < minlength) {
            minlength = pepIonID.Sequence.length();
        }
        if (pepIonID.getNMissedCleavages() > maxmiss) {
            maxmiss = pepIonID.getNMissedCleavages();
        }
    }

    FastaParser fastaparser = new FastaParser(Fasta);
    fastaparser.RemoveDecoy(Decoytag);
    //FastaParser_V2 fastaparser = FastaParser.FasterSerialzationRead(Fasta);        
    fastaparser.digestion(maxmiss, minlength, maxlength, Decoytag);

    Header();
    sb.append("<msms_run_summary base_name=\"" + FilenameUtils.getBaseName(Filename)
            + "\" search_engine=\"interprophet\" >\n");
    SearchSummary();
    int index = 0;
    for (UmpireSpecLibMatch match : Tscoring.libTargetMatches) {
        //<editor-fold defaultstate="collapsed" desc="Forward hit">            
        PeakGroupScore bestscore = match.BestHit;
        String Sequence = match.pepIonID.Sequence;
        if (bestscore != null) {
            ArrayList<ParentProtein> parentprots = new ArrayList<>();
            if (!fastaparser.PeptideList.containsKey(Sequence)) {
                //Logger.getRootLogger().warn(Sequence + " is not found as tryptic peptides in " + Fasta + ". Searching in protein sequences..");
                for (String acc : fastaparser.ProteinList.keySet()) {
                    String ProtSeq = fastaparser.ProteinList.get(acc).Seq;
                    if (ProtSeq.contains(Sequence)) {
                        ParentProtein prot = new ParentProtein();
                        prot.Acc = acc;
                        prot.Des = fastaparser.ProteinList.get(acc).Des;
                        int aaindex = ProtSeq.indexOf(Sequence) - 1;
                        if (aaindex >= 0) {
                            prot.PreAA = ProtSeq.charAt(aaindex);
                        }
                        aaindex = ProtSeq.indexOf(Sequence) + Sequence.length();
                        if (aaindex < ProtSeq.length()) {
                            prot.NextAA = ProtSeq.charAt(aaindex);
                        }
                        parentprots.add(prot);
                    }
                }
            } else {
                for (String acc : fastaparser.PeptideList.get(Sequence).Proteins) {
                    String ProtSeq = fastaparser.ProteinList.get(acc).Seq;
                    if (ProtSeq.contains(Sequence)) {
                        ParentProtein prot = new ParentProtein();
                        prot.Acc = acc;
                        prot.Des = fastaparser.ProteinList.get(acc).Des;
                        int aaindex = ProtSeq.indexOf(Sequence) - 1;
                        if (aaindex >= 0) {
                            prot.PreAA = ProtSeq.charAt(aaindex);
                        }
                        aaindex = ProtSeq.indexOf(Sequence) + Sequence.length();
                        if (aaindex < ProtSeq.length()) {
                            prot.NextAA = ProtSeq.charAt(aaindex);
                        }
                        parentprots.add(prot);
                    }
                }
            }

            if (parentprots.isEmpty()) {
                Logger.getRootLogger().warn(Sequence + " is not found in " + Fasta);
            } else {
                sb.append("<spectrum_query spectrum=\"" + FilenameUtils.getBaseName(Filename) + "." + index
                        + "." + index + "." + match.pepIonID.Charge + "\" start_scan=\"" + index
                        + "\" end_scan=\"" + index + "\" precursor_neutral_mass=\""
                        + bestscore.PrecursorNeutralMass + "\" assumed_charge=\"" + match.pepIonID.Charge
                        + "\" index=\"" + (index++) + "\" retention_time_sec=\"" + bestscore.PrecursorRT * 60f
                        + "\">\n" + "<search_result>\n" + "<search_hit hit_rank=\"1\" peptide=\"" + Sequence
                        + "\" peptide_prev_aa=\"" + parentprots.get(0).PreAA + "\" peptide_next_aa=\""
                        + parentprots.get(0).NextAA + "\" protein=\"" + parentprots.get(0).Acc
                        + "\" protein_descr=\"" + parentprots.get(0).Des + "\" num_tot_proteins=\""
                        + parentprots.size() + "\" num_matched_ions=\""
                        + (bestscore.NoMatchB + bestscore.NoMatchY) + "\" tot_num_ions=\""
                        + 2 * (Sequence.length() - 1) + "\" calc_neutral_pep_mass=\""
                        + match.pepIonID.CalcNeutralPepMass() + "\" massdiff=\""
                        + (match.pepIonID.CalcNeutralPepMass() - bestscore.PrecursorNeutralMass)
                        + "\"  num_tol_term=\"2\" num_missed_cleavages=\""
                        + match.pepIonID.getNMissedCleavages() + "\" is_rejected=\"0\">\n");

                for (int i = 1; i < parentprots.size(); i++) {
                    sb.append("<alternative_protein protein=\"" + parentprots.get(i).Acc + "\" protein_descr=\""
                            + parentprots.get(i).Des + "\" num_tol_term=\"2\" peptide_prev_aa=\""
                            + parentprots.get(i).PreAA + "\" peptide_next_aa=\"" + parentprots.get(i).NextAA
                            + "\"/>");
                }
                //                        + "<modification_info modified_peptide=\"KITIADCGQLE\">\n"
                //                        + "<mod_aminoacid_mass position=\"7\" mass=\"160.0306\"/>\n"
                //                        + "</modification_info>\n"
                //                        + "<analysis_result analysis=\"peptideprophet\">\n"
                //                        + "<peptideprophet_result probability=\"0.8297\" all_ntt_prob=\"(0.0059,0.3657,0.8297)\">\n"
                //                        + "<search_score_summary>\n"
                //                        + "<parameter name=\"fval\" value=\"1.6872\"/>\n"
                //                        + "<parameter name=\"ntt\" value=\"2\"/>\n"
                //                        + "<parameter name=\"nmc\" value=\"0\"/>\n"
                //                        + "<parameter name=\"massd\" value=\"4.011\"/>\n"
                //                        + "<parameter name=\"isomassd\" value=\"0\"/>\n"
                //                        + "</search_score_summary>\n"
                //                        + "</peptideprophet_result>\n"
                //                        + "</analysis_result>\n"
                sb.append("<analysis_result analysis=\"interprophet\">\n"
                        + "<interprophet_result probability=\"" + bestscore.MixtureModelLocalProb
                        + "\" all_ntt_prob=\"(" + bestscore.MixtureModelLocalProb + ","
                        + bestscore.MixtureModelLocalProb + "," + bestscore.MixtureModelLocalProb + ")\">\n"
                        //                        + "<search_score_summary>\n"
                        //                        + "<parameter name=\"nrs\" value=\"0\"/>\n"
                        //                        + "<parameter name=\"nsi\" value=\"0\"/>\n"
                        //                        + "<parameter name=\"nsm\" value=\"0\"/>\n"
                        //                        + "</search_score_summary>\n"
                        + "</interprophet_result>\n" + "</analysis_result>\n" + "</search_hit>\n"
                        + "</search_result>\n" + "</spectrum_query>\n");
            }
        }
        //</editor-fold>

        //<editor-fold defaultstate="collapsed" desc="Decoy hit">
        bestscore = match.BestDecoyHit;
        if (!fastaparser.PeptideList.containsKey(Sequence)) {
            continue;
        }
        String DecoySeq = fastaparser.PeptideList.get(Sequence).Decoy;
        if (bestscore != null) {
            ArrayList<ParentProtein> parentprots = new ArrayList<>();
            if (!fastaparser.PeptideList.containsKey(Sequence)) {
                //Logger.getRootLogger().warn(Sequence + " is not found as tryptic peptides in " + Fasta + ". Searching in protein sequences..");
                for (String acc : fastaparser.ProteinList.keySet()) {
                    String ProtSeq = fastaparser.ProteinList.get(acc).Seq;
                    if (ProtSeq.contains(Sequence)) {
                        ParentProtein prot = new ParentProtein();
                        prot.Acc = acc;
                        prot.Des = fastaparser.ProteinList.get(acc).Des;
                        int aaindex = ProtSeq.indexOf(Sequence) - 1;
                        if (aaindex >= 0) {
                            prot.PreAA = ProtSeq.charAt(aaindex);
                        }
                        aaindex = ProtSeq.indexOf(Sequence) + Sequence.length();
                        if (aaindex < ProtSeq.length()) {
                            prot.NextAA = ProtSeq.charAt(aaindex);
                        }
                        parentprots.add(prot);
                    }
                }
            } else {
                for (String acc : fastaparser.PeptideList.get(Sequence).Proteins) {
                    String ProtSeq = fastaparser.ProteinList.get(acc).Seq;
                    if (ProtSeq.contains(Sequence)) {
                        ParentProtein prot = new ParentProtein();
                        prot.Acc = acc;
                        prot.Des = fastaparser.ProteinList.get(acc).Des;
                        int aaindex = ProtSeq.indexOf(Sequence) - 1;
                        if (aaindex >= 0) {
                            prot.PreAA = ProtSeq.charAt(aaindex);
                        }
                        aaindex = ProtSeq.indexOf(Sequence) + Sequence.length();
                        if (aaindex < ProtSeq.length()) {
                            prot.NextAA = ProtSeq.charAt(aaindex);
                        }
                        parentprots.add(prot);
                    }
                }
            }

            if (parentprots.isEmpty()) {
                Logger.getRootLogger().warn(Sequence + " is not found in " + Fasta);
            } else {
                sb.append("<spectrum_query spectrum=\"" + Decoytag + "_" + Sequence
                        + "\" precursor_neutral_mass=\"" + bestscore.PrecursorNeutralMass
                        + "\" assumed_charge=\"" + match.pepIonID.Charge + "\" index=\"" + (index++)
                        + "\" retention_time_sec=\"" + bestscore.PrecursorRT * 60f + "\">\n"
                        + "<search_result>\n" + "<search_hit hit_rank=\"1\" peptide=\"" + DecoySeq
                        + "\" peptide_prev_aa=\"" + parentprots.get(0).PreAA + "\" peptide_next_aa=\""
                        + parentprots.get(0).NextAA + "\" protein=\"" + Decoytag + "_" + parentprots.get(0).Acc
                        + "\" protein_descr=\"" + Decoytag + "_" + parentprots.get(0).Des
                        + "\" num_tot_proteins=\"" + parentprots.size() + "\" num_matched_ions=\""
                        + (bestscore.NoMatchB + bestscore.NoMatchY) + "\" tot_num_ions=\""
                        + 2 * (Sequence.length() - 1) + "\" calc_neutral_pep_mass=\""
                        + match.pepIonID.CalcNeutralPepMass() + "\" massdiff=\""
                        + (match.pepIonID.CalcNeutralPepMass() - bestscore.PrecursorNeutralMass)
                        + "\" num_missed_cleavages=\"" + match.pepIonID.getNMissedCleavages()
                        + "\" is_rejected=\"0\">\n");

                for (int i = 1; i < parentprots.size(); i++) {
                    sb.append("<alternative_protein protein=\"" + Decoytag + "_" + parentprots.get(i).Acc
                            + "\" protein_descr=\"" + Decoytag + "_" + parentprots.get(i).Des
                            + "\" num_tol_term=\"2\" peptide_prev_aa=\"" + parentprots.get(i).PreAA
                            + "\" peptide_next_aa=\"" + parentprots.get(i).NextAA + "\"/>");
                }
                //                        + "<modification_info modified_peptide=\"KITIADCGQLE\">\n"
                //                        + "<mod_aminoacid_mass position=\"7\" mass=\"160.0306\"/>\n"
                //                        + "</modification_info>\n"
                //                        + "<analysis_result analysis=\"peptideprophet\">\n"
                //                        + "<peptideprophet_result probability=\"0.8297\" all_ntt_prob=\"(0.0059,0.3657,0.8297)\">\n"
                //                        + "<search_score_summary>\n"
                //                        + "<parameter name=\"fval\" value=\"1.6872\"/>\n"
                //                        + "<parameter name=\"ntt\" value=\"2\"/>\n"
                //                        + "<parameter name=\"nmc\" value=\"0\"/>\n"
                //                        + "<parameter name=\"massd\" value=\"4.011\"/>\n"
                //                        + "<parameter name=\"isomassd\" value=\"0\"/>\n"
                //                        + "</search_score_summary>\n"
                //                        + "</peptideprophet_result>\n"
                //                        + "</analysis_result>\n"
                sb.append("<analysis_result analysis=\"interprophet\">\n"
                        + "<interprophet_result probability=\"" + bestscore.MixtureModelLocalProb
                        + "\" all_ntt_prob=\"(" + bestscore.MixtureModelLocalProb + ","
                        + bestscore.MixtureModelLocalProb + "," + bestscore.MixtureModelLocalProb + ")\">\n"
                        //                        + "<search_score_summary>\n"
                        //                        + "<parameter name=\"nrs\" value=\"0\"/>\n"
                        //                        + "<parameter name=\"nsi\" value=\"0\"/>\n"
                        //                        + "<parameter name=\"nsm\" value=\"0\"/>\n"
                        //                        + "</search_score_summary>\n"
                        + "</interprophet_result>\n" + "</analysis_result>\n" + "</search_hit>\n"
                        + "</search_result>\n" + "</spectrum_query>\n");
            }
        }

        //</editor-fold>
    }
    sb.append("</msms_run_summary>\n");
    sb.append("</msms_pipeline_analysis>\n");
    FileWriter writer = new FileWriter(Filename);
    writer.write(sb.toString());
    writer.close();
}

From source file:ch.mlutz.plugins.t4e.tapestry.element.TapestryHtmlElement.java

public String getPath() {
    StringBuilder sb = new StringBuilder();
    IContainer webAppFolder = parent.getWebappFolder();
    IContainer currentContainer = htmlFile.getParent();
    while (!currentContainer.equals(webAppFolder)) {
        if (sb.length() > 0) {
            sb.insert(0, "/");
        }//from w  w  w  .j  a v  a  2  s.  c  o  m
        sb.insert(0, currentContainer.getName());
        currentContainer = currentContainer.getParent();
    }
    if (sb.length() > 0) {
        sb.append("/");
    }
    sb.append(FilenameUtils.getBaseName(htmlFile.getName()));
    return sb.toString();
}

From source file:it.geosolutions.geobatch.destination.action.datamigration.RasterMigrationAction.java

@Override
public Queue<EventObject> execute(Queue<EventObject> events) throws ActionException {
    listenerForwarder.setTask("Check configuration");
    checkConfiguration();//  www.  ja  v  a 2  s.  c  o  m
    // Creation of a List containing the event objects
    final LinkedList<EventObject> ret = new LinkedList<EventObject>();
    try {
        // Start of the operations
        listenerForwarder.started();
        // Until the events are present, the input files are elaborated
        while (!events.isEmpty()) {
            // Each event is polled from the list
            EventObject event = events.poll();
            if (event instanceof FileSystemEvent) {
                FileSystemEvent fse = (FileSystemEvent) event;
                File file = fse.getSource();
                // Copy
                doProcess(FilenameUtils.getBaseName(file.getName()));
            }
            // pass the feature config to the next action
            ret.add(new FileSystemEvent(((FileSystemEvent) event).getSource(), FileSystemEventType.FILE_ADDED));
        }
        listenerForwarder.completed();
        return ret;
    } catch (Exception t) {
        listenerForwarder.failed(t);
        throw new ActionException(this, t.getMessage(), t);
    }
}