Java Code Examples for org.apache.commons.io.FilenameUtils.getBaseName()

The following are Jave code examples for showing how to use getBaseName() of the org.apache.commons.io.FilenameUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jbake-rtl-jalaali   File: Crawler.java   View Source Code Vote up 6 votes
private String buildURI(final File sourceFile) {
	String uri = FileUtil.asPath(sourceFile.getPath()).replace(FileUtil.asPath( contentPath), "");

	boolean noExtensionUri = config.getBoolean(Keys.URI_NO_EXTENSION);
	String noExtensionUriPrefix = config.getString(Keys.URI_NO_EXTENSION_PREFIX);
	if (noExtensionUri && noExtensionUriPrefix != null && noExtensionUriPrefix.length() > 0) {
    	// convert URI from xxx.html to xxx/index.html
		if (uri.startsWith(noExtensionUriPrefix)) {
			uri = "/" + FilenameUtils.getPath(uri) + FilenameUtils.getBaseName(uri) + "/index" + config.getString(Keys.OUTPUT_EXTENSION);
		}
    } else {
        uri = uri.substring(0, uri.lastIndexOf(".")) + config.getString(Keys.OUTPUT_EXTENSION);
    }

    // strip off leading / to enable generating non-root based sites
	if (uri.startsWith("/")) {
		uri = uri.substring(1, uri.length());
	}
    return uri;
}
 
Example 2
Project: DIA-Umpire-Maven   File: LCMSPeakBase.java   View Source Code Vote up 6 votes
private boolean JavaSerializationPeakClusterRead() {
    if (!new File(FilenameUtils.getFullPath(ParentmzXMLName) + FilenameUtils.getBaseName(ParentmzXMLName) + "_Peak/" + FilenameUtils.getBaseName(ScanCollectionName) + "_PeakCluster.ser").exists()) {
        return false;
    }
    try {
        Logger.getRootLogger().info("Reading PeakCluster serialization from file:" + FilenameUtils.getBaseName(ScanCollectionName) + "_PeakCluster.ser...");

        FileInputStream fileIn = new FileInputStream(FilenameUtils.getFullPath(ParentmzXMLName) + FilenameUtils.getBaseName(ParentmzXMLName) + "_Peak/" + FilenameUtils.getBaseName(ScanCollectionName) + "_PeakCluster.ser");
        ObjectInputStream in = new ObjectInputStream(fileIn);
        PeakClusters = (ArrayList<PeakCluster>) in.readObject();
        in.close();
        fileIn.close();
    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        return false;
    }
    return true;
}
 
Example 3
Project: DIA-Umpire-Maven   File: FastaParser.java   View Source Code Vote up 6 votes
public static FastaParser FasterSerialzationRead(String Filename) throws FileNotFoundException {

        if (!new File(FilenameUtils.getFullPath(Filename) + FilenameUtils.getBaseName(Filename) + ".FastaSer").exists()) {
            return null;
        }
        FastaParser fastareader = null;
        try {
            org.apache.log4j.Logger.getRootLogger().info("Loading fasta serialization to file:" + FilenameUtils.getFullPath(Filename) + FilenameUtils.getBaseName(Filename) + ".FastaSer..");
            FileInputStream fileIn = new FileInputStream(FilenameUtils.getFullPath(Filename) + FilenameUtils.getBaseName(Filename) + ".FastaSer");
            FSTObjectInput in = new FSTObjectInput(fileIn);
            fastareader = (FastaParser) in.readObject();
            in.close();
            fileIn.close();
        } catch (Exception ex) {
            org.apache.log4j.Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
            return null;
        }

        return fastareader;
    }
 
