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.moneydance.modules.features.importlist.io.ImportOneOperation.java

private String getAccountNumberForFile(final File argFile) {
    final String fileName = FilenameUtils.removeExtension(argFile.getName());

    Account rootAccount = this.context.getCurrentAccountBook().getRootAccount();

    String accountNumber = "-1";

    for (Iterator<Account> iterator = AccountUtil.getAccountIterator(rootAccount); iterator.hasNext();) {
        final Account account = iterator.next();
        if (!AcctFilter.NON_CATEGORY_FILTER.matches(account) || rootAccount.equals(account)) {
            continue;
        }/*from  w  w  w .  j  av a 2  s.  c om*/

        final String accountName = account.getFullAccountName();
        if (this.isEqual(accountName, fileName)) {
            LOG.config(String.format("Found matching account \"%s\" for file %s", account.getFullAccountName(),
                    argFile.getName()));
            accountNumber = String.valueOf(account.getAccountNum());
        }
    }

    return accountNumber;
}

From source file:acmi.l2.clientmod.l2resources.Environment.java

public Collection<File> getPackage(String name) {
    return listFiles().filter(file -> FilenameUtils.removeExtension(file.getName()).equalsIgnoreCase(name))
            .collect(Collectors.toList());
}

From source file:de.uzk.hki.da.format.PublishXSLTConversionStrategy.java

/**
 * Convert file./*from  ww w.  j  av  a 2 s.  c  o m*/
 *
 * @param ci the ci
 * @return the list
 * @throws FileNotFoundException the file not found exception
 * @throws IllegalStateException the illegal state exception
 * @author Daniel M. de Oliveira
 * @author Sebastian Cuy
 */
@Override
public List<Event> convertFile(ConversionInstruction ci) throws FileNotFoundException, IllegalStateException {
    if (object == null)
        throw new IllegalStateException("Object not set");
    if (object.getIdentifier() == null || object.getIdentifier().equals(""))
        throw new IllegalStateException("object.getIdentifier() - returns no valid value");

    String objectId = object.getIdentifier().substring(object.getIdentifier().indexOf("-") + 1);
    logger.debug("objectId: " + objectId);

    Source xmlSource = createXMLSource(ci.getSource_file().toRegularFile());

    String targetFileName = FilenameUtils
            .removeExtension(FilenameUtils.getName(ci.getSource_file().toRegularFile().getAbsolutePath()));
    if (!ci.getConversion_routine().getName().endsWith("_paths-for-presenter"))
        targetFileName += "_" + ci.getConversion_routine().getName();

    List<Event> results = new ArrayList<Event>();
    DAFile publFile = new DAFile(object.getLatestPackage(), "dip/public",
            ci.getTarget_folder() + "/" + targetFileName + ".xml");
    DAFile instFile = new DAFile(object.getLatestPackage(), "dip/institution",
            ci.getTarget_folder() + "/" + targetFileName + ".xml");

    new File(object.getDataPath() + "/dip/public/" + ci.getTarget_folder()).mkdirs();
    new File(object.getDataPath() + "/dip/institution/" + ci.getTarget_folder()).mkdirs();

    logger.debug("Will transform {} to {}", ci.getSource_file(), publFile);
    logger.debug("Will transform {} to {}", ci.getSource_file(), instFile);
    try {
        if (objectId != null)
            transformer.setParameter("object-id", objectId);

        transformer.transform(xmlSource, new StreamResult(publFile.toRegularFile().getAbsolutePath()));
        transformer.transform(xmlSource, new StreamResult(instFile.toRegularFile().getAbsolutePath()));

    } catch (TransformerException e) {
        throw new RuntimeException("Error while transforming xml.", e);
    }

    Event e1 = new Event();
    e1.setType("CONVERT");
    e1.setDetail(stylesheet);
    e1.setSource_file(ci.getSource_file());
    e1.setTarget_file(publFile);
    e1.setDate(new Date());

    Event e2 = new Event();
    e2.setType("CONVERT");
    e2.setDetail(stylesheet);
    e2.setSource_file(ci.getSource_file());
    e2.setTarget_file(instFile);
    e2.setDate(new Date());

    results.add(e1);
    results.add(e2);
    return results;
}

From source file:MSUmpire.SpectrumParser.mzXMLParser.java

private void FSScanPosWrite() {
    try {/*from   w  w w  . j a v a  2  s. com*/
        Logger.getRootLogger()
                .debug("Writing ScanPos to file:" + FilenameUtils.removeExtension(filename) + ".ScanPosFS..");
        FileOutputStream fout = new FileOutputStream(FilenameUtils.removeExtension(filename) + ".ScanPosFS",
                false);
        FSTObjectOutput oos = new FSTObjectOutput(fout);
        oos.writeObject(ScanIndex);
        oos.close();
        fout.close();
    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
    }
}

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

