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:de.uzk.hki.da.format.PublishVideoConversionStrategy.java

@Override
public List<Event> convertFile(ConversionInstruction ci) throws FileNotFoundException {
    if (pkg == null)
        throw new IllegalStateException("pkg not set");

    List<Event> results = new ArrayList<Event>();

    Path.makeFile(object.getDataPath(), pips, "public", ci.getTarget_folder()).mkdirs();
    Path.makeFile(object.getDataPath(), pips, "institution", ci.getTarget_folder()).mkdirs();

    String cmdPUBLIC[] = new String[] { "HandBrakeCLI", "-i",
            ci.getSource_file().toRegularFile().getAbsolutePath(), "-o",
            object.getDataPath() + "/" + pips.toString() + "/public/"
                    + Utilities.slashize(ci.getTarget_folder())
                    + FilenameUtils.getBaseName(ci.getSource_file().toRegularFile().getAbsolutePath()) + ".mp4",
            "-e", "x264", "-f", "mp4", "-E", "faac" };

    cmdPUBLIC = (String[]) ArrayUtils.addAll(cmdPUBLIC, getRestrictionParametersForAudience("PUBLIC"));

    DAFile pubFile = new DAFile(pkg, pips + "/public", Utilities.slashize(ci.getTarget_folder())
            + FilenameUtils.getBaseName(ci.getSource_file().toRegularFile().getAbsolutePath()) + ".mp4");

    if (!executeConversionTool(cmdPUBLIC, pubFile.toRegularFile()))
        throw new RuntimeException("command not succeeded: " + Arrays.toString(cmdPUBLIC));

    Event e = new Event();
    e.setType("CONVERT");
    e.setDetail(Utilities.createString(cmdPUBLIC));
    e.setSource_file(ci.getSource_file());
    e.setTarget_file(pubFile);//from ww  w.ja  va2 s .  c om
    e.setDate(new Date());

    String cmdINSTITUTION[] = new String[] { "HandBrakeCLI", "-i",
            ci.getSource_file().toRegularFile().getAbsolutePath(), "-o",
            object.getDataPath() + "/" + pips + "/institution/" + Utilities.slashize(ci.getTarget_folder())
                    + FilenameUtils.getBaseName(ci.getSource_file().toRegularFile().getAbsolutePath()) + ".mp4",
            "-e", "x264", "-f", "mp4", "-E", "faac" };

    cmdINSTITUTION = (String[]) ArrayUtils.addAll(cmdINSTITUTION,
            getRestrictionParametersForAudience("INSTITUTION"));

    DAFile instFile = new DAFile(pkg, "dip/institution", Utilities.slashize(ci.getTarget_folder())
            + FilenameUtils.getBaseName(ci.getSource_file().toRegularFile().getAbsolutePath()) + ".mp4");

    if (!executeConversionTool(cmdINSTITUTION, instFile.toRegularFile()))
        throw new RuntimeException("command not succeeded: " + Arrays.toString(cmdINSTITUTION));

    Event e2 = new Event();
    e2.setType("CONVERT");
    e2.setDetail(Utilities.createString(cmdINSTITUTION));
    e2.setSource_file(ci.getSource_file());
    e2.setTarget_file(instFile);

    results.add(e);
    results.add(e2);

    return results;
}

From source file:io.wcm.devops.conga.plugins.aem.postprocessor.ContentPackagePostProcessor.java

