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:io.github.sn0cr.rapidRunner.testRunner.TestCaseFinder.java

public TestCaseFinder(Path parentFolder, String filePattern, String inExtension, String outExtension) {
    final String[] files = parentFolder.toFile().list(new WildcardFileFilter(filePattern));
    Arrays.sort(files, new NaturalOrderComparator());
    for (final String filename : files) {
        final String extension = FilenameUtils.getExtension(filename);
        final String name = FilenameUtils.getBaseName(filename);
        final Path toFile = Paths.get(parentFolder.toString(), filename);
        Pair<Path, Path> testCasePair;
        if (this.testCases.containsKey(name)) {
            testCasePair = this.testCases.get(name);
        } else {// w w  w  . ja v a2s.  c o  m
            testCasePair = new Pair<Path, Path>();
        }
        if (extension.equals(inExtension)) {
            testCasePair.setA(toFile);
        } else if (extension.equals(outExtension)) {
            testCasePair.setB(toFile);
        }
        if (testCasePair.notEmpty()) {
            this.testCases.put(name, testCasePair);
        }
    }
}

From source file:com.twosigma.beaker.core.module.elfinder.impl.commands.DuplicateCommand.java

@Override
public void execute(FsService fsService, HttpServletRequest request, ServletContext servletContext,
        JSONObject json) throws Exception {
    String[] targets = request.getParameterValues("targets[]");

    List<FsItemEx> added = new ArrayList<FsItemEx>();

    for (String target : targets) {
        FsItemEx fsi = super.findItem(fsService, target);
        String name = fsi.getName();
        String baseName = FilenameUtils.getBaseName(name);
        String extension = FilenameUtils.getExtension(name);

        int i = 1;
        FsItemEx newFile = null;//from   ww  w. j  a va2s . co m
        baseName = baseName.replaceAll("\\(\\d+\\)$", "");

        while (true) {
            String newName = String.format("%s(%d)%s", baseName, i,
                    (extension == null || extension.isEmpty() ? "" : "." + extension));
            newFile = new FsItemEx(fsi.getParent(), newName);
            if (!newFile.exists()) {
                break;
            }
            i++;
        }

        createAndCopy(fsi, newFile);
        added.add(newFile);
    }

    json.put("added", files2JsonArray(request, added));
}

From source file:edu.umn.msi.tropix.proteomics.conversion.impl.ConversionUtils.java

public static String getSanitizedName(@Nonnull final String filename, @Nonnull final String extension) {
    Preconditions.checkNotNull(filename, "getSanitizedName sent a null filename");
    Preconditions.checkNotNull(filename, "getSanitizedName sent a null extension");
    final String baseName = FilenameUtils.getBaseName(filename);
    final String cleanedBaseName = baseName.replaceAll("[^\\w]", "_");
    return cleanedBaseName + extension;
}

From source file:ijfx.service.batch.input.SaveToFileWrapper.java

public SaveToFileWrapper(Context context, BatchSingleInput input, File saveFile, String suffix) {

    this(context, input);

    String baseName = FilenameUtils.getBaseName(saveFile.getName());
    String ext = FilenameUtils.getExtension(saveFile.getName());
    String finalName = new StringBuilder().append(baseName).append(suffix).append(".").append(ext).toString();
    System.out.println(finalName);
    saveTo = new File(saveFile.getParentFile(), finalName);
}

From source file:com.jstar.eclipse.processing.annotations.FileAnnotations.java

public String getBaseSourceFileName() {
    return FilenameUtils.getBaseName(sourceFileName);
}

From source file:egovframework.com.utl.wed.filter.DirectoryPathManager.java

public static File getUniqueFile(final File file) {
    if (!file.exists())
        return file;

    File tmpFile = new File(file.getAbsolutePath());
    File parentDir = tmpFile.getParentFile();
    int count = 1;
    String extension = FilenameUtils.getExtension(tmpFile.getName());
    String baseName = FilenameUtils.getBaseName(tmpFile.getName());
    do {/* www. jav  a  2s  .  c om*/
        tmpFile = new File(parentDir, baseName + "_" + count++ + "_." + extension);
    } while (tmpFile.exists());
    return tmpFile;
}

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()) {/*w  w  w .j  av 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:MSUmpire.SpectrumParser.PKLScanParser.java

private void Parse() throws FileNotFoundException, IOException {
    //806.080993652344,8429.974609375,1
    //832.287536621094,7226.927734375,1
    //854.039978027344,6682.37646484375,1
    //861.061340332031,8370.4716796875,1
    BufferedReader reader = new BufferedReader(new FileReader(filename));
    String line = "";
    String[] Values = null;//from ww  w . ja va 2s.com
    scan = new ScanData();
    scan.MGFTitle = FilenameUtils.getBaseName(filename);
    while ((line = reader.readLine()) != null) {
        if ((Values = line.split(",")).length == 3) {
            scan.AddPoint(Float.parseFloat(Values[0]), Float.parseFloat(Values[1]));
        }
    }
    reader.close();
}

From source file:com.frostwire.search.torrent.TorrentCrawledSearchResult.java

public TorrentCrawledSearchResult(TorrentCrawlableSearchResult sr, TorrentInfo ti, int fileIndex,
        String filePath, long fileSize) {
    super(sr);/*from  w ww  .j  a v  a2s .c  o  m*/
    this.ti = ti;
    this.fileIndex = fileIndex;
    this.filePath = filePath;
    this.filename = FilenameUtils.getName(this.filePath);
    this.size = fileSize;
    this.displayName = FilenameUtils.getBaseName(this.filename);
}

From source file:com.frostwire.search.torlock.TorLockSearchResult.java

public TorLockSearchResult(String domainName, String detailsUrl, SearchMatcher matcher) {
    this.detailsUrl = detailsUrl;
    this.infoHash = matcher.group("infohash");
    this.filename = parseFileName(matcher.group("filename"), FilenameUtils.getBaseName(detailsUrl))
            .replaceAll("<font color=\".*?\">|</font>", "");
    this.size = parseSize(matcher.group("filesize"));
    this.creationTime = parseCreationTime(matcher.group("time"));
    this.seeds = parseSeeds(matcher.group("seeds"));
    this.torrentUrl = "http://" + domainName + "/tor/" + matcher.group("torrentid") + ".torrent";
    this.displayName = HtmlManipulator.replaceHtmlEntities(FilenameUtils.getBaseName(filename));
}