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.collaide.fileuploader.requests.repository.RepositoryRequest.java

private void unzip(File source, File destination) {
    //        try {
    String finalDestionation = new File(destination, FilenameUtils.removeExtension(source.getName()))
            .getAbsolutePath();/*from w  w  w. j  a  v  a2  s.  c  o  m*/
    logger.debug("source: " + source.getAbsolutePath());
    logger.debug("destination: " + finalDestionation);
    try {
        ZipFile zipFile = new ZipFile(source);
        zipFile.extractAll(finalDestionation);
    } catch (ZipException ex) {
        logger.error("error while unzipping: " + ex);
    }
    //            destination.mkdirs();
    //            FileSystemManager fileManager = VFS.getManager();
    //            FileObject fileObject = fileManager.resolveFile(source.getAbsolutePath());
    //            FileObject zipFile = fileManager.createFileSystem(fileObject);
    //            fileManager.toFileObject(destination).copyFrom(zipFile, new AllFileSelector());
    //            zipFile.close();
    //            fileObject.close();
    //
    //        } catch (FileSystemException ex) {
    //            logger.error("error while unzipping: " + ex);
    //        }
}

From source file:com.qwazr.compiler.JavaCompiler.java

private Collection<File> filterUptodate(File parentDir, File[] javaSourceFiles) {
    if (javaSourceFiles == null)
        return null;
    final Collection<File> finalJavaFiles = new ArrayList<File>();
    if (javaSourceFiles.length == 0)
        return finalJavaFiles;
    final File parentClassDir = new File(javaClassesDirectory,
            parentDir.getAbsolutePath().substring(javaSourcePrefixSize));
    for (File javaSourceFile : javaSourceFiles) {
        final File classFile = new File(parentClassDir,
                FilenameUtils.removeExtension(javaSourceFile.getName()) + ".class");
        if (classFile.exists() && classFile.lastModified() > javaSourceFile.lastModified())
            continue;
        finalJavaFiles.add(javaSourceFile);
    }//from  ww w .j av  a2  s.  c o  m
    return finalJavaFiles;
}

From source file:com.vvote.verifierlibrary.utils.io.IOUtils.java

/**
 * Gets the name of a file without the extension
 * //  w  w w  .  j av a  2 s  .  c o  m
 * @param filename
 * @return the name of a file without the extension
 */
public static String getFileNameWithoutExtension(String filename) {
    return FilenameUtils.removeExtension(new File(filename).getName());
}

From source file:io.github.swagger2markup.Swagger2MarkupMojo.java

private String extractSwaggerFileNameWithoutExtension(Swagger2MarkupConverter converter) {
    return FilenameUtils.removeExtension(new File(converter.getContext().getSwaggerLocation()).getName());
}

From source file:ml.hsv.java

public static fileData[] batchColorFeatureBuilder(String ip, int N, int C_h, int C_s, int C_v, File trainFile,
        File fileInputList, int cellDimension) throws IOException {
    //get array of all files 

    File ipFiles = new File(ip);

    File allImages[] = ipFiles.listFiles();
    int nImages = allImages.length;
    fileData allImageData[] = new fileData[nImages];

    FileWriter op = new FileWriter(trainFile.toString());
    FileWriter op2 = new FileWriter(fileInputList.toString());

    for (int i = 0; i < nImages; i++) {
        //System.out.print("On file number :"+(i+1)+", "+allImages[i].getName() + "\n");

        String fileNameWithOutExt = FilenameUtils.removeExtension(allImages[i].getName());

        op2.write(fileNameWithOutExt + "\n");
        op2.flush();//  ww  w .  jav  a  2  s  .c om

        //System.out.println(allImages[i].getName());
        if (allImages[i].getName().contains("cat")) //1=dog, 0=cat, -1=unknown
        {
            allImageData[i] = new fileData(0, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())),
                    N, C_h, C_s, C_v, cellDimension));
        } else if (allImages[i].getName().contains("dog")) {
            allImageData[i] = new fileData(1, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())),
                    N, C_h, C_s, C_v, cellDimension));
        } else if (allImages[i].getName().contains("airplane")) {
            allImageData[i] = new fileData(2, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())),
                    N, C_h, C_s, C_v, cellDimension));
        } else if (allImages[i].getName().contains("automobile")) {
            allImageData[i] = new fileData(3, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())),
                    N, C_h, C_s, C_v, cellDimension));
        } else if (allImages[i].getName().contains("bird")) {
            allImageData[i] = new fileData(4, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())),
                    N, C_h, C_s, C_v, cellDimension));
        } else if (allImages[i].getName().contains("deer")) {
            allImageData[i] = new fileData(5, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())),
                    N, C_h, C_s, C_v, cellDimension));
        } else if (allImages[i].getName().contains("frog")) {
            allImageData[i] = new fileData(6, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())),
                    N, C_h, C_s, C_v, cellDimension));
        } else if (allImages[i].getName().contains("horse")) {
            allImageData[i] = new fileData(7, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())),
                    N, C_h, C_s, C_v, cellDimension));
        } else if (allImages[i].getName().contains("ship")) {
            allImageData[i] = new fileData(8, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())),
                    N, C_h, C_s, C_v, cellDimension));
        } else if (allImages[i].getName().contains("truck")) {
            allImageData[i] = new fileData(9, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())),
                    N, C_h, C_s, C_v, cellDimension));
        }

        //store intermed. results start here
        StringBuffer ip2 = new StringBuffer();
        ip2.append(allImageData[i].type);
        for (int j = 0; j < allImageData[i].colorFeatureVector.size(); j++) {
            if (allImageData[i].colorFeatureVector.get(j)) {
                ip2.append(" " + (j + 1) + ":1");
            }
        }
        ip2.append("\n");
        op.write(ip2.toString());
        op.flush();
        //end intermed. results
    }

    op.close();
    op2.close();
    return allImageData;
}

