Example usage for org.apache.commons.io FilenameUtils getBaseName

List of usage examples for org.apache.commons.io FilenameUtils getBaseName

Introduction

In this page you can find the example usage for org.apache.commons.io FilenameUtils getBaseName.

Prototype

public static String getBaseName(String filename) 

Source Link

Document

Gets the base name, minus the full path and extension, from a full filename.

Usage

From source file:com.taunova.app.libview.components.ImageHelpers.java

public static File addPrefixToFile(File file, String prefix) {
    String name = FilenameUtils.getBaseName(file.getName());
    String extension = FilenameUtils.getExtension(file.getName());

    StringBuilder builder = new StringBuilder(file.getParent());
    builder.append(File.separator);
    builder.append(name);/*  ww w.j a va2s  .  com*/
    builder.append(prefix);
    builder.append('.');
    builder.append(extension);
    return new File(builder.toString());
}

From source file:net.rpproject.dl.download.java

/**
* This method is for downloading a file from a URL. 
* @param fileurl The URL that the download needs to occur
* @throws IOException //from www .  j  a  v a  2 s  .  c o m
*/
private static void fileDownloader(String fileurl) throws IOException {
    URL url = null;
    OutputStream fos = null;
    InputStream fis = null;
    File file;
    ProgressMonitor monitor = new ProgressMonitor();

    try {
        if (!window.getModText().equals("")) {
            url = new URL(fileurl);

            String fileName = FilenameUtils.getBaseName(fileurl);
            fileName = java.net.URLDecoder.decode(fileName, "UTF-8");
            String extension = FilenameUtils.getExtension(fileurl);
            String check = fileName + "." + extension;

            if (!check.equals("mods.xml")) {
                file = new File(window.getModText());
                fos = new FileOutputStream(file + "\\" + fileName + "." + extension);
            } else {
                file = new File(launcher.dataFolder + "\\RPP\\");
                fos = new FileOutputStream(file + fileName + "." + extension);
            }
            fis = url.openStream();

            DownloadWatcher watcher = new DownloadWatcher(fos);
            watcher.setListener(monitor);

            filesize = Double.parseDouble(url.openConnection().getHeaderField("Content-Length"));
            filename = fileName;

            IOUtils.copy(fis, watcher);
        }
    } catch (IOException | NumberFormatException e) {
        String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
        Logger.getLogger("RPP").log(Level.INFO, "{0} Error Downloading file: {1}",
                new Object[] { timeStamp, fileurl });
        Logger.getLogger("RPP").log(Level.INFO, (Supplier<String>) e);
    } finally {
        if (fos != null) {
            fos.close();
        }
        if (fis != null) {
            fis.close();
        }
    }
}

From source file:com.bt.download.android.gui.adapters.menu.RenameFileMenuAction.java

@Override
protected void onClick(Context context) {
    String filePath = fd.filePath;

    String name = FilenameUtils.getBaseName(filePath);
    final String ext = FilenameUtils.getExtension(filePath);

    final EditText input = new EditText(context);
    input.setText(name);//from w w w .j a v a2 s .c  o m
    input.selectAll();

    UIUtils.showOkCancelDialog(context, input, R.string.rename, new OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            String newFileName = input.getText().toString() + "." + ext;
            if (isValidFileName(newFileName)) {
                renameFile(newFileName);
                adapter.notifyDataSetChanged();
            } else {
                // FIXME
            }
        }
    });
}

From source file:de.uzk.hki.da.at.ATUseCaseIngestMigrationAllowed.java

@Test
public void test() throws IOException {
    ath.retrievePackage(o, UNPACKED_DIP, "1");

    String brep = "";
    File[] fList = Path.makeFile(UNPACKED_DIP.toString(), "data").listFiles();
    for (File file : fList) {
        if (file.getAbsolutePath().endsWith("+b")) {
            brep = FilenameUtils.getBaseName(file.getAbsolutePath());
            System.out.println(":" + brep);
        }/*from  w  ww.  j  a v a 2s  . co m*/
    }

    assertTrue(Path.makeFile(UNPACKED_DIP.toString(), "data", brep, "image42.tif").exists());

}

From source file:hudson.plugins.simpleupdatesite.Plugin.java

private String getWiki(File hpiFile) {
    try {/*w w  w.  java 2 s  .c  om*/
        String baseName = FilenameUtils.getBaseName(hpiFile.getName());
        File exceptFile = new File(hpiFile.getParent(), baseName + ".wiki");
        if (exceptFile.exists()) {
            return FileUtils.readFileToString(exceptFile, "UTF-8");
        } else {
            return "";
        }
    } catch (Exception e) {
        return "";
    }
}

From source file:com.silverpeas.jobStartPagePeas.SpaceLookHelper.java

public void setFiles(List<File> files) {
    if (files != null) {
        for (File file : files) {
            SpaceLookItem item = new SpaceLookItem(file, spaceId);
            if (item != null) {
                items.put(FilenameUtils.getBaseName(item.getName()), item);
            }//from   w  ww .  ja va 2 s  .  c o m
        }
    }
}

From source file:memoryaid.GalleryController.java

@FXML
private void uploadImageAction(ActionEvent event) throws IOException {
    String imgPath = imagePathText.getText();
    String baseName = FilenameUtils.getBaseName(imgPath);

    String destinationPath = "/Users/madhaviunnam/NetBeansProjects/MemoryAid/src/GalleryImages";
    File destinationPathObject = new File(destinationPath + "/" + baseName + ".png");
    File sourceFilePathObject = new File(imgPath);
    FileUtils.copyFile(sourceFilePathObject, destinationPathObject);
    Parent Gallery = FXMLLoader.load(getClass().getResource("Gallery1.fxml"));
    Scene Gallery_scene = new Scene(Gallery);
    Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
    app_stage.hide();//from  w  w w  . ja  va2  s  . com
    app_stage.setScene(Gallery_scene);
    app_stage.show();
}

From source file:ijfx.core.batch.item.SaveToFileWrapper.java

public SaveToFileWrapper(Context context, BatchSingleInput input, File saveFile, String suffix) {

    this(context, input);
    String baseName;/*from w ww.j a v  a  2s.  com*/
    if (input.getDefaultSaveName() != null) {
        baseName = input.getDefaultSaveName();
    } else {
        baseName = FilenameUtils.getBaseName(saveFile.getName());
    }

    String ext = FilenameUtils.getExtension(saveFile.getName());

    String finalName;

    if (suffix != null) {
        finalName = new StringBuilder().append(baseName).append("_").append(suffix).append(".").append(ext)
                .toString();
    } else {
        finalName = new StringBuilder().append(baseName).append(".").append(ext).toString();
    }
    saveTo = new File(saveFile.getParentFile(), finalName);
}

From source file:au.org.ala.delta.dist.io.DistOutputFileManager.java

protected String getNamesFileName() {
    if (StringUtils.isEmpty(_namesFileName)) {
        String outputFile = outputFile(OutputFileType.OUTPUT_FILE).getFileName();
        _namesFileName = FilenameUtils.getBaseName(outputFile);
        _namesFileName = _namesFileName + DEFAULT_NAMES_FILE_EXTENSION;
    }// ww  w.ja  v  a  2s. c om
    return _namesFileName;
}

From source file:com.igormaznitsa.zxpspritecorrector.files.AbstractFilePlugin.java

protected static String addNumberToFileName(final String name, final int number) {
    String base = FilenameUtils.getBaseName(name);
    final String ext = FilenameUtils.getExtension(name);
    return base + Integer.toString(number) + '.' + ext;
}