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:control.Uploader.java

public String getFileNameWithoutExtension() {
    return FilenameUtils.removeExtension(fileName);
}

From source file:com.mapr.ocr.text.ImageToText.java

public static String processImageFile(String fileName) {
    Tesseract instance = new Tesseract(); // JNA Interface Mapping
    File imageFile = new File(fileName);
    String resultText = null;// w  w  w . j  ava  2  s  .  c  om

    instance.setLanguage("eng");

    try {
        resultText = instance.doOCR(imageFile);
    } catch (Exception e) {
        e.printStackTrace();
        LOGGER.log(Level.SEVERE, "Exception processing image file  " + fileName + " " + e.toString());
        String rowKey = FilenameUtils
                .removeExtension(fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length()));
        populateDataInMapRDB(config, errorTable, rowKey, cf, "error", e.toString());
        populateDataInMapRDB(config, errorTable, rowKey, cf, "filepath", fileName);
    } finally {
        return resultText;
    }
}

From source file:nc.noumea.mairie.distiller.DistillerTest.java

@Test
public void bCleanUpTestFiles() {
    // delete input test image
    try {// ww  w .ja  v  a 2  s .c om
        SmbFile dFile = new SmbFile(destinationPath + "/" + testFileName, auth);
        if (dFile.exists()) {
            dFile.delete();
        }

        dFile = new SmbFile(destinationPath + "/" + testFileName, auth);
        Assert.assertFalse(dFile.exists());
    } catch (Exception ex) {
        Assert.assertNull(ex);
    }

    // delete distilled pdf
    try {
        String pdfFileName = FilenameUtils.removeExtension(testFileName) + ".pdf";
        SmbFile sFile = new SmbFile(pdfDirectory + pdfFileName, auth);
        if (sFile.exists()) {
            sFile.delete();
        }
        sFile = new SmbFile(pdfDirectory + pdfFileName, auth);
        Assert.assertFalse(sFile.exists());
    } catch (Exception ex) {
        Assert.assertNull(ex);
    }
}

From source file:cc.kave.commons.externalserializationtests.ExternalTestCaseProvider.java

private static String getTestCaseName(String fileName, String rootPrefix) {
    String fileNameWithoutExtension = FilenameUtils.removeExtension(fileName);
    return fileNameWithoutExtension.substring((rootPrefix + "\\").length());
}

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

@Override
public List<Event> convertFile(WorkArea wa, ConversionInstruction ci

) throws FileNotFoundException {
    if (pkg == null)
        throw new IllegalStateException("Package not set");

    List<Event> results = new ArrayList<Event>();

    for (String audience : audiences) {

        String audience_lc = audience.toLowerCase();
        String repName = WorkArea.TMP_PIPS + "/" + audience_lc;

        Path.make(wa.dataPath(), repName, ci.getTarget_folder()).toFile().mkdirs();

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

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

        Event e = new Event();
        e.setType("CONVERT");
        e.setDetail(StringUtilities.createString(commandAsArray));
        e.setSource_file(ci.getSource_file());
        e.setTarget_file(result);/*w ww .  j  av  a  2  s .c om*/
        e.setDate(new Date());

        results.add(e);

    }

    return results;

}

From source file:de.uni.bremen.monty.moco.codegeneration.CodeWriter.java

private OutputStream initLlvmOutput(Params params) throws FileNotFoundException {
    OutputStream llOutputStream;/*from   w w  w.j a  v a  2  s .  co m*/
    if (params.isGenerateOnlyLLVM()) {
        if (params.getOutputFile() == null) {
            //llOutputStream = System.out;
            llOutputStream = new NopOutputStream();
        } else {
            llOutputStream = new FileOutputStream(params.getOutputFile());
        }
    } else {
        String llFile;
        if (params.getInputFile() != null) {
            llFile = FilenameUtils.removeExtension(params.getInputFile()) + ".ll";
        } else {
            llFile = params.getInputFolder() + "/Main.ll";
        }
        llOutputStream = new FileOutputStream(llFile);
        params.setLlFile(llFile);
    }
    return llOutputStream;
}

From source file:ch.cern.dss.teamcity.agent.MockAgentBuildRunner.java

/**
 * Create the BuildProcess extension that will be actually run as this build stage.
 *
 * @param build   the currently running build.
 * @param context this build runner's context parameters.
 *
 * @return an instance of our custom BuildProcess extension.
 * @throws RunBuildException/* w  ww.  j a v  a2 s  . c o m*/
 */
@NotNull
@Override
public BuildProcess createBuildProcess(@NotNull AgentRunningBuild build, @NotNull BuildRunnerContext context)
        throws RunBuildException {

    Map<String, String> runnerParameters = context.getRunnerParameters();
    BuildProgressLogger logger = build.getBuildLogger();

    // Append config extension if necessary
    List<String> chrootNamesPattern = FileUtil
            .splitStringOnWhitespace(runnerParameters.get(MockConstants.CHROOTS));
    for (ListIterator<String> i = chrootNamesPattern.listIterator(); i.hasNext();) {
        String chrootName = i.next();
        if (!chrootName.endsWith(".cfg")) {
            i.set(chrootName + ".cfg");
        }
    }

    // Find mock config files
    List<String> mockConfigFiles = FileUtil.findFiles(runnerParameters.get(MockConstants.CONFIG_DIR),
            StringUtil.join(chrootNamesPattern, " "));

    List<String> chrootNames = new ArrayList<String>();
    for (String configFile : mockConfigFiles) {
        chrootNames.add(FilenameUtils.removeExtension(new File(configFile).getName()));
    }
    logger.message("Building in the following chroots: " + Arrays.toString(chrootNames.toArray()));

    // Find srpms
    List<String> srpms = FileUtil.findFiles(runnerParameters.get(MockConstants.SOURCE_RPM_DIR),
            runnerParameters.get(MockConstants.SOURCE_RPMS));
    logger.message("Building packages: " + Arrays.toString(srpms.toArray()));

    // Return custom build process
    return new MockBuildProcess(chrootNames, srpms, runnerParameters, build.getArtifactsPaths(),
            context.getBuildParameters().getEnvironmentVariables(), logger);
}