From source file:main.BasicGenSystemTest.java

/**
 * Test the generation of report by constellation.
 *//* w w w  .  j  av  a  2  s  . c o m*/
@Test
public void testGeneratedReportByConstellation() {
    System.out.println("Running test " + this.getClass().getSimpleName() + "." + new Object() {
    }.getClass().getEnclosingMethod().getName());

    // tex + pdf
    assertTrue(new File(config.getProperty(AJPropertyConstants.FILES_LOCATION.getKey()) + File.separator
            + config.getProperty(AJPropertyConstants.LATEX_REPORT_BY_CONSTELLATION_FILENAME.getKey()))
                    .exists());
    assertTrue(new File(config.getProperty(AJPropertyConstants.FILES_LOCATION.getKey()) + File.separator
            + FilenameUtils.removeExtension(
                    config.getProperty(AJPropertyConstants.LATEX_REPORT_BY_CONSTELLATION_FILENAME.getKey()))
            + ".pdf").exists());
}

From source file:MSUmpire.SpectrumParser.SpectrumParserBase.java

protected boolean FSElutionIndexRead() throws NumberFormatException, FileNotFoundException, IOException {
    if (!new File(FilenameUtils.removeExtension(filename) + ".RTidxFS").exists()) {
        return false;
    }/*from  w w  w.  ja  v a  2s . co m*/
    if (!new File(FilenameUtils.removeExtension(filename) + ".ScanRTFS").exists()) {
        return false;
    }
    if (!new File(FilenameUtils.removeExtension(filename) + ".ScanidxFS").exists()) {
        return false;
    }
    try {
        Logger.getRootLogger()
                .debug("Reading RTidx:" + FilenameUtils.removeExtension(filename) + ".RTidxFS...");
        FileInputStream fileIn = new FileInputStream(FilenameUtils.removeExtension(filename) + ".RTidxFS");
        FSTObjectInput in = new FSTObjectInput(fileIn);
        ElutionTimeToScanNoMap = (TreeMap<Float, Integer>) in.readObject();
        //scanCollection.ElutionTimeToScanNoMap = ElutionTimeToScanNoMap;
        in.close();
        fileIn.close();
    } catch (Exception ex) {
        //i.printStackTrace();
        Logger.getRootLogger().debug("RTidxFS serialization file failed");
        //Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        return false;
    }

    try {
        Logger.getRootLogger()
                .debug("Reading ScanRT:" + FilenameUtils.removeExtension(filename) + ".ScanRTFS...");
        FileInputStream fileIn = new FileInputStream(FilenameUtils.removeExtension(filename) + ".ScanRTFS");
        FSTObjectInput in = new FSTObjectInput(fileIn);
        //            ScanToElutionTime = (HashMap<Integer, Float>) in.readObject();
        ScanToElutionTime = (IntFloatHashMap) in.readObject();
        in.close();
        fileIn.close();
    } catch (Exception ex) {
        //i.printStackTrace();
        Logger.getRootLogger().debug("ScanRTFS serialization file failed");
        //Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        throw new RuntimeException(ex);
    }

    try {
        Logger.getRootLogger()
                .debug("Reading Scanidx:" + FilenameUtils.removeExtension(filename) + ".ScanidxFS...");
        FileInputStream fileIn = new FileInputStream(FilenameUtils.removeExtension(filename) + ".ScanidxFS");
        FSTObjectInput in = new FSTObjectInput(fileIn);
        MsLevelList = (TreeMap<Integer, Integer>) in.readObject();
        for (int value : MsLevelList.values()) {
            if (value == 1) {
                NoMS1Scans++;
            }
        }
        in.close();
        fileIn.close();
    } catch (Exception ex) {
        //i.printStackTrace();
        Logger.getRootLogger().debug("ScanidxFS serialization file failed");
        //Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        return false;
    }

    if (datatype != SpectralDataType.DataType.DDA) {
        if (!new File(FilenameUtils.removeExtension(filename) + ".DIAWindowsFS").exists()) {
            return false;
        }
        try {
            Logger.getRootLogger().debug(
                    "Reading DIAWindows:" + FilenameUtils.removeExtension(filename) + ".DIAWindowsFS...");
            FileInputStream fileIn = new FileInputStream(
                    FilenameUtils.removeExtension(filename) + ".DIAWindowsFS");
            FSTObjectInput in = new FSTObjectInput(fileIn);
            dIA_Setting.DIAWindows = (TreeMap<XYData, ArrayList<Integer>>) in.readObject();
            in.close();
            fileIn.close();
        } catch (Exception ex) {
            //i.printStackTrace();
            Logger.getRootLogger().debug("DIAWindowsFS serialization file failed");
            //Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
            return false;
        }
    }

    if (datatype == SpectralDataType.DataType.WiSIM) {
        if (!new File(FilenameUtils.removeExtension(filename) + ".MS1WindowsFS").exists()) {
            return false;
        }
        try {
            Logger.getRootLogger().debug(
                    "Reading MS1 Windows:" + FilenameUtils.removeExtension(filename) + ".MS1WindowsFS...");
            FileInputStream fileIn = new FileInputStream(
                    FilenameUtils.removeExtension(filename) + ".MS1WindowsFS");
            FSTObjectInput in = new FSTObjectInput(fileIn);
            dIA_Setting.MS1Windows = (TreeMap<XYData, ArrayList<Integer>>) in.readObject();
            in.close();
            fileIn.close();
        } catch (Exception ex) {
            //i.printStackTrace();
            Logger.getRootLogger().debug("MS1WindowsFS serialization file failed");
            //Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
            return false;
        }
    }
    return true;
}

