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

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

Introduction

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

Prototype

public static String removeExtension(String filename) 

Source Link

Document

Removes the extension from a filename.

Usage

From source file:diffhunter.Indexer.java

public void Make_Index(Database hashdb, String file_name, String read_gene_location)
        throws FileNotFoundException, IOException {
    Set_Parameters();//  w  w  w.j ava  2  s  .c o  m
    //System.out.print("Sasa");
    ConcurrentHashMap<String, Map<Integer, Integer>> dic_gene_loc_count = new ConcurrentHashMap<>();
    ArrayList<String> lines_from_bed_file = new ArrayList<>();
    BufferedReader br = new BufferedReader(new FileReader(file_name));

    String line = br.readLine();
    List<String> toks = Arrays.asList(line.split("\t"));
    lines_from_bed_file.add(line);
    String last_Seen_chromosome = toks.get(0).replace("chr", "");
    line = br.readLine();
    lines_from_bed_file.add(line);
    toks = Arrays.asList(line.split("\t"));
    String new_chromosome = toks.get(0).replace("chr", "");

    while (((line = br.readLine()) != null) || lines_from_bed_file.size() > 0) {
        if (line != null) {
            toks = Arrays.asList(line.split("\t"));
            new_chromosome = toks.get(0).replace("chr", "");
        }
        // process the line.
        if (line == null || !new_chromosome.equals(last_Seen_chromosome)) {
            System.out.println("Processing chromosome" + "\t" + last_Seen_chromosome);
            last_Seen_chromosome = new_chromosome;
            lines_from_bed_file.parallelStream().forEach(content -> {

                List<String> inner_toks = Arrays.asList(content.split("\t"));
                //WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING 
                //STRAND column count should be changed. 
                String strand = inner_toks.get(5);
                String chromosome_ = inner_toks.get(0).replace("chr", "");
                if (!dic_Loc_gene.get(strand).containsKey(chromosome_)) {
                    return;
                }
                Integer start_loc = Integer.parseInt(inner_toks.get(1));
                Integer end_loc = Integer.parseInt(inner_toks.get(2));
                List<Interval<String>> res__ = dic_Loc_gene.get(strand).get(chromosome_).getIntervals(start_loc,
                        end_loc);
                //IntervalTree<String> pot_gene_name=new IntervalTree<>(res__);
                //                        for (int z = 0; z < pot_gene_name.Intervals.Count; z++)
                //{
                for (int z = 0; z < res__.size(); z++) {

                    dic_gene_loc_count.putIfAbsent(res__.get(z).getData(), new HashMap<>());
                    String gene_symbol = res__.get(z).getData();
                    Integer temp_gene_start_loc = dic_genes.get(gene_symbol).start_loc;
                    Integer temp_gene_end_loc = dic_genes.get(gene_symbol).end_loc;
                    if (start_loc < temp_gene_start_loc) {
                        start_loc = temp_gene_start_loc;
                    }
                    if (end_loc > temp_gene_end_loc) {
                        end_loc = temp_gene_end_loc;
                    }
                    synchronized (dic_synchrinzer_genes.get(gene_symbol)) {
                        for (int k = start_loc; k <= end_loc; k++) {
                            Integer value_inside = 0;
                            value_inside = dic_gene_loc_count.get(gene_symbol).get(k);
                            dic_gene_loc_count.get(gene_symbol).put(k,
                                    value_inside == null ? 1 : (value_inside + 1));
                        }
                    }
                }
            });
            /*                    List<string> keys_ = dic_gene_loc_count.Keys.ToList();
             List<string> alt_keys = new List<string>();// dic_gene_loc_count.Keys.ToList();
             for (int i = 0; i < keys_.Count; i++)
             {
             Dictionary<int, int> dicccc_ = new Dictionary<int, int>();
             dic_gene_loc_count[keys_[i]] = new Dictionary<int, int>(dic_gene_loc_count[keys_[i]].Where(x => x.Value >= 2).ToDictionary(x => x.Key, x => x.Value));
             if (dic_gene_loc_count[keys_[i]].Count == 0)
             {
                    
             dic_gene_loc_count.TryRemove(keys_[i], out dicccc_);
             continue;
             }
             hashdb.Put(Get_BDB(keys_[i]), Get_BDB_Dictionary(dic_gene_loc_count[keys_[i]]));
             alt_keys.Add(keys_[i]);
             dic_gene_loc_count.TryRemove(keys_[i], out dicccc_);
             }*/
            ArrayList<String> keys_ = new ArrayList<>(dic_gene_loc_count.keySet());
            ArrayList<String> alt_keys = new ArrayList<>();
            for (int i = 0; i < keys_.size(); i++) {

                //LinkedHashMap<Integer, Integer> tmep_map = new LinkedHashMap<>(dic_gene_loc_count.get(keys_.get(i)));
                LinkedHashMap<Integer, Integer> tmep_map = new LinkedHashMap<>();
                /*tmep_map = */
                dic_gene_loc_count.get(keys_.get(i)).entrySet().stream().filter(p -> p.getValue() >= 2)
                        .sorted(Comparator.comparing(E -> E.getKey()))
                        .forEach((entry) -> tmep_map.put(entry.getKey(), entry.getValue()));//.collect(Collectors.toMap(p -> p.getKey(), p -> p.getValue()));
                if (tmep_map.isEmpty()) {
                    dic_gene_loc_count.remove(keys_.get(i));
                    continue;
                }

                //Map<Integer, Integer> tmep_map1 = new LinkedHashMap<>();
                //tmep_map1=sortByKey(tmep_map);
                //tmep_map.entrySet().stream().sorted(Comparator.comparing(E -> E.getKey())).forEach((entry) -> tmep_map1.put(entry.getKey(), entry.getValue()));
                //BerkeleyDB_Box box=new BerkeleyDB_Box();
                hashdb.put(null, BerkeleyDB_Box.Get_BDB(keys_.get(i)),
                        BerkeleyDB_Box.Get_BDB_Dictionary(tmep_map));
                alt_keys.add(keys_.get(i));
                dic_gene_loc_count.remove(keys_.get(i));
                //dic_gene_loc_count.put(keys_.get(i),tmep_map);
            }

            hashdb.sync();
            int a = 1111;
            /*                    hashdb.Sync();
             File.AppendAllLines("InputDB\\" + Path.GetFileNameWithoutExtension(file_name) + "_genes.txt", alt_keys);
             //total_lines_processed_till_now += lines_from_bed_file.Count;
             //worker.ReportProgress(total_lines_processed_till_now / count_);
             lines_from_bed_file.Clear();
             if (!reader.EndOfStream)
             {
             lines_from_bed_file.Add(_line_);
             }
             last_Seen_chromosome = new_choromosome;*/
            lines_from_bed_file.clear();
            if (line != null) {
                lines_from_bed_file.add(line);
            }
            Path p = Paths.get(file_name);
            file_name = p.getFileName().toString();

            BufferedWriter output = new BufferedWriter(new FileWriter((Paths
                    .get(read_gene_location, FilenameUtils.removeExtension(file_name) + ".txt").toString()),
                    true));
            for (String alt_key : alt_keys) {
                output.append(alt_key);
                output.newLine();
            }
            output.close();
            /*if (((line = br.readLine()) != null))
            {
            lines_from_bed_file.add(line);
            toks=Arrays.asList(line.split("\t"));
            new_chromosome=toks.get(0).replace("chr", "");
            }*/
            //last_Seen_chromosome=new_chromosome;
        } else if (new_chromosome.equals(last_Seen_chromosome)) {
            lines_from_bed_file.add(line);
        }

    }
    br.close();
    hashdb.sync();
    hashdb.close();

}

