本文整理了Java中org.apache.commons.io.FilenameUtils.getExtension()
方法的一些代码示例,展示了FilenameUtils.getExtension()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FilenameUtils.getExtension()
方法的具体详情如下:
包路径:org.apache.commons.io.FilenameUtils
类名称:FilenameUtils
方法名:getExtension
[英]Gets the extension of a filename.
This method returns the textual part of the filename after the last dot. There must be no directory separator after the dot.
foo.txt --> "txt"
a/b/c.jpg --> "jpg"
a/b.txt/c --> ""
a/b/c --> ""
The output will be the same irrespective of the machine that the code is running on.
[中]获取文件名的扩展名。
此方法返回文件名最后一个点后的文本部分。点后面不能有目录分隔符。
foo.txt --> "txt"
a/b/c.jpg --> "jpg"
a/b.txt/c --> ""
a/b/c --> ""
无论代码在哪台机器上运行,输出都是相同的。
代码示例来源:origin: gocd/gocd
public boolean namecheckForJar(String filename) {
return FilenameUtils.getExtension(filename).equals("jar");
}
}
代码示例来源:origin: commons-io/commons-io
/**
* Compare the extensions of two files the specified case sensitivity.
*
* @param file1 The first file to compare
* @param file2 The second file to compare
* @return a negative value if the first file's extension
* is less than the second, zero if the extensions are the
* same and a positive value if the first files extension
* is greater than the second file.
*
*/
@Override
public int compare(final File file1, final File file2) {
final String suffix1 = FilenameUtils.getExtension(file1.getName());
final String suffix2 = FilenameUtils.getExtension(file2.getName());
return caseSensitivity.checkCompareTo(suffix1, suffix2);
}
代码示例来源:origin: SonarSource/sonarqube
public static String getByFilename(String filename) {
String extension = FilenameUtils.getExtension(filename);
String mime = null;
if (!Strings.isNullOrEmpty(extension)) {
mime = MAP.get(extension.toLowerCase(Locale.ENGLISH));
}
return mime != null ? mime : DEFAULT;
}
}
代码示例来源:origin: jeremylong/DependencyCheck
/**
* Returns the (lowercase) file extension for a specified file.
*
* @param fileName the file name to retrieve the file extension from.
* @return the file extension.
*/
public static String getFileExtension(String fileName) {
final String fileExt = FilenameUtils.getExtension(fileName);
return null == fileExt || fileExt.isEmpty() ? null : fileExt.toLowerCase();
}
代码示例来源:origin: SonarSource/sonarqube
/**
* @see org.sonar.api.server.ws.WebService.NewAction#setResponseExample(java.net.URL)
*/
@CheckForNull
public String responseExampleFormat() {
if (responseExample != null) {
return StringUtils.lowerCase(FilenameUtils.getExtension(responseExample.getFile()));
}
return null;
}
代码示例来源:origin: Meituan-Dianping/walle
private void generateChannelApk(final File inputFile, final File outputDir, final String channel) {
final String name = FilenameUtils.getBaseName(inputFile.getName());
final String extension = FilenameUtils.getExtension(inputFile.getName());
final String newName = name + "_" + channel + "." + extension;
final File channelApk = new File(outputDir, newName);
try {
FileUtils.copyFile(inputFile, channelApk);
ChannelWriter.put(channelApk, channel, extraInfo);
} catch (IOException | SignatureNotFoundException e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: Meituan-Dianping/walle
private void generateChannelApk(final File inputFile, final File outputDir, final String channel, final String alias, final Map<String, String> extraInfo) {
final String channelName = alias == null ? channel : alias;
final String name = FilenameUtils.getBaseName(inputFile.getName());
final String extension = FilenameUtils.getExtension(inputFile.getName());
final String newName = name + "_" + channelName + "." + extension;
final File channelApk = new File(outputDir, newName);
try {
FileUtils.copyFile(inputFile, channelApk);
ChannelWriter.put(channelApk, channel, extraInfo);
} catch (IOException | SignatureNotFoundException e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: knightliao/disconf
/**
* 根据文件名返回其文件后缀ENUM
*/
public static SupportFileTypeEnum getByFileName(String fileName) {
String extension = FilenameUtils.getExtension(fileName);
if (StringUtils.isEmpty(extension)) {
return SupportFileTypeEnum.ANY;
}
for (SupportFileTypeEnum supportFileTypeEnum : SupportFileTypeEnum.values()) {
if (extension.equals(supportFileTypeEnum.modelName)) {
return supportFileTypeEnum;
}
}
return SupportFileTypeEnum.ANY;
}
代码示例来源:origin: pmd/pmd
@Override
public FileVisitResult visitFile(final Path file,
final BasicFileAttributes attrs) throws IOException {
String extension = FilenameUtils.getExtension(file.toString());
if ("jar".equalsIgnoreCase(extension)) {
fileVisitor.visitFile(file, attrs);
}
return FileVisitResult.CONTINUE;
}
};
代码示例来源:origin: ata4/disunity
public static boolean isResource(BundleEntry entry) {
String ext = FilenameUtils.getExtension(entry.name());
return ext.equals("resource");
}
代码示例来源:origin: ata4/disunity
public static boolean isLibrary(BundleEntry entry) {
String ext = FilenameUtils.getExtension(entry.name());
return ext.equals("dll") || ext.equals("mdb");
}
代码示例来源:origin: pentaho/pentaho-kettle
@Override public String getMimeType( String name ) {
String extension = FilenameUtils.getExtension( name );
return getMimeTypes().get( extension );
}
代码示例来源:origin: commons-io/commons-io
/**
* Checks whether the extension of the filename is that specified.
* <p>
* This method obtains the extension as the textual part of the filename
* after the last dot. There must be no directory separator after the dot.
* The extension check is case-sensitive on all platforms.
*
* @param filename the filename to query, null returns false
* @param extension the extension to check for, null or empty checks for no extension
* @return true if the filename has the specified extension
* @throws java.lang.IllegalArgumentException if the supplied filename contains null bytes
*/
public static boolean isExtension(final String filename, final String extension) {
if (filename == null) {
return false;
}
failIfNullBytePresent(filename);
if (extension == null || extension.isEmpty()) {
return indexOfExtension(filename) == NOT_FOUND;
}
final String fileExt = getExtension(filename);
return fileExt.equals(extension);
}
代码示例来源:origin: commons-io/commons-io
/**
* Checks whether the extension of the filename is one of those specified.
* <p>
* This method obtains the extension as the textual part of the filename
* after the last dot. There must be no directory separator after the dot.
* The extension check is case-sensitive on all platforms.
*
* @param filename the filename to query, null returns false
* @param extensions the extensions to check for, null checks for no extension
* @return true if the filename is one of the extensions
* @throws java.lang.IllegalArgumentException if the supplied filename contains null bytes
*/
public static boolean isExtension(final String filename, final Collection<String> extensions) {
if (filename == null) {
return false;
}
failIfNullBytePresent(filename);
if (extensions == null || extensions.isEmpty()) {
return indexOfExtension(filename) == NOT_FOUND;
}
final String fileExt = getExtension(filename);
for (final String extension : extensions) {
if (fileExt.equals(extension)) {
return true;
}
}
return false;
}
代码示例来源:origin: commons-io/commons-io
/**
* Checks whether the extension of the filename is one of those specified.
* <p>
* This method obtains the extension as the textual part of the filename
* after the last dot. There must be no directory separator after the dot.
* The extension check is case-sensitive on all platforms.
*
* @param filename the filename to query, null returns false
* @param extensions the extensions to check for, null checks for no extension
* @return true if the filename is one of the extensions
* @throws java.lang.IllegalArgumentException if the supplied filename contains null bytes
*/
public static boolean isExtension(final String filename, final String[] extensions) {
if (filename == null) {
return false;
}
failIfNullBytePresent(filename);
if (extensions == null || extensions.length == 0) {
return indexOfExtension(filename) == NOT_FOUND;
}
final String fileExt = getExtension(filename);
for (final String extension : extensions) {
if (fileExt.equals(extension)) {
return true;
}
}
return false;
}
代码示例来源:origin: pentaho/pentaho-kettle
protected static String getFileType( final String fineName ) {
final String fileExt = fineName == null ? null : FilenameUtils.getExtension( fineName );
String fileType = BaseMessages.getString( PKG, "System.FileType.File" );
if ( "ktr".equals( fileExt ) ) {
fileType = BaseMessages.getString( PKG, "System.FileType.Transformation" );
} else if ( "kjb".equals( fileExt ) ) {
fileType = BaseMessages.getString( PKG, "System.FileType.Job" );
}
return fileType;
}
代码示例来源:origin: SonarSource/sonarqube
@Override
public boolean match(Path absolutePath, Path relativePath, boolean caseSensitiveFileExtension) {
String path = PathUtils.sanitize(absolutePath.toString());
if (!caseSensitiveFileExtension) {
String extension = sanitizeExtension(FilenameUtils.getExtension(path));
if (StringUtils.isNotBlank(extension)) {
path = StringUtils.removeEndIgnoreCase(path, extension);
path = path + extension;
}
}
return pattern.match(path);
}
代码示例来源:origin: SonarSource/sonarqube
@Override
public boolean match(Path absolutePath, Path relativePath, boolean caseSensitiveFileExtension) {
String path = PathUtils.sanitize(relativePath.toString());
if (!caseSensitiveFileExtension) {
String extension = sanitizeExtension(FilenameUtils.getExtension(path));
if (StringUtils.isNotBlank(extension)) {
path = StringUtils.removeEndIgnoreCase(path, extension);
path = path + extension;
}
}
return path != null && pattern.match(path);
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testGetExtension() {
assertEquals(null, FilenameUtils.getExtension(null));
assertEquals("ext", FilenameUtils.getExtension("file.ext"));
assertEquals("", FilenameUtils.getExtension("README"));
assertEquals("com", FilenameUtils.getExtension("domain.dot.com"));
assertEquals("jpeg", FilenameUtils.getExtension("image.jpeg"));
assertEquals("", FilenameUtils.getExtension("a.b/c"));
assertEquals("txt", FilenameUtils.getExtension("a.b/c.txt"));
assertEquals("", FilenameUtils.getExtension("a/b/c"));
assertEquals("", FilenameUtils.getExtension("a.b\\c"));
assertEquals("txt", FilenameUtils.getExtension("a.b\\c.txt"));
assertEquals("", FilenameUtils.getExtension("a\\b\\c"));
assertEquals("", FilenameUtils.getExtension("C:\\temp\\foo.bar\\README"));
assertEquals("ext", FilenameUtils.getExtension("../filename.ext"));
}
代码示例来源:origin: pentaho/pentaho-kettle
private NamedParams getMeta( RepositoryFile file ) throws KettleException {
NamedParams meta = null;
if ( file != null ) {
String extension = FilenameUtils.getExtension( file.getName() );
Repository repo = PDIImportUtil.connectToRepository( null );
if ( "ktr".equalsIgnoreCase( extension ) ) {
meta = new TransMeta( convertTransformation( file.getId() ), repo, true, null, null );
} else if ( "kjb".equalsIgnoreCase( extension ) ) {
meta = new JobMeta( convertJob( file.getId() ), repo, null );
}
}
return meta;
}
内容来源于网络,如有侵权,请联系作者删除!