From source file:com.vvote.verifierlibrary.utils.io.IOUtils.java

/**
 * Gets a file path not including the extension of the file
 * /*from   w ww .  j a v a 2 s  .  co m*/
 * @param filename
 * @return file path without the extension of the file
 */
public static String getFilePathWithoutExtension(String filename) {
    return FilenameUtils.removeExtension(new File(filename).getPath());
}

From source file:gov.nih.nci.firebird.test.FirebirdFileFactory.java

public FirebirdFile create(String fullyQualifiedResourcePath) {
    FirebirdFile firebirdFile = create(new byte[0]);
    firebirdFile.setByteDataSource(new ClasspathResource(fullyQualifiedResourcePath));
    String resourceBaseName = new File(fullyQualifiedResourcePath).getName();
    if (fullyQualifiedResourcePath.endsWith(".gz")) {
        firebirdFile.setName(FilenameUtils.removeExtension(resourceBaseName));
    } else {//from   w ww  .  j  a v a  2  s. c o  m
        firebirdFile.setName(resourceBaseName);
    }
    return firebirdFile;
}

From source file:de.teamgrit.grit.checking.compile.HaskellCompileChecker.java

/**
 * checkProgram invokes the Haskell compiler on a given file and reports
 * the output.//from   ww w.j  a v a2  s.  c om
 * 
 * @param pathToProgramFile
 *            Specifies the file or folder containing that should be
 *            compiled. (accepts .lhs and .hs files)
 * @param compilerName
 *            The compiler to be used (usually ghc).
 * @param compilerFlags
 *            Additional flags to be passed to the compiler.
 * @throws FileNotFoundException
 *             Is thrown when the file in pathToProgramFile cannot be
 *             opened
 * @throws BadCompilerSpecifiedException
 *             Is thrown when the given compiler cannot be called
 * @return A {@link CompilerOutput} that contains all compiler messages and
 *         flags on how the compile run went.
 * @throws BadFlagException
 *             When ghc doesn't recognize a flag, this exception is thrown.
 */