From source file:ca.on.oicr.pde.workflows.GATKHaplotypeCallerWorkflow.java

@Override
public Map<String, SqwFile> setupFiles() {

    List<String> inputFilesList = Arrays.asList(StringUtils.split(getProperty("input_files"), ","));
    Set<String> inputFilesSet = new HashSet<>(inputFilesList);

    if (inputFilesList.size() != inputFilesSet.size()) {
        throw new RuntimeException("Duplicate files detected in input_files");
    }/*from   w  w  w. ja v a2  s . co m*/

    if ((inputFilesSet.size() % 2) != 0) {
        throw new RuntimeException("Each bam should have a corresponding index");
    }

    Map<String, String> bams = new HashMap<>();
    Map<String, String> bais = new HashMap<>();
    for (String f : inputFilesSet) {
        String fileExtension = FilenameUtils.getExtension(f);
        String fileKey = FilenameUtils.removeExtension(f);
        if (null != fileExtension) {
            switch (fileExtension) {
            case "bam":
                bams.put(fileKey, f);
                break;
            case "bai":
                if (fileKey.endsWith(".bam")) {
                    fileKey = FilenameUtils.removeExtension(fileKey);
                }
                bais.put(fileKey, f);
                break;
            default:
                throw new RuntimeException("Unsupported input file type");
            }
        }
    }

    int id = 0;
    for (Entry<String, String> e : bams.entrySet()) {
        String key = e.getKey();
        String bamFilePath = e.getValue();

        String baiFilePath = bais.get(key);
        if (baiFilePath == null) {
            throw new RuntimeException("Missing index for " + FilenameUtils.getName(bamFilePath));
        }

        SqwFile bam = this.createFile("file_in_" + id++);
        bam.setSourcePath(bamFilePath);
        bam.setType("application/bam");
        bam.setIsInput(true);

        SqwFile bai = this.createFile("file_in_" + id++);
        bai.setSourcePath(baiFilePath);
        bai.setType("application/bam-index");
        bai.setIsInput(true);

        //FIXME: this seems to work for now, it would be better to be able to set the provisionedPath as
        //bai.getProvisionedPath != bai.getOutputPath ...
        //at least with seqware 1.1.0, setting output path changes where the output file will be stored,
        //but the commonly used get provisioned path will return the incorrect path to the file
        bai.setOutputPath(FilenameUtils.getPath(bam.getProvisionedPath()));

        inputBamFiles.add(bam.getProvisionedPath());
    }

    return this.getFiles();
}

From source file:ch.ifocusit.livingdoc.plugin.baseMojo.AbstractAsciidoctorMojo.java

protected void write(AsciiDocBuilder asciiDocBuilder, Format format, String outputFilename)
        throws MojoExecutionException {
    generatedDocsDirectory.mkdirs();/* w w  w.  j  av  a  2  s  . co m*/
    File output = getOutput(outputFilename, Format.adoc);
    try {
        // write adco file
        asciiDocBuilder.writeToFile(generatedDocsDirectory.getAbsolutePath(),
                FilenameUtils.removeExtension(outputFilename), StandardCharsets.UTF_8);
        if (Format.html.equals(format)) {
            // convert adoc to html
            createAsciidoctor().convertFile(output, options());
        }
    } catch (IOException e) {
        throw new MojoExecutionException(
                String.format("Unable to convert asciidoc file '%s' to html !", output.getAbsolutePath()), e);
    }
}

From source file:com.qq.tars.service.PatchService.java

public String war2tgz(String packageWarPath, String serverName) throws Exception {
    String basePath = FilenameUtils.removeExtension(packageWarPath);
    String serverPath = basePath + "/" + serverName;
    String frameZipPath = new ClassPathResource("frame.zip").getFile().getCanonicalPath();

    StringBuilder script = new StringBuilder();
    script.append(String.format("rm -rf %s;", basePath));
    script.append(String.format("mkdir -p %s;", serverPath));
    script.append(String.format("unzip -q %s -d %s;", frameZipPath, serverPath));
    script.append(String.format("unzip -q %s -d %s/apps/ROOT/;", packageWarPath, serverPath));
    script.append(String.format("cd %s;tar -cvzf %s.tgz *;cd -;", basePath, basePath));
    script.append(String.format("rm -rf %s;", basePath));
    script.append(String.format("rm -rf %s;", packageWarPath));
    Pair<Integer, Pair<String, String>> result = SystemUtils.exec(script.toString());
    log.info("script={}, code={}, stdout={}, stderr={}", script, result.getLeft(), result.getRight().getLeft(),
            result.getRight().getRight());
    return basePath + ".tgz";
}