Example 4
Project: AccessConverter   File: AccessConverter.java   View Source Code Vote up 6 votes
private static File getOutputFile(String extension) {
    outputFilename = args.HasOption("output-file") ? 
            args.GetOption("output-file") : 
            FilenameUtils.getBaseName(args.GetOption("access-file")) + "." + extension;
    
    File outFile = new File(FilenameUtils.concat(FilenameUtils.getFullPath(args.GetOption("access-file")), outputFilename));
    if(outFile.exists()) {
        try {
            outFile.delete();
        } catch(SecurityException e) {
            Error(String.format("Could not delete existing output file '%s'", outputFilename));
            return null;
        }
    }
    
    return outFile;
}
 
Example 5
Project: s3-proxy-chunk-upload   File: VideoConverter.java   View Source Code Vote up 6 votes
private String createSuffixUrl(String inputUrl, String suffix) {
    String outputUrl = "";

    if(suffix.equals(STREAM)) {
        if (inputUrl.endsWith(VIDEO_EXTENSION)) {
            String name = FilenameUtils.getBaseName(inputUrl);
            String outName = name.replace(VIDEO_EXTENSION, "");
            outName = outName + '/' + STREAM;
            outputUrl = inputUrl.replace(name + VIDEO_EXTENSION, outName);
        }
    } else {
        if (inputUrl.endsWith(VIDEO_EXTENSION)) {
            outputUrl = inputUrl.replace(VIDEO_EXTENSION, suffix + VIDEO_EXTENSION);
        }
    }

    return outputUrl;
}
 
Example 6
Project: DIA-Umpire-Maven   File: InstrumentParameter.java   View Source Code Vote up 6 votes
public static InstrumentParameter ReadParametersSerialization(String filepath) {
    if (!new File(FilenameUtils.getFullPath(filepath) + FilenameUtils.getBaseName(filepath) + "_params.ser").exists()) {
        return null;
    }
    try {
        Logger.getRootLogger().info("Reading parameters from file:" + FilenameUtils.getFullPath(filepath) + FilenameUtils.getBaseName(filepath) + "_params.ser...");

        FileInputStream fileIn = new FileInputStream(FilenameUtils.getFullPath(filepath) + FilenameUtils.getBaseName(filepath) + "_params.ser");
        ObjectInputStream in = new ObjectInputStream(fileIn);
        InstrumentParameter params = (InstrumentParameter) in.readObject();
        in.close();
        fileIn.close();
        return params;

    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        return null;
    }
}
 
Example 7
Project: DIA-Umpire-Maven   File: LCMSPeakDIAMS2.java   View Source Code Vote up 6 votes
private boolean FSCluster2CurveRead() {
    if (!new File(FilenameUtils.getFullPath(ParentmzXMLName) + FilenameUtils.getBaseName(ParentmzXMLName) + "_Peak/" + FilenameUtils.getBaseName(ScanCollectionName) + "_Clus2Cur.serFS").exists()) {
        return false;
    }
    try {
        Logger.getRootLogger().debug("Reading PrecursorFragmentCorr serialization from file:" + FilenameUtils.getBaseName(ScanCollectionName) + "_Clus2Cur.serFS...");
        FileInputStream fileIn = new FileInputStream(FilenameUtils.getFullPath(ParentmzXMLName) + FilenameUtils.getBaseName(ParentmzXMLName) + "_Peak/" + FilenameUtils.getBaseName(ScanCollectionName) + "_Clus2Cur.serFS");
        FSTObjectInput in = new FSTObjectInput(fileIn);
        FragmentsClu2Cur = (HashMap<Integer, ArrayList<PrecursorFragmentPairEdge>>) in.readObject();
        in.close();
        fileIn.close();

    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        return false;
    }
    return true;
}
 