@Override
public CompilerOutput checkProgram(Path pathToProgramFile, String compilerName, List<String> compilerFlags)
        throws FileNotFoundException, BadCompilerSpecifiedException, BadFlagException {

    Process compilerProcess = null;

    try {
        // create compiler invocation.
        List<String> compilerInvocation = createCompilerInvocation(pathToProgramFile, compilerName,
                compilerFlags);

        ProcessBuilder compilerProcessBuilder = new ProcessBuilder(compilerInvocation);

        // make sure the compiler stays in its directory.
        compilerProcessBuilder.directory(pathToProgramFile.getParent().toFile());

        compilerProcess = compilerProcessBuilder.start();
        // this will never happen because createCompilerInvocation never
        // throws this Exception. Throw declaration needs to be in method
        // declaration because of the implemented Interface although we
        // never use it in the HaskellCompileChecker
    } catch (CompilerOutputFolderExistsException e) {
        LOGGER.severe("A problem while compiling, which never should happen, occured" + e.getMessage());
    } catch (BadCompilerSpecifiedException e) {
        throw new BadCompilerSpecifiedException(e.getMessage());
    } catch (IOException e) {

        // If we cannot call the compiler we return a CompilerOutput
        // initialized with false, false, indicating
        // that the compiler wasn't invoked properly and that there was no
        // clean Compile.
        CompilerOutput compilerInvokeError = new CompilerOutput();
        compilerInvokeError.setClean(false);
        compilerInvokeError.setCompilerInvoked(false);
        return compilerInvokeError;
    }

    // Now we read compiler output. If everything is ok ghc reports
    // nothing in the errorStream.
    InputStream compilerOutputStream = compilerProcess.getErrorStream();
    InputStreamReader compilerStreamReader = new InputStreamReader(compilerOutputStream);
    BufferedReader compilerOutputBuffer = new BufferedReader(compilerStreamReader);
    String line;

    CompilerOutput compilerOutput = new CompilerOutput();
    compilerOutput.setCompilerInvoked(true);

    List<String> compilerOutputLines = new LinkedList<>();

    try {
        while ((line = compilerOutputBuffer.readLine()) != null) {
            compilerOutputLines.add(line);
        }
        // Errors are separated via an empty line (""). But after the
        // the last error the OutputBuffer has nothing more to write.
        // In order to recognize the last error we insert an empty String
        // at the end of the list.
        // Only needs to be done when there are errors.
        if (compilerOutputLines.size() != 0) {
            line = "";
            compilerOutputLines.add(line);
        }

        compilerOutputStream.close();
        compilerStreamReader.close();
        compilerOutputBuffer.close();
        compilerProcess.destroy();

    } catch (IOException e) {

        // Reading might go wrong here if ghc should unexpectedly die
        LOGGER.severe("Error while reading from compiler stream.");
        compilerOutput.setClean(false);
        compilerOutput.setCompileStreamBroken(true);
        return compilerOutput;
    }

    // ghc -c generates a .o(object) and a .hi(haskell interface) file.
    // But we don't need those files so they can be deleted.
    // The generated files have the same name like our input file so we
    // can just exchange the file endings in order to get the
    // correct file paths for deletion
    if (Files.isDirectory(pathToProgramFile, LinkOption.NOFOLLOW_LINKS)) {

        // we use a file walker in order to find all files in the folder
        // and its subfolders
        RegexDirectoryWalker dirWalker = new RegexDirectoryWalker(".+\\.([Ll])?[Hh][Ss]");
        try {
            Files.walkFileTree(pathToProgramFile, dirWalker);
        } catch (IOException e) {
            LOGGER.severe("Could not walk submission " + pathToProgramFile.toString()
                    + " while building copiler invocation: " + e.getMessage());
        }

        for (Path candidatePath : dirWalker.getFoundFiles()) {
            File candidateFile = candidatePath.toFile();
            if (!candidateFile.isDirectory()) {
                String extension = FilenameUtils.getExtension(candidateFile.toString());
                if (extension.matches("[Ll]?[Hh][Ss]")) {
                    File ghcGeneratedObject = new File(
                            FilenameUtils.removeExtension(candidateFile.toString()) + ".o");
                    File ghcGeneratedInterface = new File(
                            FilenameUtils.removeExtension(candidateFile.toString()) + ".hi");
                    ghcGeneratedObject.delete();
                    ghcGeneratedInterface.delete();
                }
            }
        }
    } else {
        String extension = FilenameUtils.getExtension(pathToProgramFile.toString());
        if (extension.matches("[Ll]?[Hh][Ss]")) {
            File ghcGeneratedObject = new File(
                    FilenameUtils.removeExtension(pathToProgramFile.toString()) + ".o");
            File ghcGeneratedInterface = new File(
                    FilenameUtils.removeExtension(pathToProgramFile.toString()) + ".hi");
            ghcGeneratedObject.delete();
            ghcGeneratedInterface.delete();
        }

    }

    // if there are no errors there is no Output to handle
    if (compilerOutputLines.size() != 0) {
        compilerOutput = splitCompilerOutput(compilerOutputLines, compilerOutput);
    } else {
        compilerOutput.setClean(true);
    }
    return compilerOutput;
}