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.moviejukebox.scanner.MediaInfoScanner.java

@SuppressWarnings("resource")
protected MediaInfoStream createStream(String movieFilePath) throws IOException {
    if (MI_READ_FROM_FILE) {
        // check file
        String filename = FilenameUtils.removeExtension(movieFilePath) + ".mediainfo";
        Collection<File> files = FileTools.fileCache.searchFilename(filename, Boolean.FALSE);
        if (files != null && !files.isEmpty()) {
            // create new input stream for reading
            LOG.debug("Reading from file {}", filename);
            return new MediaInfoStream(new FileInputStream(files.iterator().next()));
        }/*ww w. j  a v  a2s. c  om*/
    }

    // Create the command line
    List<String> commandMedia = new ArrayList<>(MI_EXE);
    commandMedia.add(movieFilePath);

    ProcessBuilder pb = new ProcessBuilder(commandMedia);
    // set up the working directory.
    pb.directory(MI_PATH);
    return new MediaInfoStream(pb.start());
}

From source file:eu.intermodalics.tango_ros_streamer.activities.RunningActivity.java

private void setupUI() {
    setContentView(R.layout.running_activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from w w w .  j av  a 2s  . co m
    mUriTextView = (TextView) findViewById(R.id.master_uri);
    mUriTextView.setText(mMasterUri);
    mRosLightImageView = (ImageView) findViewById(R.id.is_ros_ok_image);
    mTangoLightImageView = (ImageView) findViewById(R.id.is_tango_ok_image);
    mlogSwitch = (Switch) findViewById(R.id.log_switch);
    mlogSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
            mDisplayLog = isChecked;
            mLogTextView.setVisibility(isChecked ? View.VISIBLE : View.INVISIBLE);
        }
    });
    mLogTextView = (TextView) findViewById(R.id.log_view);
    mLogTextView.setMovementMethod(new ScrollingMovementMethod());
    mSaveMapButton = (Button) findViewById(R.id.save_map_button);
    mSaveMapButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showSaveMapDialog();
        }
    });
    mLoadOccupancyGridButton = (Button) findViewById(R.id.load_occupancy_grid_button);
    mLoadOccupancyGridButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mOccupancyGridNameList = new ArrayList<String>();
            try {
                String directory = mParameterNode
                        .getStringParam(getString(R.string.occupancy_grid_directory_key));
                File occupancyGridDirectory = new File(directory);
                if (occupancyGridDirectory != null && occupancyGridDirectory.isDirectory()) {
                    File[] files = occupancyGridDirectory.listFiles();
                    for (File file : files) {
                        if (FilenameUtils.getExtension(file.getName()).equals("yaml")) {
                            mOccupancyGridNameList.add(FilenameUtils.removeExtension(file.getName()));
                        }
                    }
                }
                showLoadOccupancyGridDialog(/* firstTry */ true, mOccupancyGridNameList);
            } catch (RuntimeException e) {
                e.printStackTrace();
            }
        }
    });
    updateLoadAndSaveMapButtons();
}

From source file:ffx.algorithms.MolecularDynamics.java

/**
 * <p>//  w w w .ja va 2 s.  c  o m
 * init</p>
 *
 * @param nSteps a int.
 * @param timeStep a double.
 * @param printInterval a double.
 * @param saveInterval a double.
 * @param fileType a String.
 * @param restartFrequency the number of steps between writing restart
 * files.
 * @param temperature a double.
 * @param initVelocities a boolean.
 * @param dyn a {@link java.io.File} object.
 */