Example 8
Project: DIA-Umpire-Maven   File: LCMSPeakBase.java   View Source Code Vote up 6 votes
private boolean FS_PeakClusterRead() {
    if (!new File(FilenameUtils.getFullPath(ParentmzXMLName) + FilenameUtils.getBaseName(ParentmzXMLName) + "_Peak/" + FilenameUtils.getBaseName(ScanCollectionName) + "_PeakCluster.serFS").exists()) {
        return false;
    }
    try {
        Logger.getRootLogger().info("Reading PeakCluster serialization from file:" + FilenameUtils.getBaseName(ScanCollectionName) + "_PeakCluster.serFS...");

        FileInputStream fileIn = new FileInputStream(FilenameUtils.getFullPath(ParentmzXMLName) + FilenameUtils.getBaseName(ParentmzXMLName) + "_Peak/" + FilenameUtils.getBaseName(ScanCollectionName) + "_PeakCluster.serFS");
        FSTObjectInput in = new FSTObjectInput(fileIn);
        PeakClusters = (ArrayList<PeakCluster>) in.readObject();
        in.close();
        fileIn.close();
    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        if (FS_PeakClusterRead_Old()) {
            WritePeakClusterSerialization();
            return true;
        }
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        return false;
    }
    return true;
}
 
Example 9
Project: DIA-Umpire-Maven   File: LCMSPeakBase.java   View Source Code Vote up 5 votes
private void FS_PeakClusterWrite() {
    try {
        Logger.getRootLogger().info("Writing PeakCluster serialization to file:" + FilenameUtils.getBaseName(ScanCollectionName) + "_PeakCluster.serFS...");
        FileOutputStream fout = new FileOutputStream(FilenameUtils.getFullPath(ParentmzXMLName) + FilenameUtils.getBaseName(ParentmzXMLName) + "_Peak/" + FilenameUtils.getBaseName(ScanCollectionName) + "_PeakCluster.serFS", false);
        FSTObjectOutput out = new FSTObjectOutput(fout);
        out.writeObject(PeakClusters);
        out.close();
        fout.close();
    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        JavaSerializationPeakClusterWrite();
    }
}
 
Example 10
Project: DIA-Umpire-Maven   File: LCMSPeakDIAMS2.java   View Source Code Vote up 5 votes
private void FSCluster2CurveUnfragWrite() {
    try {
        Logger.getRootLogger().debug("Writing UnfragPrecursorFragCorr serialization to file:" + FilenameUtils.getBaseName(ScanCollectionName) + "_UnfClus2Cur.serFS...");
        FileOutputStream fout = new FileOutputStream(FilenameUtils.getFullPath(ParentmzXMLName) + FilenameUtils.getBaseName(ParentmzXMLName) + "_Peak/" + FilenameUtils.getBaseName(ScanCollectionName) + "_UnfClus2Cur.serFS", false);
        FSTObjectOutput oos = new FSTObjectOutput(fout);
        oos.writeObject(UnFragIonClu2Cur);
        oos.close();
        fout.close();
    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
    }
}
 