/**
 * Convert file./*from  w ww  .java2 s.  c o m*/
 *
 * @param ci the ci
 * @return the list
 * @throws FileNotFoundException the file not found exception
 */
@Override
public List<Event> convertFile(WorkArea wa, ConversionInstruction ci) throws FileNotFoundException {
    if (pkg == null)
        throw new IllegalStateException("Package not set");
    Path.make(wa.dataPath(), object.getNameOfLatestBRep(), ci.getTarget_folder()).toFile().mkdirs();

    String[] commandAsArray = assemble(wa, ci, object.getNameOfLatestBRep());
    if (!cliConnector.execute(commandAsArray))
        throw new RuntimeException("convert did not succeed");

    String targetSuffix = ci.getConversion_routine().getTarget_suffix();
    if (targetSuffix.equals("*"))
        targetSuffix = FilenameUtils.getExtension(toAbsolutePath(wa.dataPath(), ci.getSource_file()));
    DAFile result = new DAFile(object.getNameOfLatestBRep(),
            ci.getTarget_folder() + "/"
                    + FilenameUtils.removeExtension(Matcher.quoteReplacement(
                            FilenameUtils.getName(toAbsolutePath(wa.dataPath(), ci.getSource_file()))))
                    + "." + targetSuffix);

    Event e = new Event();
    e.setType("CONVERT");
    e.setDetail(StringUtilities.createString(commandAsArray));
    e.setSource_file(ci.getSource_file());
    e.setTarget_file(result);
    e.setDate(new Date());

    List<Event> results = new ArrayList<Event>();
    results.add(e);
    return results;
}

From source file:de.nbi.ontology.test.OntologyUtilTest.java

/**
 * Test, if concept labels are created properly. The input file contains a
 * URI in each line.//w  w  w  .jav a  2s. c  o  m
 * 
 * @param inFile
 *            input file
 * @throws IOException
 */
@SuppressWarnings("unchecked")
@Test(dataProviderClass = TestFileProvider.class, dataProvider = "labelTestFiles", groups = { "functest" })
public void getLabel(File inFile) throws IOException {

    // TODO. With the recent change to the OntologyUtil class, labels are
    // not extracted from a concept's uri any more. Instead, the RDF Label
    // annotations are used. Thus, a concept can have more than one label now.
    // The problem is that no assumption about the order in which the labels
    // are returned can be made. We have to rewrite the test case such that
    // it does not make this assumption.

    log.info("Processing " + inFile.getName());
    String basename = FilenameUtils.removeExtension(inFile.getAbsolutePath());
    File outFile = new File(basename + ".out");
    File resFile = new File(basename + ".res");

    List<String> uris = FileUtils.readLines(inFile);
    PrintWriter w = new PrintWriter(new FileWriter(outFile));

    for (String u : uris) {
        OntClass clazz = index.getModel().getOntClass(u);
        List<String> labels = OntologyUtils.getLabels(clazz);
        for (String l : labels) {
            log.debug("** " + u + " => " + l);
            w.println(l);
        }
    }
    w.flush();
    w.close();

    Assert.assertTrue(FileUtils.contentEquals(outFile, resFile));
}

From source file:com.alibaba.otter.node.etl.common.io.ArchiveBeanIntegration.java

@Test
public void test_unpack() {
    ArchiveBean archiveBean = new ArchiveBean();
    try {//w  w w.j  a  v a 2  s. com
        archiveBean.afterPropertiesSet();
        archiveBean.setUseLocalFileMutliThread(false);
    } catch (Exception e1) {
        want.fail();
    }

    File archiveFile = new File("/tmp/otter/test.gzip");
    // for (File archiveFile : archiveFiles.listFiles()) {
    // if (archiveFile.isDirectory()) {
    // continue;
    // }
    //
    // if (!"FileBatch-2013-03-07-16-27-05-245-369-3209577.gzip".equals(archiveFile.getName())) {
    // continue;
    // }

    System.out.println("start unpack : " + archiveFile.getName());
    File targetFile = new File("/tmp/otter", FilenameUtils.removeExtension(archiveFile.getName()));
    archiveBean.unpack(archiveFile, targetFile);
    // }
}

From source file:com.jci.utils.CommonUtils.java

/**
 * Gets the dest mapping.//from www .java2  s  .  com
 *
 * @param folderUrl the folder url
 * @return the dest mapping
 */