@Override
public List<FileContext> apply(FileContext fileContext, PostProcessorContext context) {
    File file = fileContext.getFile();
    Logger logger = context.getLogger();
    Map<String, Object> options = context.getOptions();

    try {//w w  w  . j a  v a2s.c om
        // extract file header
        FileHeaderContext fileHeader = extractFileHeader(fileContext, context);

        // create AEM content package with configurations
        File zipFile = new File(file.getParentFile(), FilenameUtils.getBaseName(file.getName()) + ".zip");
        logger.info("Generate " + zipFile.getCanonicalPath());

        String rootPath = ContentPackageUtil.getMandatoryProp(options, PROPERTY_PACKAGE_ROOT_PATH);

        ContentPackageBuilder builder = ContentPackageUtil.getContentPackageBuilder(options, fileHeader);
        try (ContentPackage contentPackage = builder.build(zipFile)) {

            // add content from JSON file
            ContentElement content = jsonContentLoader.load(fileContext.getFile());
            contentPackage.addContent(rootPath, content);

            // add additional binary files
            for (ContentPackageBinaryFile binaryFile : ContentPackageUtil.getFiles(options)) {
                String path = binaryFile.getPath();
                try (InputStream is = binaryFile.getInputStream(context.getUrlFileManager(),
                        fileContext.getTargetDir())) {
                    contentPackage.addFile(path, is);
                }
                binaryFile.deleteIfRequired(context.getUrlFileManager(), fileContext.getTargetDir());
            }

        }

        // delete provisioning file after transformation
        file.delete();

        // set force to true by default for CONGA-generated packages (but allow override from role definition)
        Map<String, Object> modelOptions = new HashMap<>();
        modelOptions.put("force", true);
        modelOptions.putAll(fileContext.getModelOptions());

        return ImmutableList.of(new FileContext().file(zipFile).modelOptions(modelOptions));
    } catch (IOException ex) {
        throw new GeneratorException(
                "Unable to post-process JSON data file: " + FileUtil.getCanonicalPath(file), ex);
    }
}

From source file:com.blueverdi.rosietheriveter.AlbumPageFactory.java

public AlbumPage getAlbumPage(int index) {
    if (index < 0) {
        throw new IllegalArgumentException("index < 0");
    }/*from w  ww .  ja  v a2  s  .c  o  m*/
    if (index >= imageFiles.length) {
        throw new IllegalArgumentException("index too large");
    }
    AlbumPage ret = new AlbumPage();
    ret.BitmapName = getBitmapName(imageFiles[index]);
    ret.bitmap = getBitmapFromAssets(ret.BitmapName);
    String audioFileName = FilenameUtils.concat(audioSource,
            FilenameUtils.getBaseName(imageFiles[index]) + ".mp3");
    ret.mp3 = null;
    try {
        context.getAssets().open(audioFileName);
        ret.mp3 = audioFileName;

    } catch (IOException ex) {

    }
    return ret;
}

From source file:com.frostwire.android.gui.transfers.AzureusBittorrentDownload.java

public AzureusBittorrentDownload(TransferManager manager, DownloadManager downloadManager) {
    this.manager = manager;
    this.downloadManager = downloadManager;

    try {/*from  www.  ja  va2s  .  c o m*/
        hash = TorrentUtil.hashToString(downloadManager.getTorrent().getHash());
    } catch (Throwable e) {
        Log.e(TAG, String.format("Error getting hash %s", e.getMessage()));
        hash = "";
    }

    fileInfoSet = TorrentUtil.getNoSkippedFileInfoSet(downloadManager);
    partialDownload = !TorrentUtil.getSkippedFiles(downloadManager).isEmpty();

    if (partialDownload) {
        if (fileInfoSet.isEmpty()) {
            size = downloadManager.getSize();
        } else {
            size = 0;
            for (DiskManagerFileInfo fileInfo : fileInfoSet) {
                size += fileInfo.getLength();
            }
        }
    } else {
        size = downloadManager.getSize();
    }

    if (fileInfoSet.size() == 1) {
        displayName = FilenameUtils
                .getBaseName(fileInfoSet.toArray(new DiskManagerFileInfo[0])[0].getFile(false).getName());
    } else {
        displayName = downloadManager.getDisplayName();
    }

    items = new ArrayList<BittorrentDownloadItem>(fileInfoSet.size());
    for (DiskManagerFileInfo fileInfo : fileInfoSet) {
        items.add(new AzureusBittorrentDownloadItem(fileInfo));
    }
}

