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:aurelienribon.gdxsetupui.Helper.java

public static boolean isFileRuntimeJar(String filename) {
    if (!filename.endsWith(".jar"))
        return false;
    String name = FilenameUtils.getBaseName(filename);
    if (endsWith(name, "-source", "-sources", "-src"))
        return false;
    return true;/*from  w  ww  .j av  a  2s .co  m*/
}

From source file:de.mpg.imeji.presentation.beans.PropertyBean.java

/**
  * Default constructor/* w w  w .  j  av a 2  s  .c om*/
  */
public PropertyBean() {
    try {
        this.digilibEnabled = Boolean.parseBoolean(PropertyReader.getProperty("imeji.digilib.enable"));
        this.internalStorageBase = FilenameUtils.getBaseName(
                FilenameUtils.normalizeNoEndSeparator(PropertyReader.getProperty("imeji.storage.path")));
        applicationURL = StringHelper.normalizeURI(PropertyReader.getProperty("imeji.instance.url"));
        css_default = PropertyReader.getProperty("imeji.layout.css_default");
        css_alternate = PropertyReader.getProperty("imeji.layout.css_alternate");
        readBaseUri();
        this.appName = PropertyReader.getProperty("imeji.instance.name");
    } catch (Exception e) {
        throw new RuntimeException("Error reading properties: ", e);
    }
}

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

@Test
public void test() throws IOException {
    ath.waitForObjectToBeInFinishState(ORIG_NAME);
    Object o = new Object();
    o.setOrig_name(ORIG_NAME);/*ww  w. ja va  2s . c  om*/
    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);
        }
    }

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

}

From source file:com.frostwire.search.bitsnoop.BitSnoopSearchResult.java

public BitSnoopSearchResult(String detailsUrl, SearchMatcher matcher) {
    this.detailsUrl = detailsUrl;
    this.infoHash = matcher.group(1);
    this.filename = parseFileName(matcher.group(2), FilenameUtils.getBaseName(detailsUrl));
    this.torrentUrl = matcher.group(3);
    this.size = parseSize(matcher.group(4));
    this.seeds = parseSeeds(matcher.group(5));
    this.creationTime = parseCreationTime(matcher.group(6));
    this.displayName = HtmlManipulator.replaceHtmlEntities(FilenameUtils.getBaseName(filename));
}

From source file:com.aliyun.odps.mapred.bridge.MetaExplorerImpl.java

/**
 * Upload a resource file and add it to resource list. The resource name is
 * <code>fileprefix+padding+extension</code>
 *
 * @param filePath/*  w w  w.j av a2  s.  com*/
 * @param type
 * @param padding
 * @param isTempResource
 * @return genuine resource name
 * @throws OdpsException
 */
@Override
public String addFileResourceWithRetry(String filePath, Resource.Type type, String padding,
        boolean isTempResource) throws OdpsException {

    String baseName = FilenameUtils.getBaseName(filePath);
    String extension = FilenameUtils.getExtension(filePath);
    String resourceName = baseName + padding;

    File file = new File(filePath);
    FileResource res = null;
    switch (type) {
    case FILE:
        res = new FileResource();
        break;
    case JAR:
        res = new JarResource();
        break;
    default:
        throw new OdpsException("Unsupported resource type:" + type);
    }

    FileInputStream in = null;
    int trial = 0;
    res.setIsTempResource(isTempResource);
    String rname = null;
    while (trial <= 3) {
        try {
            rname = resourceName + "_" + trial;
            if (extension != null && !extension.isEmpty()) {
                rname += "." + extension;
            }
            res.setName(rname);
            in = new FileInputStream(file);
            odps.resources().create(res, in);
            return rname;
        } catch (OdpsException e) {
            LOG.error("Upload resource " + rname + " failed:" + e.getMessage() + ", retry count=" + trial);
            try {
                Thread.sleep(60 * 1000);
            } catch (InterruptedException e1) {
                // Silently swallow it.
            }
        } catch (FileNotFoundException e) {
            throw new OdpsException("Resource file: " + filePath + " not found.", e);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    throw new OdpsException(e);
                }
            }
        }
        trial++;
    }
    throw new OdpsException("Upload resource failed.");

}

From source file:com.legstar.protobuf.cobol.ProtoCobolUtils.java

/**
 * The java class name derived from the proto file name.
 * /*w  w  w  .j ava 2 s.  c o  m*/
 * @param protoFile the proto file
 * @return the java class name
 */
public static String getDefaultJavaClassName(File protoFile) {
    return StringUtils.capitalize(FilenameUtils.getBaseName(protoFile.getName())) + ".java";
}

From source file:javacommon.excel.ExcelUtils.java

