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:com.opendoorlogistics.core.utils.ui.FileBrowserPanel.java

private static JButton createBrowseButton(final boolean directoriesOnly, final String browserApproveButtonText,
        final JTextField textField, final FileFilter... fileFilters) {
    JButton browseButton = new JButton("...");
    browseButton.addActionListener(new ActionListener() {

        @Override/*www .  j  a va 2  s.  c om*/
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser();

            if (textField.getText() != null) {
                File file = new File(textField.getText());

                // if the file doesn't exist but the directory does, get that
                if (!file.exists() && file.getParentFile() != null && file.getParentFile().exists()) {
                    file = file.getParentFile();
                }

                if (!directoriesOnly && file.isFile()) {
                    chooser.setSelectedFile(file);
                }

                if (file.isDirectory() && file.exists()) {
                    chooser.setCurrentDirectory(file);
                }
            }

            if (directoriesOnly) {
                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            }

            // add filters and automatically select correct one
            if (fileFilters.length == 1) {
                chooser.setFileFilter(fileFilters[0]);
            } else {
                for (FileFilter filter : fileFilters) {
                    chooser.addChoosableFileFilter(filter);
                    if (filter instanceof FileNameExtensionFilter) {
                        if (matchesFilter((FileNameExtensionFilter) filter, textField.getText())) {
                            chooser.setFileFilter(filter);
                        }
                    }
                }
            }

            if (chooser.showDialog(textField, browserApproveButtonText) == JFileChooser.APPROVE_OPTION) {
                //File selected = processSelectedFile(chooser.getSelectedFile());
                File selected = chooser.getSelectedFile();

                String path = selected.getPath();
                FileFilter filter = chooser.getFileFilter();
                if (filter != null && filter instanceof FileNameExtensionFilter) {

                    boolean found = matchesFilter(((FileNameExtensionFilter) chooser.getFileFilter()), path);

                    if (!found) {
                        String[] exts = ((FileNameExtensionFilter) chooser.getFileFilter()).getExtensions();
                        if (exts.length > 0) {
                            path = FilenameUtils.removeExtension(path);
                            path += "." + exts[0];
                        }
                    }

                }
                textField.setText(path);
            }
        }
    });

    return browseButton;
}

From source file:it.redturtle.mobile.apparpav.MeteogramAdapter.java

/**
 * SINGLE IMAGE ROW/*w w  w  .  j a  v  a2 s  . c  o  m*/
 * @param att
 * @param linear
 * @return
 */
public LinearLayout getSingleImageRow(Map<String, String> att, LinearLayout linear) {

    LinearLayout container_layout = new LinearLayout(context);
    container_layout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.view_shape_meteo));
    container_layout.setMinimumHeight(46);
    container_layout.setVerticalGravity(Gravity.CENTER);

    LinearLayout.LayoutParams value = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.5f);
    TextView tx = new TextView(context);
    tx.setText(att.get("title"));
    tx.setTextSize(11);
    tx.setTypeface(null, Typeface.BOLD);
    tx.setGravity(Gravity.LEFT);
    tx.setPadding(3, 0, 0, 2);
    tx.setTextColor(Color.rgb(66, 66, 66));
    container_layout.addView(tx, value);

    LinearLayout.LayoutParams value_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 40, 0.5f);
    ImageView img = new ImageView(context);
    String path = "it.redturtle.mobile.apparpav:drawable/" + FilenameUtils.removeExtension(att.get("value"));
    img.setImageResource(context.getResources().getIdentifier(path, null, null));
    img.setPadding(0, 3, 0, 3);
    container_layout.addView(img, value_params);

    linear.addView(container_layout);
    return linear;
}

From source file:com.uwsoft.editor.controlles.ResolutionManager.java