From source file:io.stallion.contentPublishing.UploadRequestProcessor.java

public void createResized(U uploaded, BufferedImage image, String orgPath, int targetHeight, int targetWidth,
        String postfix, Scalr.Mode scalrMode) throws IOException {
    String imageFormat = uploaded.getExtension();

    BufferedImage scaledImg = Scalr.resize(image, Scalr.Method.QUALITY, scalrMode, targetWidth, targetHeight,
            Scalr.OP_ANTIALIAS);//ww  w.j a  va2 s. c  o  m
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int height = scaledImg.getHeight();
    int width = scaledImg.getWidth();
    ImageIO.write(scaledImg, imageFormat, baos);
    baos.flush();
    byte[] scaledImageInByte = baos.toByteArray();
    baos.close();

    String relativePath = FilenameUtils.removeExtension(uploaded.getCloudKey());
    if (!"org".equals(postfix)) {
        relativePath = relativePath + "." + postfix;
    }
    relativePath = relativePath + "." + uploaded.getExtension();
    String thumbnailPath = this.uploadsFolder + relativePath;
    Log.info("Write all byptes to {0}", thumbnailPath);
    FileUtils.writeAllBytes(scaledImageInByte, new File(thumbnailPath));
    Long sizeBytes = new File(thumbnailPath).length();
    //String url = "{cdnUrl}/st-publisher/files/view/" + uploaded.getSecret() + "/" + uploaded.getId() + "/" + postfix + "?ts=" + DateUtils.mils();
    String url = makeRawUrlForFile(uploaded, postfix);
    if (postfix.equals("thumb")) {
        uploaded.setThumbCloudKey(relativePath);
        uploaded.setThumbRawUrl(url);
        uploaded.setThumbHeight(height);
        uploaded.setThumbWidth(width);
    } else if (postfix.equals("small")) {
        uploaded.setSmallCloudKey(relativePath);
        uploaded.setSmallRawUrl(url);
        uploaded.setSmallHeight(height);
        uploaded.setSmallWidth(width);
    } else if (postfix.equals("medium")) {
        uploaded.setMediumCloudKey(relativePath);
        uploaded.setMediumRawUrl(url);
        uploaded.setMediumHeight(height);
        uploaded.setMediumWidth(width);
    } else if (postfix.equals("org")) {
        uploaded.setCloudKey(relativePath);
        uploaded.setRawUrl(url);
        uploaded.setSizeBytes(sizeBytes);
        uploaded.setHeight(height);
        uploaded.setWidth(width);
    }

    //return scaledImageInByte;
}