From source file:de.uzk.hki.da.convert.PublishVideoConversionStrategy.java

@Override
public List<Event> convertFile(WorkArea wa, ConversionInstruction ci) throws FileNotFoundException {
    if (pkg == null)
        throw new IllegalStateException("pkg not set");

    List<Event> results = new ArrayList<Event>();

    Path.makeFile(wa.dataPath(), pips, "public", ci.getTarget_folder()).mkdirs();
    Path.makeFile(wa.dataPath(), pips, "institution", ci.getTarget_folder()).mkdirs();

    String cmdPUBLIC[] = new String[] { "HandBrakeCLI", "-i", wa.toFile(ci.getSource_file()).getAbsolutePath(),
            "-o",
            wa.dataPath() + "/" + pips.toString() + "/public/" + StringUtilities.slashize(ci.getTarget_folder())
                    + FilenameUtils.getBaseName(wa.toFile(ci.getSource_file()).getAbsolutePath()) + ".mp4",
            "-e", "x264", "-f", "mp4", "-E", "faac" };

    cmdPUBLIC = (String[]) ArrayUtils.addAll(cmdPUBLIC, getRestrictionParametersForAudience("PUBLIC"));

    DAFile pubFile = new DAFile(pips + "/public", StringUtilities.slashize(ci.getTarget_folder())
            + FilenameUtils.getBaseName(wa.toFile(ci.getSource_file()).getAbsolutePath()) + ".mp4");

    if (!executeConversionTool(cmdPUBLIC, wa.toFile(pubFile)))
        throw new RuntimeException("command not succeeded: " + Arrays.toString(cmdPUBLIC));

    Event e = new Event();
    e.setType("CONVERT");
    e.setDetail(StringUtilities.createString(cmdPUBLIC));
    e.setSource_file(ci.getSource_file());
    e.setTarget_file(pubFile);//from  www.  ja v a 2 s . co  m
    e.setDate(new Date());

    String cmdINSTITUTION[] = new String[] { "HandBrakeCLI", "-i",
            wa.toFile(ci.getSource_file()).getAbsolutePath(), "-o",
            wa.dataPath() + "/" + pips + "/institution/" + StringUtilities.slashize(ci.getTarget_folder())
                    + FilenameUtils.getBaseName(wa.toFile(ci.getSource_file()).getAbsolutePath()) + ".mp4",
            "-e", "x264", "-f", "mp4", "-E", "faac" };

    cmdINSTITUTION = (String[]) ArrayUtils.addAll(cmdINSTITUTION,
            getRestrictionParametersForAudience("INSTITUTION"));

    DAFile instFile = new DAFile(WorkArea.TMP_PIPS + "/institution",
            StringUtilities.slashize(ci.getTarget_folder())
                    + FilenameUtils.getBaseName(wa.toFile(ci.getSource_file()).getAbsolutePath()) + ".mp4");

    if (!executeConversionTool(cmdINSTITUTION, wa.toFile(instFile)))
        throw new RuntimeException("command not succeeded: " + Arrays.toString(cmdINSTITUTION));

    Event e2 = new Event();
    e2.setType("CONVERT");
    e2.setDetail(StringUtilities.createString(cmdINSTITUTION));
    e2.setSource_file(ci.getSource_file());
    e2.setTarget_file(instFile);

    results.add(e);
    results.add(e2);

    return results;
}

From source file:MSUmpire.SearchResultWriter.PepXMLWriter.java