public TreeMap<String, HashMap<Integer, String>> getDestMapping(String folderUrl) { // NO_UCD (unused code)
    HashMap<Integer, String> map = null;
    ObjectMapper mapper = new ObjectMapper();

    TreeMap<String, HashMap<Integer, String>> mappingList = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
    File folder = new File(folderUrl);
    File[] listOfFiles = folder.listFiles();

    for (int i = 0; i < listOfFiles.length; i++) {//reading only 1 file need to make changes
        if (listOfFiles[i].isFile()) {
            TypeReference<HashMap<Integer, String>> typeRef = new TypeReference<HashMap<Integer, String>>() {
            };
            try {
                map = mapper.readValue(listOfFiles[i], typeRef);
                mappingList.put(FilenameUtils.removeExtension(listOfFiles[i].getName()), map);
            } catch (IOException e) {
                LOG.error("### Exception in   ####", e);

            }
        }
    }
    LOG.error("mappingList--->" + mappingList);
    return mappingList;
}

From source file:de.flashpixx.rrd_antlr4.generator.IBaseGenerator.java

/**
 * ctor/*  w  ww  .  j  a  va  2s . c o m*/
 *
 * @param p_baseoutputdirectory base output directory
 * @param p_templates array with exporting templates
 * @param p_imports set with imported grammar files
 * @param p_docuclean set with documentation strings
 */
protected IBaseGenerator(final File p_baseoutputdirectory, final Set<File> p_imports,
        final Set<String> p_docuclean, final Set<ETemplate> p_templates) {
    m_docuclean = p_docuclean;
    m_templates = p_templates;
    m_baseoutput = p_baseoutputdirectory;
    m_imports = Collections.unmodifiableMap(p_imports.parallelStream()
            .collect(Collectors.toMap(i -> FilenameUtils.removeExtension(i.getName()), i -> i)));
}

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

/**
 * Convert file.// ww  w  . ja  v  a  2  s  . co  m
 *
 * @param ci the ci
 * @return the list
 * @throws FileNotFoundException the file not found exception
 * @throws IllegalStateException the illegal state exception
 * @author Daniel M. de Oliveira
 * @author Sebastian Cuy
 */
@Override
public List<Event> convertFile(WorkArea wa, ConversionInstruction ci)
        throws FileNotFoundException, IllegalStateException {
    if (object == null)
        throw new IllegalStateException("Object not set");
    if (object.getIdentifier() == null || object.getIdentifier().equals(""))
        throw new IllegalStateException("object.getIdentifier() - returns no valid value");

    String objectId = object.getIdentifier().substring(object.getIdentifier().indexOf("-") + 1);
    logger.debug("objectId: " + objectId);

    Source xmlSource = createXMLSource(wa.toFile(ci.getSource_file()));

    String targetFileName = FilenameUtils
            .removeExtension(FilenameUtils.getName(wa.toFile(ci.getSource_file()).getAbsolutePath()));
    if (!ci.getConversion_routine().getName().endsWith("_paths-for-presenter"))
        targetFileName += "_" + ci.getConversion_routine().getName();

    List<Event> results = new ArrayList<Event>();
    DAFile publFile = new DAFile(WorkArea.TMP_PIPS + "/public",
            ci.getTarget_folder() + "/" + targetFileName + ".xml");
    DAFile instFile = new DAFile(WorkArea.TMP_PIPS + "/institution",
            ci.getTarget_folder() + "/" + targetFileName + ".xml");

    new File(wa.dataPath() + "/" + WorkArea.TMP_PIPS + "/public/" + ci.getTarget_folder()).mkdirs();
    new File(wa.dataPath() + "/" + WorkArea.TMP_PIPS + "/institution/" + ci.getTarget_folder()).mkdirs();

    logger.debug("Will transform {} to {}", ci.getSource_file(), publFile);
    logger.debug("Will transform {} to {}", ci.getSource_file(), instFile);
    try {
        if (objectId != null)
            transformer.setParameter("object-id", objectId);

        transformer.transform(xmlSource, new StreamResult(wa.toFile(publFile).getAbsolutePath()));
        transformer.transform(xmlSource, new StreamResult(wa.toFile(instFile).getAbsolutePath()));

    } catch (TransformerException e) {
        throw new RuntimeException("Error while transforming xml.", e);
    }

    Event e1 = new Event();
    e1.setType("CONVERT");
    e1.setDetail(stylesheet);
    e1.setSource_file(ci.getSource_file());
    e1.setTarget_file(publFile);
    e1.setDate(new Date());

    Event e2 = new Event();
    e2.setType("CONVERT");
    e2.setDetail(stylesheet);
    e2.setSource_file(ci.getSource_file());
    e2.setTarget_file(instFile);
    e2.setDate(new Date());

    results.add(e1);
    results.add(e2);
    return results;
}