From source file:com.uwsoft.editor.proxy.ProjectManager.java

public File importExternalAnimationIntoProject(FileHandle animationFileSource) {
    try {//from   w w w  . ja  v a2s  . co m
        String fileName = animationFileSource.name();
        if (!Overlap2DUtils.JSON_FILTER.accept(null, fileName)
                && !Overlap2DUtils.SCML_FILTER.accept(null, fileName)) {
            //showError("Spine animation should be a .json file with atlas in same folder \n Spriter animation should be a .scml file with images in same folder");
            return null;
        }

        String fileNameWithOutExt = FilenameUtils.removeExtension(fileName);
        String sourcePath;
        String animationDataPath;
        String targetPath;
        if (Overlap2DUtils.JSON_FILTER.accept(null, fileName)) {
            sourcePath = animationFileSource.path();

            animationDataPath = FilenameUtils.getFullPathNoEndSeparator(sourcePath);
            targetPath = currentProjectPath + "/assets/orig/spine-animations" + File.separator
                    + fileNameWithOutExt;
            FileHandle atlasFileSource = new FileHandle(
                    animationDataPath + File.separator + fileNameWithOutExt + ".atlas");
            if (!atlasFileSource.exists()) {
                //showError("the atlas file needs to have same name and location as the json file");
                return null;
            }

            FileUtils.forceMkdir(new File(targetPath));
            File jsonFileTarget = new File(targetPath + File.separator + fileNameWithOutExt + ".json");
            File atlasFileTarget = new File(targetPath + File.separator + fileNameWithOutExt + ".atlas");
            Array<File> imageFiles = getAtlasPages(atlasFileSource);

            FileUtils.copyFile(animationFileSource.file(), jsonFileTarget);
            FileUtils.copyFile(atlasFileSource.file(), atlasFileTarget);

            for (File imageFile : imageFiles) {
                FileHandle imgFileTarget = new FileHandle(targetPath + File.separator + imageFile.getName());
                FileUtils.copyFile(imageFile, imgFileTarget.file());
            }

            return atlasFileTarget;

        } else if (Overlap2DUtils.SCML_FILTER.accept(null, fileName)) {
            targetPath = currentProjectPath + "/assets/orig/spriter-animations" + File.separator
                    + fileNameWithOutExt;
            File scmlFileTarget = new File(targetPath + File.separator + fileNameWithOutExt + ".scml");
            ArrayList<File> imageFiles = getScmlFileImagesList(animationFileSource);

            FileUtils.copyFile(animationFileSource.file(), scmlFileTarget);
            for (File imageFile : imageFiles) {
                File imgFileTarget = new File(targetPath + File.separator + imageFile.getName());
                FileUtils.copyFile(imageFile, imgFileTarget);
            }
            return scmlFileTarget;

        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:ffx.algorithms.mc.RosenbluthChiAllMove.java

private void write() {
    if (noSnaps) {
        return;/*from  ww w . j a  v  a 2s . c o  m*/
    }
    if (writer == null) {
        writer = new PDBFilter(mola.getFile(), mola, null, null);
    }
    String filename = FilenameUtils.removeExtension(mola.getFile().toString());
    filename = mola.getFile().getAbsolutePath();
    if (!filename.contains("_mc")) {
        filename = FilenameUtils.removeExtension(filename) + "_mc.pdb";
    }
    File file = new File(filename);
    writer.writeFile(file, false);
}

From source file:dk.dma.msinm.common.repo.RepositoryService.java

/**
 * Returns a unique file name in the given folder.
 * If the given file name is not unique, a new is constructed
 * by adding a number to the file name/*from   w  w w .j av a2  s . c  om*/
 * @param folder the folder
 * @param name the file name
 * @return the new unique file
 */
private Path getUniqueFile(Path folder, String name) {
    Path file = folder.resolve(name);
    if (Files.exists(file)) {
        for (int x = 2; true; x++) {
            String fileName = FilenameUtils.removeExtension(name) + " " + x + "."
                    + FilenameUtils.getExtension(name);
            file = folder.resolve(fileName);
            if (!Files.exists(file)) {
                break;
            }
        }
    }
    return file;
}

From source file:com.o2d.pkayjava.editor.proxy.ProjectManager.java

public File importExternalAnimationIntoProject(FileHandle animationFileSource) {
    try {//  w ww .ja  v a2s .c  o m
        String fileName = animationFileSource.name();
        if (!Overlap2DUtils.JSON_FILTER.accept(null, fileName)
                && !Overlap2DUtils.SCML_FILTER.accept(null, fileName)) {
            //showError("Spine animation should be a .json file with atlas in same folder \n Spriter animation should be a .scml file with images in same folder");
            return null;
        }

        String fileNameWithOutExt = FilenameUtils.removeExtension(fileName);
        String sourcePath;
        String animationDataPath;
        String targetPath;
        if (Overlap2DUtils.JSON_FILTER.accept(null, fileName)) {
            sourcePath = animationFileSource.path();

            animationDataPath = FilenameUtils.getFullPathNoEndSeparator(sourcePath);
            targetPath = currentWorkingPath + "/" + currentProjectVO.projectName
                    + "/assets/orig/spine-animations" + File.separator + fileNameWithOutExt;
            FileHandle atlasFileSource = new FileHandle(
                    animationDataPath + File.separator + fileNameWithOutExt + ".atlas");
            if (!atlasFileSource.exists()) {
                //showError("the atlas file needs to have same name and location as the json file");
                return null;
            }

            FileUtils.forceMkdir(new File(targetPath));
            File jsonFileTarget = new File(targetPath + File.separator + fileNameWithOutExt + ".json");
            File atlasFileTarget = new File(targetPath + File.separator + fileNameWithOutExt + ".atlas");
            Array<File> imageFiles = getAtlasPages(atlasFileSource);

            FileUtils.copyFile(animationFileSource.file(), jsonFileTarget);
            FileUtils.copyFile(atlasFileSource.file(), atlasFileTarget);

            for (File imageFile : imageFiles) {
                FileHandle imgFileTarget = new FileHandle(targetPath + File.separator + imageFile.getName());
                FileUtils.copyFile(imageFile, imgFileTarget.file());
            }

            return atlasFileTarget;

        } else if (Overlap2DUtils.SCML_FILTER.accept(null, fileName)) {
            targetPath = currentWorkingPath + "/" + currentProjectVO.projectName
                    + "/assets/orig/spriter-animations" + File.separator + fileNameWithOutExt;
            File scmlFileTarget = new File(targetPath + File.separator + fileNameWithOutExt + ".scml");
            ArrayList<File> imageFiles = getScmlFileImagesList(animationFileSource);

            FileUtils.copyFile(animationFileSource.file(), scmlFileTarget);
            for (File imageFile : imageFiles) {
                File imgFileTarget = new File(targetPath + File.separator + imageFile.getName());
                FileUtils.copyFile(imageFile, imgFileTarget);
            }
            return scmlFileTarget;

        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.moviejukebox.scanner.MovieFilenameScanner.java

private MovieFilenameScanner(File file) {
    // CHECK FOR USE_PARENT_PATTERN matches
    if (useParentRegex && USE_PARENT_PATTERN.matcher(file.getName()).find()) {
        // Check the container to see if it's a RAR file and go up a further directory
        String rarExtensionCheck;
        try {/*  w  ww.j av  a2 s. c  om*/
            rarExtensionCheck = file.getParentFile().getName().toLowerCase();
        } catch (Exception error) {
            rarExtensionCheck = Movie.UNKNOWN;
        }

        if (ARCHIVE_SCAN_RAR && RAR_EXT_PATTERN.matcher(rarExtensionCheck).find()) {
            // We need to go up two parent directories
            this.file = file.getParentFile().getParentFile();
        } else {
            // Just go up one parent directory.
            this.file = file.getParentFile();
        }

        LOG.debug("UseParentPattern matched for {} - Using parent folder name: {}", file.getName(),
                this.file.getName());
    } else {
        this.file = file;
    }

    this.filename = this.file.getName();
    rest = filename;
    LOG.trace("Processing filename: '{}'", rest);

    // EXTENSION AND CONTAINER
    if (this.file.isFile()) {
        // Extract and strip extension
        String ext = FilenameUtils.getExtension(rest);
        if (ext.length() > 0) {
            rest = FilenameUtils.removeExtension(rest);
        }
        dto.setExtension(ext);

        dto.setContainer(dto.getExtension().toUpperCase());
    } else {
        // For DVD images
        // no extension
        dto.setExtension("");
        dto.setContainer("DVD");
        dto.setVideoSource("DVD");
    }

    rest = cleanUp(rest);
    LOG.trace("After Extension: '{}'", rest);

    // Detect incomplete filenames and add parent folder name to parser
    for (Pattern pattern : PARENT_FOLDER_PART_PATTERNS) {
        final Matcher matcher = pattern.matcher(rest);
        if (matcher.find()) {
            final File folder = this.file.getParentFile();
            if (folder == null) {
                break;
            }
            rest = cleanUp(folder.getName()) + "./." + rest;
            break;
        }
    }
    LOG.trace("After incomplete filename: '{}'", rest);

    // Remove version info
    for (Pattern pattern : MOVIE_VERSION_PATTERNS) {
        rest = pattern.matcher(rest).replaceAll("./.");
    }
    LOG.trace("After version info: '{}'", rest);

    // EXTRAS (Including Trailers)
    {
        for (Pattern pattern : EXTRAS_PATTERNS) {
            Matcher matcher = pattern.matcher(rest);
            if (matcher.find()) {
                dto.setExtra(Boolean.TRUE);
                dto.setPartTitle(matcher.group(1));
                rest = cutMatch(rest, matcher, "./EXTRA/.");
                break;
            }
        }
    }
    LOG.trace("After Extras: '{}'", rest);

    dto.setFps(seekPatternAndUpdateRest(FPS_MAP, dto.getFps()));
    dto.setAudioCodec(seekPatternAndUpdateRest(AUDIO_CODEC_MAP, dto.getAudioCodec()));
    dto.setVideoCodec(seekPatternAndUpdateRest(VIDEO_CODEC_MAP, dto.getVideoCodec()));
    dto.setHdResolution(seekPatternAndUpdateRest(HD_RESOLUTION_MAP, dto.getHdResolution()));
    dto.setVideoSource(seekPatternAndUpdateRest(VIDEO_SOURCE_MAP, dto.getVideoSource(), PART_PATTERNS));

    // SEASON + EPISODES
    {
        final Matcher matcher = TV_PATTERN.matcher(rest);
        if (matcher.find()) {
            if ("720".equals(matcher.group(1)) || "1080".equals(matcher.group(1))
                    || "2160".equals(matcher.group(1))) {
                LOG.trace("Skipping pattern detection of '{}' because it looks like a resolution",
                        matcher.group(0));
            } else {
                // logger.finest("It's a TV Show: " + group0);
                rest = cutMatch(rest, matcher, "./TVSHOW/.");

                final Matcher smatcher = SEASON_PATTERN.matcher(matcher.group(0));
                smatcher.find();
                int season = Integer.parseInt(smatcher.group(1));
                dto.setSeason(season);

                final Matcher ematcher = EPISODE_PATTERN.matcher(matcher.group(0));
                while (ematcher.find()) {
                    dto.getEpisodes().add(Integer.parseInt(ematcher.group(1)));
                }
            }
        }
    }
    LOG.trace("After season & episode: '{}'", rest);

    // PART
    {
        for (Pattern pattern : PART_PATTERNS) {
            Matcher matcher = pattern.matcher(rest);
            if (matcher.find()) {
                rest = cutMatch(rest, matcher, " /PART/ ");
                dto.setPart(Integer.parseInt(matcher.group(1)));
                break;
            }
        }
    }
    LOG.trace("After Part: '{}'", rest);

    // SETS
    {
        for (;;) {
            final Matcher matcher = SET_PATTERN.matcher(rest);
            if (!matcher.find()) {
                break;
            }
            rest = cutMatch(rest, matcher, Movie.SPACE_SLASH_SPACE);

            MovieFileNameDTO.SetDTO set = new MovieFileNameDTO.SetDTO();
            dto.getSets().add(set);

            String n = matcher.group(1);
            Matcher nmatcher = SET_INDEX_PATTERN.matcher(n);
            if (nmatcher.find()) {
                set.setIndex(Integer.parseInt(nmatcher.group(1)));
                n = cutMatch(n, nmatcher);
            }
            set.setTitle(n.trim());
        }
    }
    LOG.trace("After Sets: '{}'", rest);

    // Movie ID detection
    {
        Matcher matcher = ID_PATTERN.matcher(rest);
        if (matcher.find()) {
            rest = cutMatch(rest, matcher, " /ID/ ");

            String[] idString = matcher.group(1).split("[-\\s+]");
            if (idString.length == 2) {
                dto.setId(idString[0].toLowerCase(), idString[1]);
            } else {
                LOG.debug("Error decoding ID from filename: {}", matcher.group(1));
            }
        } else {
            matcher = IMDB_PATTERN.matcher(rest);
            if (matcher.find()) {
                rest = cutMatch(rest, matcher, " /ID/ ");
                dto.setId(ImdbPlugin.IMDB_PLUGIN_ID, matcher.group(1));
            }
        }
    }
    LOG.trace("After Movie ID: '{}'", rest);

    // LANGUAGES
    if (languageDetection) {
        for (;;) {
            String language = seekPatternAndUpdateRest(STRICT_LANGUAGE_MAP, null);
            if (language == null) {
                break;
            }
            dto.getLanguages().add(language);
        }
    }
    LOG.trace("After languages: '{}'", rest);

    // TITLE
    {
        int iextra = dto.isExtra() ? rest.indexOf("/EXTRA/") : rest.length();
        int itvshow = dto.getSeason() >= 0 ? rest.indexOf("/TVSHOW/") : rest.length();
        int ipart = dto.getPart() >= 0 ? rest.indexOf("/PART/") : rest.length();

        {
            int min = iextra < itvshow ? iextra : itvshow;
            min = min < ipart ? min : ipart;

            // Find first token before trailer, TV show and part
            // Name should not start with '-' (exclude wrongly marked part/episode titles)
            String title = "";
            StringTokenizer t = new StringTokenizer(rest.substring(0, min), "/[]");
            while (t.hasMoreElements()) {
                String token = t.nextToken();
                token = cleanUpTitle(token);
                if (token.length() >= 1 && token.charAt(0) != '-') {
                    title = token;
                    break;
                }
            }

            boolean first = Boolean.TRUE;
            while (t.hasMoreElements()) {
                String token = t.nextToken();
                token = cleanUpTitle(token);
                // Search year (must be next to a non-empty token)
                if (first) {
                    if (token.length() > 0) {
                        try {
                            int year = Integer.parseInt(token);
                            if (year >= 1800 && year <= 3000) {
                                dto.setYear(year);
                            }
                        } catch (NumberFormatException error) {
                            /* ignore */ }
                    }
                    first = Boolean.FALSE;
                }

                if (!languageDetection) {
                    break;
                }

                // Loose language search
                if (token.length() >= 2 && token.indexOf('-') < 0) {
                    for (Map.Entry<String, Pattern> e : LOOSE_LANGUAGE_MAP.entrySet()) {
                        Matcher matcher = e.getValue().matcher(token);
                        if (matcher.find()) {
                            dto.getLanguages().add(e.getKey());
                        }
                    }
                }
            }

            // Search year within title (last 4 digits or 4 digits in parenthesis)
            if (dto.getYear() < 0) {
                Matcher ymatcher = MOVIE_YEAR_PATTERN.matcher(title);
                if (ymatcher.find()) {
                    int year = Integer.parseInt(ymatcher.group(1));
                    if (year >= 1919 && year <= 2099) {
                        dto.setYear(year);
                        title = cutMatch(title, ymatcher);
                    }
                }
            }
            dto.setTitle(title);
        }

        // EPISODE TITLE
        if (dto.getSeason() >= 0) {
            itvshow += 8;
            Matcher matcher = SECOND_TITLE_PATTERN.matcher(rest.substring(itvshow));
            while (matcher.find()) {
                String title = cleanUpTitle(matcher.group(1));
                if (title.length() > 0) {
                    if (SKIP_EP_TITLE) {
                        dto.setEpisodeTitle(Movie.UNKNOWN);
                    } else {
                        dto.setEpisodeTitle(title);
                    }
                    break;
                }
            }
        }

        // PART TITLE
        if (dto.getPart() >= 0) {
            // Just do this for no extra, already named.
            if (!dto.isExtra()) {
                ipart += 6;
                Matcher matcher = SECOND_TITLE_PATTERN.matcher(rest.substring(ipart));
                while (matcher.find()) {
                    String title = cleanUpTitle(matcher.group(1));
                    if (title.length() > 0) {
                        dto.setPartTitle(title);
                        break;
                    }
                }
            }
        }
    }
    LOG.trace("Final: {}", dto.toString());

}

From source file:it.isislab.dmason.util.SystemManagement.Worker.WorkerUpdater.java

/**
 * Called from UI//w  w  w  .  ja v a  2s  . c om
 */
public void startUpdate() {

    if (fTPAddress != null) {
        if (updateFile != null) {
            File dest = new File(FTP_HOME + SEPARATOR + UPDATE_DIR + SEPARATOR + updateFile.getName());

            try {
                FileUtils.copyFile(updateFile, dest);

                Digester dg = new Digester(DigestAlgorithm.MD5);

                InputStream in = new FileInputStream(dest);
                masterUI.setCurWorkerDigest(dg.getDigest(in));

                String fileName = FilenameUtils.removeExtension(updateFile.getName());
                dg.storeToPropFile(FTP_HOME + SEPARATOR + UPDATE_DIR + SEPARATOR + fileName + ".hash");

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (NoDigestFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            UpdateData ud = new UpdateData(updateFile.getName(), fTPAddress);
            master.notifyUpdateAll(ud);
        }
    }
}

From source file:edu.cornell.med.icb.goby.modes.VCFSubsetMode.java

private String removeExtensions(File inputFile) {
    String filename = inputFile.getName();
    if (filename.endsWith(".vcf.gz")) {
        return FilenameUtils.removeExtension(FilenameUtils.removeExtension(inputFile.getName()));
    } else if (filename.endsWith(".vcf")) {
        return FilenameUtils.removeExtension(inputFile.getName());
    } else {//  w  ww .  java  2s.c  o  m
        return "output" + (fileIndex++);
    }
}

From source file:MyFormApp.java

void pdfToimage(File filename) throws FileNotFoundException, IOException { //?pdf ?

    // TODO Auto-generated method stub
    File pdfFile = new File(filename.toString()); // pdf
    RandomAccessFile raf = new RandomAccessFile(pdfFile, "r");
    FileChannel channel = raf.getChannel();
    ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
    PDFFile pdf = new PDFFile(buf);

    int i = 0;//ww  w .j  a  v  a  2 s.  c  o m
    String fileNameWithOutExt = FilenameUtils.removeExtension(filename.getName());

    Rectangle rect = new Rectangle(0, 0, (int) pdf.getPage(i).getBBox().getWidth(), //
            (int) pdf.getPage(i).getBBox().getHeight());
    BufferedImage bufferedImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);

    Image image = pdf.getPage(i).getImage(rect.width, rect.height, // width & height
            rect, // clip rect
            null, // null for the ImageObserver
            true, // fill background with white
            true // block until drawing is done
    );
    Graphics2D bufImageGraphics = bufferedImage.createGraphics();
    bufImageGraphics.drawImage(image.getScaledInstance(100, 100, Image.SCALE_AREA_AVERAGING), 0, 0, null);

    ImageIO.write(bufferedImage, "PNG", new File(PATH + fileNameWithOutExt + ".png")); //? 
}