public void createResizedAnimations(ResolutionEntryVO resolution) {
    String currProjectPath = dataManager.getCurrentWorkingPath() + File.separator
            + dataManager.getCurrentProjectVO().projectName;

    // Unpack spine orig
    File spineSourceDir = new File(currProjectPath + File.separator + "assets/orig/spine-animations");
    if (spineSourceDir.exists()) {
        for (File entry : spineSourceDir.listFiles()) {
            if (entry.isDirectory()) {
                String animName = FilenameUtils.removeExtension(entry.getName());
                createResizedSpineAnimation(animName, resolution);
            }/*w  ww .  j  av  a  2  s .com*/
        }
    }

    //Unpack sprite orig
    File spriteSourceDir = new File(currProjectPath + File.separator + "assets/orig/sprite-animations");
    if (spriteSourceDir.exists()) {
        for (File entry : spriteSourceDir.listFiles()) {
            if (entry.isDirectory()) {
                String animName = FilenameUtils.removeExtension(entry.getName());
                createResizedSpriteAnimation(animName, resolution);
            }
        }
    }
}

From source file:com.wx3.galacdecks.Bootstrap.java

private void importRules(GameDatastore datastore, String path) throws IOException {
    Files.walk(Paths.get(path)).forEach(filePath -> {
        if (Files.isRegularFile(filePath)) {
            try {
                if (FilenameUtils.getExtension(filePath.getFileName().toString()).toLowerCase().equals("js")) {
                    String id = FilenameUtils.removeExtension(filePath.getFileName().toString());
                    List<String> lines = Files.readAllLines(filePath);
                    if (lines.size() < 3) {
                        throw new RuntimeException(
                                "Script file should have at least 3 lines: description, trigger, and code.");
                    }/* w  w  w .  ja va2s  .  c  o  m*/
                    String description = lines.get(0).substring(2).trim();

                    String trigger = lines.get(1).substring(11).trim();
                    // Check that this actually is a valid trigger event:
                    try {
                        if (!trigger.equals(GameRules.BUFF_PHASE)) {
                            Class.forName(eventPackage + "." + trigger);
                        }

                    } catch (ClassNotFoundException e) {
                        throw new RuntimeException("No such GameEvent: " + trigger);
                    }
                    String script = String.join("\n", lines);
                    EntityRule rule = EntityRule.createRule(trigger, script, id, description);
                    datastore.createRule(rule);
                    ruleCache.put(id, rule);
                    logger.info("Imported rule " + id);
                }
            } catch (Exception e) {
                throw new RuntimeException("Failed to parse " + filePath + ": " + e.getMessage());
            }
        }
    });
}

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

private void complete() {
    boolean success = true;
    String location = null;/* w  w  w  . ja  v  a 2 s . c  om*/
    if (link.isCompressed()) {
        status = STATUS_UNCOMPRESSING;
        location = FilenameUtils.removeExtension(savePath.getAbsolutePath());
        success = ZipUtils.unzip(savePath, new File(location));
    }

    if (success) {
        if (listener != null) {
            listener.onComplete(this);
        }

        status = STATUS_COMPLETE;

        manager.incrementDownloadsToReview();
        Engine.instance().notifyDownloadFinished(getDisplayName(), getSavePath());

        if (savePath.getAbsoluteFile().exists()) {
            Librarian.instance()
                    .scan(link.isCompressed() ? new File(location) : getSavePath().getAbsoluteFile());
        }
    } else {
        error(new Exception("Error"));
    }
}

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