Example 11
Project: recruitervision   File: FileServiceImpl.java   View Source Code Vote up 5 votes
@Override
public File saveParsedText(String path, File file, String text) {
    String filename = FilenameUtils.getBaseName(file.getName()) + EXTENSION;
    createDirectory(CommonUtils.TMP_FILES_PATH);
    String tmpFile = String.join(CommonUtils.DELIMITER, path, filename);
    try {
        FileWriter fileWriter = new FileWriter(tmpFile);
        fileWriter.write(text);
        fileWriter.flush();
        fileWriter.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return new File(tmpFile);
}
 
Example 12
Project: DIA-Umpire-Maven   File: LCMSID.java   View Source Code Vote up 5 votes
private void ExportPepPSMCSV(String folder) throws IOException {
    if (folder == null | "".equals(folder)) {
        folder = FilenameUtils.getFullPath(mzXMLFileName);
    }
    Logger.getRootLogger().info("Writing PSM result to file:" + folder + FilenameUtils.getBaseName(mzXMLFileName) + "_PSMs.csv...");
    FileWriter writer = new FileWriter(folder + FilenameUtils.getBaseName(mzXMLFileName) + "_PSMs.csv");
    writer.write("SpecID,Sequence,ModSeq,TPPModSeq,Modification,Charge,mz,NeutralPepMass,ObservedMass,RT,AdjustedRT,Rank,ScanNo,PreAA,NextAA,MissedCleavage,ExpectValue,MassError,Prob,Rawname,ParentPepIndex,MS1Quant\n");
    for (PepIonID pepion : PepIonList.values()) {
        for (PSM psm : pepion.GetPSMList()) {
            writer.write(psm.SpecNumber + "," + psm.Sequence + "," + psm.ModSeq + "," + psm.TPPModSeq + "," + psm.GetModificationString() + "," + psm.Charge + "," + psm.ObserPrecursorMz() + "," + psm.NeutralPepMass + "," + psm.ObserPrecursorMass + "," + psm.RetentionTime + "," + psm.NeighborMaxRetentionTime + "," + psm.Rank + "," + psm.ScanNo + "," + psm.PreAA + "," + psm.NextAA + "," + psm.MissedCleavage + "," + psm.expect + "," + psm.MassError + "," + psm.Probability + "," + psm.RawDataName + "," + pepion.Index + "," + pepion.GetMS1() + "\n");
        }
    }
    writer.close();
}
 
Example 13
Project: airsonic   File: ImportPlaylistController.java   View Source Code Vote up 5 votes
@RequestMapping(method = RequestMethod.POST)
protected String handlePost(RedirectAttributes redirectAttributes,
                                       HttpServletRequest request
                                       ) throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();

    try {
        if (ServletFileUpload.isMultipartContent(request)) {

            FileItemFactory factory = new DiskFileItemFactory();
            ServletFileUpload upload = new ServletFileUpload(factory);
            List<?> items = upload.parseRequest(request);
            for (Object o : items) {
                FileItem item = (FileItem) o;

                if ("file".equals(item.getFieldName()) && !StringUtils.isBlank(item.getName())) {
                    if (item.getSize() > MAX_PLAYLIST_SIZE_MB * 1024L * 1024L) {
                        throw new Exception("The playlist file is too large. Max file size is " + MAX_PLAYLIST_SIZE_MB + " MB.");
                    }
                    String playlistName = FilenameUtils.getBaseName(item.getName());
                    String fileName = FilenameUtils.getName(item.getName());
                    String format = StringUtils.lowerCase(FilenameUtils.getExtension(item.getName()));
                    String username = securityService.getCurrentUsername(request);
                    Playlist playlist = playlistService.importPlaylist(username, playlistName, fileName,
                                                                       item.getInputStream(), null);
                    map.put("playlist", playlist);
                }
            }
        }
    } catch (Exception e) {
        map.put("error", e.getMessage());
    }

    redirectAttributes.addFlashAttribute("model", map);
    return "redirect:importPlaylist";
}
 
Example 14
Project: walle   File: Batch2Command.java   View Source Code Vote up 5 votes
private void generateChannelApk(final File inputFile, final File outputDir, final String channel, final String alias, final Map<String, String> extraInfo) {
    final String channelName = alias == null ? channel : alias;
    final String name = FilenameUtils.getBaseName(inputFile.getName());
    final String extension = FilenameUtils.getExtension(inputFile.getName());
    final String newName = name + "_" + channelName + "." + extension;
    final File channelApk = new File(outputDir, newName);
    try {
        FileUtils.copyFile(inputFile, channelApk);
        ChannelWriter.put(channelApk, channel, extraInfo);
    } catch (IOException | SignatureNotFoundException e) {
        e.printStackTrace();
    }
}
 
Example 15
Project: DIA-Umpire-Maven   File: TargetMatchScoring.java   View Source Code Vote up 5 votes
public boolean LibraryMatchWrite() throws FileNotFoundException {
    try {
        Logger.getRootLogger().info("Writing Target match results to file:" + FilenameUtils.getFullPath(Filename) + FilenameUtils.getBaseName(Filename) + "_" + LibID + "_LibMatch.serFS...");
        FileOutputStream fout = new FileOutputStream(FilenameUtils.getFullPath(Filename) + FilenameUtils.getBaseName(Filename) + "_" + LibID + "_LibMatch.serFS", false);
        FSTObjectOutput out = new FSTObjectOutput(fout);
        out.writeObject(this);
        out.close();
        fout.close();
    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        return false;
    }
    return true;
}
 