public void init(final int nSteps, final double timeStep, final double printInterval, final double saveInterval,
        final String fileType, final double restartFrequency, final double temperature,
        final boolean initVelocities, final File dyn) {

    /**
     * Return if already running.
     */
    if (!done) {
        logger.warning(
                " Programming error - attempt to modify parameters of a running MolecularDynamics instance.");
        return;
    }

    this.nSteps = nSteps;
    totalSimTime = 0.0;
    /**
     * Convert the time step from femtoseconds to picoseconds.
     */
    dt = timeStep * 1.0e-3;

    /**
     * Convert the print interval to a print frequency.
     */
    printFrequency = 100;
    if (printInterval >= this.dt) {
        printFrequency = (int) (printInterval / this.dt);
    }

    /**
     * Convert the save interval to a save frequency.
     */
    saveSnapshotFrequency = 1000;
    if (saveInterval >= this.dt) {
        saveSnapshotFrequency = (int) (saveInterval / this.dt);
    }

    /**
     * Set snapshot file type.
     */
    saveSnapshotAsPDB = true;
    if (fileType.equals("XYZ")) {
        saveSnapshotAsPDB = false;
    } else if (!fileType.equals("PDB")) {
        logger.warning("Snapshot file type unrecognized; saving snaphshots as PDB.\n");
    }

    /**
     * Convert restart frequency to steps.
     */
    saveRestartFileFrequency = 1000;
    if (restartFrequency >= this.dt) {
        saveRestartFileFrequency = (int) (restartFrequency / this.dt);
    }

    assemblies.stream().parallel().forEach((ainfo) -> {
        MolecularAssembly mola = ainfo.getAssembly();
        CompositeConfiguration aprops = ainfo.props;
        File file = mola.getFile();
        String filename = FilenameUtils.removeExtension(file.getAbsolutePath());
        File archFile = ainfo.archiveFile;
        if (archFile == null) {
            archFile = new File(filename + ".arc");
            ainfo.archiveFile = XYZFilter.version(archFile);
        }
        if (ainfo.xyzFilter == null) {
            ainfo.xyzFilter = new XYZFilter(file, mola, mola.getForceField(), aprops);
        }
        if (ainfo.pdbFilter == null) {
            if (!filename.contains("_dyn")) {
                ainfo.pdbFile = new File(filename + "_dyn.pdb");
            }
            ainfo.pdbFilter = new PDBFilter(ainfo.pdbFile, mola, mola.getForceField(), aprops);
        }
    });

    /*File file = molecularAssembly.getFile();
    String filename = FilenameUtils.removeExtension(file.getAbsolutePath());
    if (archiveFile == null) {
    archiveFile = new File(filename + ".arc");
    archiveFile = XYZFilter.version(archiveFile);
    }*/

    String firstFileName = FilenameUtils.removeExtension(molecularAssembly.getFile().getAbsolutePath());

    if (dyn == null) {
        this.restartFile = new File(firstFileName + ".dyn");
        loadRestart = false;
    } else {
        this.restartFile = dyn;
        loadRestart = true;
    }

    /*if (xyzFilter == null) {
    xyzFilter = new XYZFilter(file, molecularAssembly,
            molecularAssembly.getForceField(), properties);
    }*/

    if (dynFilter == null) {
        dynFilter = new DYNFilter(molecularAssembly.getName());
    }

    /*if (pdbFilter == null) {
    if (!filename.contains("_dyn")) {
        pdbFile = new File(filename + "_dyn.pdb");
    }
    pdbFilter = new PDBFilter(pdbFile, molecularAssembly, null, null);
    }*/

    this.targetTemperature = temperature;
    this.initVelocities = initVelocities;
}

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

private void writeSnapshot(String suffix) {
    if (!writeSnapshots) {
        return;//from  w  ww  . j a v  a 2  s . co m
    }
    String filename = FilenameUtils.removeExtension(mola.getFile().toString()) + "." + suffix + "-"
            + numMovesProposed;
    if (snapshotInterleaving) {
        filename = mola.getFile().getAbsolutePath();
        if (!filename.contains("dyn")) {
            filename = FilenameUtils.removeExtension(filename) + "_dyn.pdb";
        }
    }
    File file = new File(filename);
    PDBFilter writer = new PDBFilter(file, mola, null, null);
    writer.writeFile(file, false);
}

From source file:com.github.os72.protocjar.maven.ProtocJarMojo.java

private Collection<String> buildCommand(File file, String version, String type, String pluginPath,
        File outputDir, String outputOptions) throws MojoExecutionException {
    Collection<String> cmd = new ArrayList<String>();
    populateIncludes(cmd);//from   w  ww. j a  va  2s  . com
    cmd.add("-I" + file.getParentFile().getAbsolutePath());
    if ("descriptor".equals(type)) {
        File outFile = new File(outputDir, file.getName());
        cmd.add("--descriptor_set_out=" + FilenameUtils.removeExtension(outFile.toString()) + ".desc");
        cmd.add("--include_imports");
        if (outputOptions != null) {
            for (String arg : outputOptions.split("\\s+"))
                cmd.add(arg);
        }
    } else {
        if (outputOptions != null) {
            cmd.add("--" + type + "_out=" + outputOptions + ":" + outputDir);
        } else {
            cmd.add("--" + type + "_out=" + outputDir);
        }

        if (pluginPath != null) {
            getLog().info("    Plugin path: " + pluginPath);
            cmd.add("--plugin=protoc-gen-" + type + "=" + pluginPath);
        }
    }
    cmd.add(file.toString());
    if (version != null)
        cmd.add("-v" + version);
    return cmd;
}

From source file:com.uwsoft.editor.data.manager.DataManager.java

