Java Code Examples for org.apache.commons.io.FilenameUtils#indexOfExtension()

The following examples show how to use org.apache.commons.io.FilenameUtils#indexOfExtension() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConflictHandler.java    From PeerWasp with MIT License 6 votes vote down vote up
/**
 * Generate the conflict name of a file with help of the
 * current time and the conflict-suffix. Consider the example
 * hello_world.txt
 *
 * @param path to be renamed
 * @return The renamed version of the provided path. Example:
 *         hello_world_CONFLICT_2015-03-02_18-03-17.txt
 */
public static Path rename(Path path) {
	String pathString = path.toString();
	String renamedFileString = null;
	String conflictSuffix = "_CONFLICT_";

	// get index of extension (even works with files like "hello.world.txt")
	int indexOfExtension = FilenameUtils.indexOfExtension(pathString);

	String fileName = pathString.substring(0, indexOfExtension);
	String fileExtension = pathString.substring(indexOfExtension);

	renamedFileString = fileName + conflictSuffix + currentDate() + fileExtension;
	Path renamedFile = Paths.get(renamedFileString);

	return renamedFile;
}
 
Example 2
Source File: ResourceUtil.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
public static File save(File file, Object data, ResourceFileType type) throws IOException {
    boolean hasExtension = FilenameUtils.indexOfExtension(file.getAbsolutePath()) != -1;
    File output = hasExtension ? file : type.addExtensionIfMissing(file);
    ensureDir(file);
    getObjectMapper(type).writeValue(output, data);
    return output;
}
 
Example 3
Source File: MPQFileHandle.java    From riiablo with Apache License 2.0 5 votes vote down vote up
@Override
public String pathWithoutExtension() {
  int index = FilenameUtils.indexOfExtension(fileName);
  if (index == -1) {
    return fileName;
  }

  return fileName.substring(0, index);
}
 
Example 4
Source File: RansacFilterClient.java    From render with GNU General Public License v2.0 5 votes vote down vote up
private String[] splitFileName(final String fullPathName) {
    final int extensionIndex;
    String baseName = FilenameUtils.getBaseName(fullPathName);
    if (fullPathName.endsWith(".gz") || fullPathName.endsWith(".zip")) {
        extensionIndex = FilenameUtils.indexOfExtension(baseName);
        baseName = fullPathName.substring(0, extensionIndex);
    } else {
        extensionIndex = FilenameUtils.indexOfExtension(fullPathName);
    }
    return new String[] { baseName, fullPathName.substring(extensionIndex)};
}
 
Example 5
Source File: FileUtils.java    From developer-studio with Apache License 2.0 4 votes vote down vote up
public static File[] getAllExactMatchingFiles(String sourceDir, String fileNamePrefix, String extension, List fileList, List skipList) {
    
    File libDir = new File(sourceDir);
    String libDirPath = libDir.getAbsolutePath();
    File[] items = libDir.listFiles();
    if (items != null) {
        for (int i = 0; i < items.length; i++) {
        	if(items[i].isDirectory()){
        		if(!skipList.contains(items[i].getName())){
        			getAllExactMatchingFiles(items[i].getPath(), fileNamePrefix, extension, fileList,skipList);
        		}
        	}else{
             String item = items[i].getName();
             
             String fileName = null;
             String ext = "";
             
             if(FilenameUtils.indexOfExtension(item)==-1){
		fileName=item;
	}else{
		fileName = FilenameUtils.removeExtension(item);
		ext = FilenameUtils.getExtension(item); 
	}
             
             if (fileNamePrefix != null && extension != null) {
                 if (fileNamePrefix.equalsIgnoreCase(fileName) && extension.equalsIgnoreCase(ext)) {
                     fileList.add(new File(libDirPath + File.separator + item));
                 }
             } else if (fileNamePrefix == null && extension != null) {
                 if (extension.equalsIgnoreCase(ext)) {
                     fileList.add(new File(libDirPath + File.separator + item));
                 }
             } else if (fileNamePrefix != null && extension == null) {
                 if (fileNamePrefix.equalsIgnoreCase(fileName)) {
                     fileList.add(new File(libDirPath + File.separator + item));
                 }
             } else {
                 fileList.add(new File(libDirPath + File.separator + item));
             }
        	}
        }
        return (File[]) fileList.toArray(new File[fileList.size()]);
    }
    return new File[0];
}