Example 16
Project: DIA-Umpire-Maven   File: DIAPack.java   View Source Code Vote up 4 votes
public String GetIPROPHETPepXML() {
    return FilenameUtils.getFullPath(Filename) + "interact-" + FilenameUtils.getBaseName(Filename) + ".iproph.pep.xml";
}
 
Example 17
Project: OneClient   File: ModInstaller.java   View Source Code Vote up 4 votes
public String getName() {
	if (name == null || name.isEmpty()) {
		this.name = FilenameUtils.getBaseName(this.hash.getFilePath());
	}
	return name;
}
 
Example 18
Project: DIA-Umpire-Maven   File: LCMSPeakMS1.java   View Source Code Vote up 4 votes
public void GenerateMassCalibrationRTMap() throws IOException {
    String pngfile = FilenameUtils.getFullPath(ScanCollectionName) + "/" + FilenameUtils.getBaseName(ScanCollectionName) + "_masscaliRT.png";
    XYSeries series = new XYSeries("PSM");
    XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
    LoessInterpolator loessInterpolator = new LoessInterpolator(
            0.75,//bandwidth,
            2//robustnessIters
    );

    for (PSM psm : this.IDsummary.PSMList.values()) {
        float ppm = InstrumentParameter.CalcSignedPPM(psm.ObserPrecursorMass, psm.NeutralPepMass);
        series.add(new XYDataItem(psm.RetentionTime, ppm));
    }
    double x[] = new double[IDsummary.PSMList.size()];
    double y[] = new double[x.length];
    double currentmin = 0f;
    for (int i = 0; i < series.getItemCount(); i++) {
        x[i] = (double) series.getX(i);
        if (x[i] <= currentmin) {
            x[i] = currentmin + 0.0001f;
        }
        currentmin = x[i];
        y[i] = (double) series.getY(i);
    }

    Masscalibrationfunction = loessInterpolator.interpolate(x, y);
    XYSeries smoothline = new XYSeries("Loess Regression");

    double xvalue = series.getMinX();

    while (xvalue < series.getMaxX()) {
        smoothline.add(xvalue, Masscalibrationfunction.value(xvalue));
        xvalue += 0.05d;
    }
    xySeriesCollection.addSeries(smoothline);
    xySeriesCollection.addSeries(series);

    JFreeChart chart = ChartFactory.createScatterPlot("Mass calibration", "RT", "Mass error (ppm)", xySeriesCollection,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyPlot = (XYPlot) chart.getPlot();
    xyPlot.setDomainCrosshairVisible(true);
    xyPlot.setRangeCrosshairVisible(true);

    XYItemRenderer renderer = xyPlot.getRenderer();
    renderer.setSeriesPaint(1, Color.blue);
    renderer.setSeriesPaint(0, Color.BLACK);
    renderer.setSeriesShape(1, new Ellipse2D.Double(0, 0, 3, 3));
    renderer.setSeriesStroke(1, new BasicStroke(1.0f));
    xyPlot.setBackgroundPaint(Color.white);
    ChartUtilities.saveChartAsPNG(new File(pngfile), chart, 1000, 600);
}
 
Example 19
Project: csv2bib   File: SpringerBibTex.java   View Source Code Vote up 4 votes
public SpringerBibTex(String outputFile, List<String> urls) {
	this.urls = urls;
	this.outputFile = FilenameUtils.getBaseName(Paths.get(outputFile).toString());
}
 
Example 20
Project: NGB-master   File: DownloadFileManager.java   View Source Code Vote up 4 votes
private String createPathFromUrlString(final String urlString) {
    final String hash = Utils.getHashFromUrlString(urlString);
    final String dir = downloadDirPath + Utils.getPathFromHash(hash);
    makeDir(dir);
    return dir + DELIMITER + FilenameUtils.getBaseName(urlString) + hash + FilenameUtils.getExtension(urlString);
}