public void Write() throws IOException, XmlPullParserException {
    int minlength = Integer.MAX_VALUE;
    int maxlength = 0;
    int maxmiss = 0;
    for (PepIonID pepIonID : PepList) {
        if (pepIonID.Sequence.length() > maxlength) {
            maxlength = pepIonID.Sequence.length();
        }/*  w w w.  j  a  va  2  s.c o  m*/
        if (pepIonID.Sequence.length() < minlength) {
            minlength = pepIonID.Sequence.length();
        }
        if (pepIonID.getNMissedCleavages() > maxmiss) {
            maxmiss = pepIonID.getNMissedCleavages();
        }
    }

    FastaParser_V2 fastaparser = FastaParser_V2.FasterSerialzationRead(Fasta);
    if (fastaparser == null) {
        fastaparser = new FastaParser_V2(Fasta);
        fastaparser.digestion(maxmiss, minlength, maxlength, "DECOY");
    }
    Header();
    sb.append("<msms_run_summary base_name=\"" + FilenameUtils.getBaseName(Filename)
            + "\" search_engine=\"Umpire\" >\n");
    SearchSummary();
    int index = 0;
    for (PepIonID pepIonID : PepList) {
        ArrayList<ParentProtein> parentprots = new ArrayList<>();
        if (!fastaparser.PeptideList.containsKey(pepIonID.Sequence)) {
            Logger.getRootLogger().warn(pepIonID.Sequence + " is not found as tryptic peptides in " + Fasta
                    + ". Searching protein sequences..");
            for (String acc : fastaparser.ProteinList.keySet()) {
                String ProtSeq = fastaparser.ProteinList.get(acc).Seq;
                if (ProtSeq.contains(pepIonID.Sequence)) {
                    ParentProtein prot = new ParentProtein();
                    prot.Acc = acc;
                    prot.Des = fastaparser.ProteinList.get(acc).Des;
                    int aaindex = ProtSeq.indexOf(pepIonID.Sequence) - 1;
                    if (aaindex >= 0) {
                        prot.PreAA = ProtSeq.charAt(aaindex);
                    }
                    aaindex = ProtSeq.indexOf(pepIonID.Sequence) + pepIonID.Sequence.length();
                    if (aaindex < ProtSeq.length()) {
                        prot.NextAA = ProtSeq.charAt(aaindex);
                    }
                    parentprots.add(prot);
                }
            }
        } else {
            for (String acc : fastaparser.PeptideList.get(pepIonID.Sequence).Proteins) {
                String ProtSeq = fastaparser.ProteinList.get(acc).Seq;
                if (ProtSeq.contains(pepIonID.Sequence)) {
                    ParentProtein prot = new ParentProtein();
                    prot.Acc = acc;
                    prot.Des = fastaparser.ProteinList.get(acc).Des;
                    int aaindex = ProtSeq.indexOf(pepIonID.Sequence) - 1;
                    if (aaindex >= 0) {
                        prot.PreAA = ProtSeq.charAt(aaindex);
                    }
                    aaindex = ProtSeq.indexOf(pepIonID.Sequence) + pepIonID.Sequence.length();
                    if (aaindex < ProtSeq.length()) {
                        prot.NextAA = ProtSeq.charAt(aaindex);
                    }
                    parentprots.add(prot);
                }
            }
        }

        if (parentprots.isEmpty()) {
            Logger.getRootLogger().warn(pepIonID.Sequence + " is not found in " + Fasta);
        } else {
            sb.append("<spectrum_query spectrum=\"" + pepIonID.GetKey() + "\" precursor_neutral_mass=\""
                    + pepIonID.CalcNeutralPepMass() + "\" assumed_charge=\"" + pepIonID.Charge + "\" index=\""
                    + (index++) + "\" retention_time_sec=\"" + pepIonID.PeakRT * 60f + "\">\n"
                    + "<search_result>\n" + "<search_hit hit_rank=\"1\" peptide=\"" + pepIonID.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=\"" + pepIonID.GetFragCount()
                    + "\" tot_num_ions=\"" + 2 * (pepIonID.Sequence.length() - 1)
                    + "\" calc_neutral_pep_mass=\"" + pepIonID.CalcNeutralPepMass() + "\" massdiff=\""
                    + (pepIonID.CalcNeutralPepMass() - pepIonID.ObservedMass()) + "\" num_missed_cleavages=\""
                    + 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=\""
                    + pepIonID.TargetedProbability() + "\">\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");
        }

    }
    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:com.fluidops.iwb.api.solution.AbstractSingleFileBasedSolutionService.java

/**
 * @param solution//from   w  ww.j  a v a2s  .  com
 * @return
 */
public SolutionInfo readSolutionInfo(File solution) {
    VersionInfo info = readVersionInfo(solution);
    if (info == null) {
        info = new VersionInfo();
    }
    if (StringUtil.isNullOrEmpty(info.getCanonicalProductName())) {
        // no product name set, use solution file name (without extension) as product name
        String name = FilenameUtils.getBaseName(solution.getName());
        info.setProductName(name);
    }

    return new SolutionInfoImpl(info);
}

From source file:com.frostwire.gui.bittorrent.SoundcloudDownload.java

public SoundcloudDownload(SoundcloudSearchResult sr) {
    this.sr = sr;
    this.size = sr.getSize();

    String filename = sr.getFilename();

    completeFile = buildFile(SharingSettings.TORRENT_DATA_DIR_SETTING.getValue(), filename);
    tempAudio = buildTempFile(FilenameUtils.getBaseName(filename), "audio");

    bytesReceived = 0;//from ww  w  . jav a 2 s  .c om
    dateCreated = new Date();

    httpClientListener = new HttpDownloadListenerImpl();

    httpClient = HttpClientFactory.newInstance();
    httpClient.setListener(httpClientListener);

    start();
}

From source file:com.frostwire.gui.bittorrent.YouTubeDownload.java

public YouTubeDownload(YouTubeCrawledSearchResult sr) {
    this.sr = sr;
    this.downloadType = buildDownloadType(sr);
    this.size = sr.getSize();

    String filename = sr.getFilename();

    completeFile = buildFile(SharingSettings.TORRENT_DATA_DIR_SETTING.getValue(), filename);
    tempVideo = buildTempFile(FilenameUtils.getBaseName(filename), "video");
    tempAudio = buildTempFile(FilenameUtils.getBaseName(filename), "audio");

    bytesReceived = 0;//from   w w w  . ja  va 2  s .co  m
    dateCreated = new Date();

    httpClientListener = new HttpDownloadListenerImpl();

    httpClient = HttpClientFactory.newInstance();
    httpClient.setListener(httpClientListener);

    start();
}

From source file:com.artofsolving.jodconverter.web.DocumentConverterServlet.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    ApplicationContext applicationContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(getServletContext());
    ServletFileUpload fileUpload = (ServletFileUpload) applicationContext.getBean("fileUpload");
    DocumentConverter converter = (DocumentConverter) applicationContext.getBean("documentConverter");
    DocumentFormatRegistry registry = (DocumentFormatRegistry) applicationContext
            .getBean("documentFormatRegistry");

    if (!ServletFileUpload.isMultipartContent(request)) {
        throw new IllegalArgumentException("request is not multipart");
    }/*from w  w w. j av  a  2s .  c o m*/

    // determine output format based on the request uri
    String outputExtension = FilenameUtils.getExtension(request.getRequestURI());
    DocumentFormat outputFormat = registry.getFormatByFileExtension(outputExtension);
    if (outputFormat == null) {
        throw new IllegalArgumentException("invalid outputFormat: " + outputExtension);
    }

    FileItem inputFileUpload = getInputFileUpload(request, fileUpload);
    if (inputFileUpload == null) {
        throw new IllegalArgumentException("inputDocument is null");
    }
    String inputExtension = FilenameUtils.getExtension(inputFileUpload.getName());
    DocumentFormat inputFormat = registry.getFormatByFileExtension(inputExtension);

    response.setContentType(outputFormat.getMimeType());
    String fileName = FilenameUtils.getBaseName(inputFileUpload.getName()) + "."
            + outputFormat.getFileExtension();
    response.setHeader("Content-Disposition", "inline; filename=" + fileName);
    //response.setContentLength(???);

    converter.convert(inputFileUpload.getInputStream(), inputFormat, response.getOutputStream(), outputFormat);
}