@Override
public void execute() throws IOException {

    HeptamerInfo heptamers = null;//  www .  ja v  a  2s  .co  m
    try {
        if (heptamerInfoFilename != null) {
            heptamers = HeptamerInfo.load(heptamerInfoFilename);
        }

    } catch (ClassNotFoundException e) {
        System.err.println("Cannot load heptamer information from file " + heptamerInfoFilename);
        System.exit(1);
    }

    final ProgressLogger progress = new ProgressLogger();
    progress.start();
    progress.displayFreeMemory = true;
    WeightCalculator calculator = null;
    WeightCalculationMethod method = null;
    try {
        method = WeightCalculationMethod.valueOf(estimationMethod.toUpperCase());
    } catch (IllegalArgumentException e) {
        System.err.println("The estimation method entered is not valid. Valid methods include "
                + "heptamers, GC, AT, A, T, C, G ");
        System.exit(1);
    }

    switch (method) {
    case HEPTAMERS:
        if (heptamers == null) {
            System.err.println("Heptamer info must be provided to estimate heptamer weights.");
            System.exit(0);
        }
        calculator = new HeptamerWeight(heptamers);

        break;
    case G: {
        final BaseProportionWeight calc = new BaseProportionWeight(colorSpace);
        calc.setBase('G');
        calculator = calc;
        break;
    }

    case C: {
        final BaseProportionWeight calc = new BaseProportionWeight(colorSpace);
        calc.setBase('C');
        calculator = calc;
        break;
    }
    case A: {
        final BaseProportionWeight calc = new BaseProportionWeight(colorSpace);
        calc.setBase('A');
        calculator = calc;
        break;
    }
    case T: {
        final BaseProportionWeight calc = new BaseProportionWeight(colorSpace);
        calc.setBase('T');
        calculator = calc;
        break;
    }
    case GC:
        calculator = new GCProportionWeight(colorSpace);
        break;
    case AT:
        calculator = new ATProportionWeight(colorSpace);
        break;
    case ATGC:
        calculator = new ATGCCorrectionWeight(colorSpace);
        break;
    }

    for (final String inputFilename : inputFilenames) {
        // for each reads file:
        LOG.info("Now scanning " + inputFilename);

        if (inputFilenames.size() >= 1) {
            // if we process one or more reads file, build the map filename dynamically for each input file.
            mapFilename = FilenameUtils.removeExtension(inputFilename) + "." + calculator.id() + "-weights";
        }
        final ReadsReader reader = new ReadsReader(new FileInputStream(inputFilename));
        try {
            final WeightsInfo weights = new WeightsInfo();
            final MutableString sequence = new MutableString();
            int numberOfReads = 0;
            for (final Reads.ReadEntry readEntry : reader) {
                ReadsReader.decodeSequence(readEntry, sequence);
                final int readIndex = readEntry.getReadIndex();
                final float weight = calculator.weight(sequence);

                weights.setWeight(readIndex, weight);

                progress.lightUpdate();
                numberOfReads++;
            }
            weights.size(numberOfReads);
            progress.stop();
            weights.save(mapFilename);

        } finally {

            if (reader != null) {
                try {
                    reader.close();

                } catch (IOException e) { // NOPMD
                    // silently ignore
                }
            }
        }
    }

}

From source file:de.tudarmstadt.ukp.dkpro.core.io.brat.BratReader.java

private void readText(JCas aJCas, Resource res) throws IOException {
    String annUrl = res.getResource().getURL().toString();
    String textUrl = FilenameUtils.removeExtension(annUrl) + ".txt";

    try (InputStream is = new BufferedInputStream(new URL(textUrl).openStream())) {
        aJCas.setDocumentText(IOUtils.toString(is, encoding));
    }/* w  w  w  .j a v  a  2  s.co m*/
}

From source file:de.uniwue.info6.misc.StringTools.java

/**
 *
 *
 * @param path/*from w w  w .  j  av  a 2 s .  co  m*/
 * @return
 */
public static String normalizeFileName(String path) {
    String newName = FilenameUtils.removeExtension(path).toLowerCase();
    return normalize(newName);
}

From source file:de.mprengemann.intellij.plugin.androidicons.forms.MaterialIconsImporter.java

private void fillCategories() {
    categorySpinner.removeAllItems();//  ww  w .ja  va2  s  .c o m
    if (this.assetRoot.getCanonicalPath() == null) {
        return;
    }
    File assetRoot = new File(this.assetRoot.getCanonicalPath());
    final FilenameFilter folderFileNameFiler = new FilenameFilter() {
        @Override
        public boolean accept(File file, String s) {
            return !s.startsWith(".") && new File(file, s).isDirectory()
                    && !PluginSettings.BLACKLISTED_MATERIAL_ICONS_FOLDER
                            .contains(FilenameUtils.removeExtension(s));
        }
    };
    File[] categories = assetRoot.listFiles(folderFileNameFiler);
    Arrays.sort(categories, alphabeticalComparator);
    for (File file : categories) {
        categorySpinner.addItem(file.getName());
    }
}

From source file:de.tudarmstadt.ukp.dkpro.core.api.datasets.internal.actions.Explode.java

public static String getBase(String aFilename) {
    // We always extract archives into a subfolder. Figure out the name of the folder.
    String base = aFilename;//  w w  w.ja va  2 s  .  co  m
    while (base.contains(".")) {
        base = FilenameUtils.removeExtension(base);
    }
    return base;
}