/**
 * ?/*w  ww  .jav a 2  s. c  om*/
 * @param file 
 * @param data ?
 */
public static <T> void write(File file, List<T[]> data) throws IOException {
    Writer w = new ExcelWriter(getWorkBook(file.getName()));
    String sheetName = FilenameUtils.getBaseName(file.getName());
    Sheet sheet = w.createSheet(sheetName);
    for (int i = 0; i < data.size(); i++) {
        w.writeRow(sheet, data.get(i), i);
    }
    OutputStream out = null;
    try {
        out = FileUtils.openOutputStream(file);
        w.flush(out);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:com.esri.geoevent.test.performance.report.AbstractFileRollOverReportWriter.java

protected void rollOver(String fileName) {
    File target;//from w  ww .  j a  v  a  2s  .  c om
    File file;
    boolean renameSucceeded = true;

    if (!new File(fileName).exists()) {
        return;
    }

    // If maxBackups <= 0, then there is no file renaming to be done.
    if (getMaxNumberOfReportFiles() > 0) {
        // Delete the oldest file, to keep Windows happy.
        String ext = FilenameUtils.getExtension(fileName);
        String baseFileName = FilenameUtils.getFullPath(fileName) + FilenameUtils.getBaseName(fileName);

        file = new File(baseFileName + getMaxNumberOfReportFiles() + '.' + ext);
        if (file.exists()) {
            renameSucceeded = file.delete();
        }

        // Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2}
        for (int i = getMaxNumberOfReportFiles() - 1; i >= 1 && renameSucceeded; i--) {
            file = new File(baseFileName + i + "." + ext);
            if (file.exists()) {
                target = new File(baseFileName + (i + 1) + '.' + ext);
                renameSucceeded = file.renameTo(target);
            }
        }

        if (renameSucceeded) {
            // Rename fileName to fileName.1
            target = new File(baseFileName + 1 + "." + ext);
            file = new File(fileName);
            renameSucceeded = file.renameTo(target);
        }
    }
}

From source file:dialog.DialogFunctionUser.java

private void actionAddUserNoController() {
    if (!isValidData()) {
        return;// www .  j a v  a2 s .  c o  m
    }
    if (isExistUsername(tfUsername.getText())) {
        JOptionPane.showMessageDialog(null, "Username  tn ti", "Error", JOptionPane.ERROR_MESSAGE);
        return;
    }
    String username = tfUsername.getText();
    String fullname = tfFullname.getText();
    String password = new String(tfPassword.getPassword());
    password = LibraryString.md5(password);
    int role = cbRole.getSelectedIndex();
    User objUser;
    if (mAvatar != null) {
        objUser = new User(UUID.randomUUID().toString(), username, password, fullname, role,
                new Date(System.currentTimeMillis()), mAvatar.getPath());
        String fileName = FilenameUtils.getBaseName(mAvatar.getName()) + "-" + System.nanoTime() + "."
                + FilenameUtils.getExtension(mAvatar.getName());
        Path source = Paths.get(mAvatar.toURI());
        Path destination = Paths.get("files/" + fileName);
        try {
            Files.copy(source, destination, StandardCopyOption.REPLACE_EXISTING);
        } catch (IOException ex) {
            Logger.getLogger(DialogFunctionRoom.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        objUser = new User(UUID.randomUUID().toString(), username, password, fullname, role,
                new Date(System.currentTimeMillis()), "");
    }
    if ((new ModelUser()).addItem(objUser)) {
        ImageIcon icon = new ImageIcon(getClass().getResource("/images/ic_success.png"));
        JOptionPane.showMessageDialog(this.getParent(), "Thm thnh cng", "Success",
                JOptionPane.INFORMATION_MESSAGE, icon);
    } else {
        JOptionPane.showMessageDialog(this.getParent(), "Thm tht bi", "Fail",
                JOptionPane.ERROR_MESSAGE);
    }
    this.dispose();
}

From source file:gui.menubar.SaveCommand.java

/**
 * Passes the file to the LevelSaver, first ensuring it has the correct
 * file type suffix./*from   w ww .j av  a 2 s  . com*/
 */
@Override
public void execute() {
    fileChooser.setCurrentDirectory(new File(SAVE_FILE_LOCATION));
    fileChooser.setFileFilter(new XmlFileFilter());
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    if (fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        if (selectedFile != null) {
            if (FilenameUtils.getExtension(selectedFile.getName()).equalsIgnoreCase("xml")) {
                levelSaver.save(level, selectedFile);
            } else {
                selectedFile = new File(selectedFile.getParentFile(),
                        FilenameUtils.getBaseName(selectedFile.getName()) + ".xml");
                levelSaver.save(level, selectedFile);
            }
        }
    }
}