public File importExternalAnimationIntoProject(File animationFileSource) {
    try {/*  w ww.  j  ava2  s .c  o  m*/
        JsonFilenameFilter jsonFilenameFilter = new JsonFilenameFilter();
        ScmlFilenameFilter scmlFilenameFilter = new ScmlFilenameFilter();
        if (!jsonFilenameFilter.accept(null, animationFileSource.getName())
                && !scmlFilenameFilter.accept(null, animationFileSource.getName())) {
            //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(animationFileSource.getName());
        String sourcePath;
        String animationDataPath;
        String targetPath;
        if (jsonFilenameFilter.accept(null, animationFileSource.getName())) {
            sourcePath = animationFileSource.getAbsolutePath();
            animationDataPath = sourcePath.substring(0, sourcePath.lastIndexOf(File.separator))
                    + File.separator;
            targetPath = currentWorkingPath + "/" + currentProjectVO.projectName
                    + "/assets/orig/spine-animations" + File.separator + fileNameWithOutExt;
            File atlasFileSource = new File(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");
            ArrayList<File> imageFiles = getImageListFromAtlas(atlasFileSource);

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

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

            return atlasFileTarget;

        } else if (scmlFilenameFilter.accept(null, animationFileSource.getName())) {
            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, 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.uwsoft.editor.proxy.ProjectManager.java

public void importSpriteAnimationsIntoProject(final Array<FileHandle> fileHandles,
        ProgressHandler progressHandler) {
    if (fileHandles == null) {
        return;//from  w w w . j ava2 s.  c  o m
    }
    handler = progressHandler;

    ExecutorService executor = Executors.newSingleThreadExecutor();

    executor.execute(() -> {

        String newAnimName = null;

        String rawFileName = fileHandles.get(0).name();
        String fileExtension = FilenameUtils.getExtension(rawFileName);
        if (fileExtension.equals("png")) {
            Settings settings = new Settings();
            settings.square = true;
            settings.flattenPaths = true;

            TexturePacker texturePacker = new TexturePacker(settings);
            FileHandle pngsDir = new FileHandle(fileHandles.get(0).parent().path());
            for (FileHandle entry : pngsDir.list(Overlap2DUtils.PNG_FILTER)) {
                texturePacker.addImage(entry.file());
            }
            String fileNameWithoutExt = FilenameUtils.removeExtension(rawFileName);
            String fileNameWithoutFrame = fileNameWithoutExt.replaceAll("\\d*$", "");
            String targetPath = currentProjectPath + "/assets/orig/sprite-animations" + File.separator
                    + fileNameWithoutFrame;
            File targetDir = new File(targetPath);
            if (targetDir.exists()) {
                try {
                    FileUtils.deleteDirectory(targetDir);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            texturePacker.pack(targetDir, fileNameWithoutFrame);
            newAnimName = fileNameWithoutFrame;
        } else {
            for (FileHandle fileHandle : fileHandles) {
                try {
                    Array<File> imgs = getAtlasPages(fileHandle);
                    String fileNameWithoutExt = FilenameUtils.removeExtension(fileHandle.name());
                    String targetPath = currentProjectPath + "/assets/orig/sprite-animations" + File.separator
                            + fileNameWithoutExt;
                    File targetDir = new File(targetPath);
                    if (targetDir.exists()) {
                        FileUtils.deleteDirectory(targetDir);
                    }
                    for (File img : imgs) {
                        FileUtils.copyFileToDirectory(img, targetDir);
                    }
                    FileUtils.copyFileToDirectory(fileHandle.file(), targetDir);
                    newAnimName = fileNameWithoutExt;
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        if (newAnimName != null) {
            ResolutionManager resolutionManager = facade.retrieveProxy(ResolutionManager.NAME);
            resolutionManager.resizeSpriteAnimationForAllResolutions(newAnimName, currentProjectInfoVO);
        }
    });
    executor.execute(() -> {
        changePercentBy(100 - currentPercent);
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        handler.progressComplete();
    });
    executor.shutdown();
}

From source file:de.uzk.hki.da.model.Object.java

/**
 * Gets the newest files from all representations.
 *
 * @param sidecarExtensions Files with the given extensions are considered sidecar files. Sidecar files are treated differently from other files
 *  (see <a href="https://github.com/da-nrw/DNSCore/blob/master/ContentBroker/src/main/markdown/dip_specification.md#sidecar-files">documentation</a> for details)
 * @return newest DAFile of each Document.  
 * @author Thomas Kleinke/*from   w  w  w.ja  va 2 s  .co m*/
 * @author Daniel M. de Oliveira
 * @throws RuntimeException if it finds a file on the file system to which it cannot find a corresponding attached instance of
 * DAFile in this object.
 */

// TODO make it a set
public List<DAFile> getNewestFilesFromAllRepresentations(String sidecarExts) {
    // document name to newest file instance
    Map<String, DAFile> documentMap = new HashMap<String, DAFile>();

    for (String rep : getReps())
        for (DAFile f : getFilesFromRepresentation(rep)) {
            if (FriendlyFilesUtils.isFriendlyFileExtension(f.getRelative_path(), sidecarExts))
                documentMap.put(f.getRelative_path(), f);
            else
                documentMap.put(FilenameUtils.removeExtension(f.getRelative_path()), f);
        }

    return new ArrayList<DAFile>(documentMap.values());
}

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

public void importSpriteAnimationsIntoProject(final Array<FileHandle> fileHandles,
        ProgressHandler progressHandler) {
    if (fileHandles == null) {
        return;//  ww  w.j av a2  s  .  com
    }
    handler = progressHandler;

    ExecutorService executor = Executors.newSingleThreadExecutor();

    executor.execute(() -> {

        String newAnimName = null;

        String rawFileName = fileHandles.get(0).name();
        String fileExtension = FilenameUtils.getExtension(rawFileName);
        if (fileExtension.equals("png")) {
            Settings settings = new Settings();
            settings.square = true;
            settings.flattenPaths = true;

            TexturePacker texturePacker = new TexturePacker(settings);
            FileHandle pngsDir = new FileHandle(fileHandles.get(0).parent().path());
            for (FileHandle entry : pngsDir.list(Overlap2DUtils.PNG_FILTER)) {
                texturePacker.addImage(entry.file());
            }
            String fileNameWithoutExt = FilenameUtils.removeExtension(rawFileName);
            String fileNameWithoutFrame = fileNameWithoutExt.replaceAll("\\d*$", "");
            String targetPath = currentWorkingPath + "/" + currentProjectVO.projectName
                    + "/assets/orig/sprite-animations" + File.separator + fileNameWithoutFrame;
            File targetDir = new File(targetPath);
            if (targetDir.exists()) {
                try {
                    FileUtils.deleteDirectory(targetDir);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            texturePacker.pack(targetDir, fileNameWithoutFrame);
            newAnimName = fileNameWithoutFrame;
        } else {
            for (FileHandle fileHandle : fileHandles) {
                try {
                    Array<File> imgs = getAtlasPages(fileHandle);
                    String fileNameWithoutExt = FilenameUtils.removeExtension(fileHandle.name());
                    String targetPath = currentWorkingPath + "/" + currentProjectVO.projectName
                            + "/assets/orig/sprite-animations" + File.separator + fileNameWithoutExt;
                    File targetDir = new File(targetPath);
                    if (targetDir.exists()) {
                        FileUtils.deleteDirectory(targetDir);
                    }
                    for (File img : imgs) {
                        FileUtils.copyFileToDirectory(img, targetDir);
                    }
                    FileUtils.copyFileToDirectory(fileHandle.file(), targetDir);
                    newAnimName = fileNameWithoutExt;
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        if (newAnimName != null) {
            ResolutionManager resolutionManager = facade.retrieveProxy(ResolutionManager.NAME);
            resolutionManager.resizeSpriteAnimationForAllResolutions(newAnimName, currentProjectInfoVO);
        }
    });
    executor.execute(() -> {
        changePercentBy(100 - currentPercent);
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        handler.progressComplete();
    });
    executor.shutdown();
}

From source file:it.dfa.unict.CodeRadePortlet.java

private String processInputFile(UploadPortletRequest uploadRequest, String username, String timestamp,
        AppInput appInput) throws CodeRadePortletException, IOException {

    String createdFile = "";
    String fileInputName = "fileupload"; //Input filed name in view.jsp        

    // Get the uploaded file as a file.
    File uploadedFile = uploadRequest.getFile(fileInputName);
    String sourceFileName = uploadRequest.getFileName(fileInputName);
    String modelName = FilenameUtils.removeExtension(sourceFileName);
    appInput.setModelName(modelName);/*from w w w  .ja v  a 2 s .  c o m*/
    String extension = FilenameUtils.getExtension(sourceFileName);

    long sizeInBytes = uploadRequest.getSize(fileInputName);

    if (uploadRequest.getSize(fileInputName) == 0) {
        throw new CodeRadePortletException("empty-file");
    }

    _log.debug("Uploading file: " + sourceFileName + " ...");

    File folder = new File(ROOT_FOLDER_NAME);

    // Check minimum storage space to save new files...
    if (folder.getUsableSpace() < UPLOAD_LIMIT) {
        throw new CodeRadePortletException("error-disk-space");
    } else if (sizeInBytes > UPLOAD_LIMIT) {
        throw new CodeRadePortletException("error-limit-exceeded");
    } else {

        // This is our final file path.
        File filePath = new File(folder.getAbsolutePath() + File.separator + username + "_" + modelName + "_"
                + timestamp + "." + extension);

        // Move the existing temporary file to new location.
        FileUtils.copyFile(uploadedFile, filePath);
        _log.debug("File created: " + filePath);
        createdFile = filePath.getAbsolutePath();

    }
    return createdFile;
}