本文整理了Java中org.apache.commons.io.FilenameUtils.isExtension()
方法的一些代码示例,展示了FilenameUtils.isExtension()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FilenameUtils.isExtension()
方法的具体详情如下:
包路径:org.apache.commons.io.FilenameUtils
类名称:FilenameUtils
方法名:isExtension
[英]Checks whether the extension of the filename is that specified.
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.
[中]
代码示例来源:origin: apache/incubator-gobblin
@Override
public boolean accept(Path path) {
return FilenameUtils.isExtension(path.getName(), "avro");
}
})) {
代码示例来源:origin: uber/okbuck
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public static boolean isConsumable(File file) {
// Skip artifact files which are coming from the transformed folder.
// transforms-1 contains the contents of the resolved aar/jar and
// hence should not be consumed.
if (file.getAbsolutePath().contains("transforms-1/files-1")) {
return false;
}
return FilenameUtils.isExtension(file.getName(), ALLOWED_EXTENSIONS);
}
代码示例来源:origin: apache/incubator-gobblin
public static Schema getNewestSchemaFromSource(Path sourceDir, FileSystem fs) throws IOException {
FileStatus[] files = fs.listStatus(sourceDir);
Arrays.sort(files, new LastModifiedDescComparator());
for (FileStatus status : files) {
if (status.isDirectory()) {
Schema schema = getNewestSchemaFromSource(status.getPath(), fs);
if (schema != null)
return schema;
} else if (FilenameUtils.isExtension(status.getPath().getName(), AVRO)) {
return AvroUtils.getSchemaFromDataFile(status.getPath(), fs);
}
}
return null;
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testIsExtension() {
assertFalse(FilenameUtils.isExtension(null, (String) null));
assertFalse(FilenameUtils.isExtension("file.txt", (String) null));
assertTrue(FilenameUtils.isExtension("file", (String) null));
assertFalse(FilenameUtils.isExtension("file.txt", ""));
assertTrue(FilenameUtils.isExtension("file", ""));
assertTrue(FilenameUtils.isExtension("file.txt", "txt"));
assertFalse(FilenameUtils.isExtension("file.txt", "rtf"));
assertFalse(FilenameUtils.isExtension("a/b/file.txt", (String) null));
assertFalse(FilenameUtils.isExtension("a/b/file.txt", ""));
assertTrue(FilenameUtils.isExtension("a/b/file.txt", "txt"));
assertFalse(FilenameUtils.isExtension("a/b/file.txt", "rtf"));
assertFalse(FilenameUtils.isExtension("a.b/file.txt", (String) null));
assertFalse(FilenameUtils.isExtension("a.b/file.txt", ""));
assertTrue(FilenameUtils.isExtension("a.b/file.txt", "txt"));
assertFalse(FilenameUtils.isExtension("a.b/file.txt", "rtf"));
assertFalse(FilenameUtils.isExtension("a\\b\\file.txt", (String) null));
assertFalse(FilenameUtils.isExtension("a\\b\\file.txt", ""));
assertTrue(FilenameUtils.isExtension("a\\b\\file.txt", "txt"));
assertFalse(FilenameUtils.isExtension("a\\b\\file.txt", "rtf"));
assertFalse(FilenameUtils.isExtension("a.b\\file.txt", (String) null));
assertFalse(FilenameUtils.isExtension("a.b\\file.txt", ""));
assertTrue(FilenameUtils.isExtension("a.b\\file.txt", "txt"));
assertFalse(FilenameUtils.isExtension("a.b\\file.txt", "rtf"));
assertFalse(FilenameUtils.isExtension("a.b\\file.txt", "TXT"));
}
代码示例来源:origin: neo4j/neo4j
private void checkArchiveName( long highestLogVersion, long byteOffset, File corruptedLogsArchive )
{
String name = corruptedLogsArchive.getName();
assertTrue( name.startsWith( "corrupted-neostore.transaction.db-" + highestLogVersion + "-" + byteOffset ) );
assertTrue( FilenameUtils.isExtension( name, "zip" ) );
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testIsExtensionArray() {
assertFalse(FilenameUtils.isExtension(null, (String[]) null));
assertFalse(FilenameUtils.isExtension("file.txt", (String[]) null));
assertTrue(FilenameUtils.isExtension("file", (String[]) null));
assertFalse(FilenameUtils.isExtension("file.txt", new String[0]));
assertTrue(FilenameUtils.isExtension("file.txt", new String[]{"txt"}));
assertFalse(FilenameUtils.isExtension("file.txt", new String[]{"rtf"}));
assertTrue(FilenameUtils.isExtension("file", new String[]{"rtf", ""}));
assertTrue(FilenameUtils.isExtension("file.txt", new String[]{"rtf", "txt"}));
assertFalse(FilenameUtils.isExtension("a/b/file.txt", (String[]) null));
assertFalse(FilenameUtils.isExtension("a/b/file.txt", new String[0]));
assertTrue(FilenameUtils.isExtension("a/b/file.txt", new String[]{"txt"}));
assertFalse(FilenameUtils.isExtension("a/b/file.txt", new String[]{"rtf"}));
assertTrue(FilenameUtils.isExtension("a/b/file.txt", new String[]{"rtf", "txt"}));
assertFalse(FilenameUtils.isExtension("a.b/file.txt", (String[]) null));
assertFalse(FilenameUtils.isExtension("a.b/file.txt", new String[0]));
assertTrue(FilenameUtils.isExtension("a.b/file.txt", new String[]{"txt"}));
assertFalse(FilenameUtils.isExtension("a.b/file.txt", new String[]{"rtf"}));
assertTrue(FilenameUtils.isExtension("a.b/file.txt", new String[]{"rtf", "txt"}));
assertFalse(FilenameUtils.isExtension("a\\b\\file.txt", (String[]) null));
assertFalse(FilenameUtils.isExtension("a\\b\\file.txt", new String[0]));
assertTrue(FilenameUtils.isExtension("a\\b\\file.txt", new String[]{"txt"}));
assertFalse(FilenameUtils.isExtension("a\\b\\file.txt", new String[]{"rtf"}));
assertTrue(FilenameUtils.isExtension("a\\b\\file.txt", new String[]{"rtf", "txt"}));
assertFalse(FilenameUtils.isExtension("a.b\\file.txt", (String[]) null));
代码示例来源:origin: commons-io/commons-io
@Test
public void testIsExtensionCollection() {
assertFalse(FilenameUtils.isExtension(null, (Collection<String>) null));
assertFalse(FilenameUtils.isExtension("file.txt", (Collection<String>) null));
assertTrue(FilenameUtils.isExtension("file", (Collection<String>) null));
assertFalse(FilenameUtils.isExtension("file.txt", new ArrayList<String>()));
assertTrue(FilenameUtils.isExtension("file.txt", new ArrayList<>(Arrays.asList(new String[]{"txt"}))));
assertFalse(FilenameUtils.isExtension("file.txt", new ArrayList<>(Arrays.asList(new String[]{"rtf"}))));
assertTrue(FilenameUtils.isExtension("file", new ArrayList<>(Arrays.asList(new String[]{"rtf", ""}))));
assertTrue(FilenameUtils.isExtension("file.txt", new ArrayList<>(Arrays.asList(new String[]{"rtf", "txt"}))));
assertFalse(FilenameUtils.isExtension("a/b/file.txt", (Collection<String>) null));
assertFalse(FilenameUtils.isExtension("a/b/file.txt", new ArrayList<String>()));
assertTrue(FilenameUtils.isExtension("a/b/file.txt", new ArrayList<>(Arrays.asList(new String[]{"txt"}))));
assertFalse(FilenameUtils.isExtension("a/b/file.txt", new ArrayList<>(Arrays.asList(new String[]{"rtf"}))));
assertTrue(FilenameUtils.isExtension("a/b/file.txt", new ArrayList<>(Arrays.asList(new String[]{"rtf", "txt"}))));
assertFalse(FilenameUtils.isExtension("a.b/file.txt", (Collection<String>) null));
assertFalse(FilenameUtils.isExtension("a.b/file.txt", new ArrayList<String>()));
assertTrue(FilenameUtils.isExtension("a.b/file.txt", new ArrayList<>(Arrays.asList(new String[]{"txt"}))));
assertFalse(FilenameUtils.isExtension("a.b/file.txt", new ArrayList<>(Arrays.asList(new String[]{"rtf"}))));
assertTrue(FilenameUtils.isExtension("a.b/file.txt", new ArrayList<>(Arrays.asList(new String[]{"rtf", "txt"}))));
assertFalse(FilenameUtils.isExtension("a\\b\\file.txt", (Collection<String>) null));
assertFalse(FilenameUtils.isExtension("a\\b\\file.txt", new ArrayList<String>()));
assertTrue(FilenameUtils.isExtension("a\\b\\file.txt", new ArrayList<>(Arrays.asList(new String[]{"txt"}))));
assertFalse(FilenameUtils.isExtension("a\\b\\file.txt", new ArrayList<>(Arrays.asList(new String[]{"rtf"}))));
assertTrue(FilenameUtils.isExtension("a\\b\\file.txt", new ArrayList<>(Arrays.asList(new String[]{"rtf", "txt"}))));
assertFalse(FilenameUtils.isExtension("a.b\\file.txt", (Collection<String>) null));
代码示例来源:origin: commons-io/commons-io
@Test
public void testIsExtension_injection() {
try {
FilenameUtils.isExtension("a.b\\fi\u0000le.txt", "TXT");
fail("Should throw IAE");
} catch (final IllegalArgumentException ignore) {
}
}
代码示例来源:origin: apache/incubator-gobblin
for (String filePathString : this.dataset.jobProps()
.getPropAsList(MRCompactor.COMPACTION_JOB_LATE_DATA_FILES)) {
if (FilenameUtils.isExtension(filePathString, getApplicableFileExtensions())) {
newLateFilePaths.add(new Path(filePathString));
代码示例来源:origin: zalando/intellij-swagger
public boolean isSwaggerContentCompatible(VirtualFile file) {
return FilenameUtils.isExtension(
file.getName(),
new String[] {
FileConstants.JSON_FILE_EXTENSION,
FileConstants.YAML_FILE_EXTENSION,
FileConstants.YML_FILE_EXTENSION
});
}
}
代码示例来源:origin: naver/ngrinder
void decompressDownloadPackage() {
File interDir = new File(agentConfig.getHome().getTempDirectory(), "update_package_unpacked");
File toDir = new File(agentConfig.getCurrentDirectory(), "update_package");
interDir.mkdirs();
toDir.mkdirs();
if (FilenameUtils.isExtension(download.getName(), "tar")) {
File outFile = new File(toDir, "ngrinder-agent.tar");
CompressionUtils.untar(download, interDir);
FileUtils.deleteQuietly(outFile);
} else {
LOGGER.error("{} is not allowed to be unpacked.", download.getName());
}
try {
FileUtils.deleteQuietly(toDir);
FileUtils.moveDirectory(new File(interDir, "ngrinder-agent"), toDir);
} catch (IOException e) {
LOGGER.error("Error while moving a file ", e);
}
FileUtils.deleteQuietly(download);
FileUtils.deleteQuietly(interDir);
}
}
代码示例来源:origin: naver/ngrinder
if (FilenameUtils.isExtension(outputFile.getName(), EXECUTABLE_EXTENSION)) {
outputFile.setExecutable(true, true);
代码示例来源:origin: zhoulychn/mybatis-generator
/**
* 判断文件是否有某扩展名
*
* @param filename
* 文件完整路径
* @param extension
* 扩展名名称
* @return 若是,返回true,否则返回false
*/
public static boolean isExtension(String filename, String extension) {
return FilenameUtils.isExtension(filename, extension);
}
代码示例来源:origin: zhoulychn/mybatis-generator
/**
* 判断文件的扩展名是否是扩展名数组中的一个
*
* @param filename
* 文件完整路径
* @param extensions
* 扩展名名称
* @return 若是,返回true,否则返回false
*/
public static boolean isExtension(String filename, String[] extensions) {
return FilenameUtils.isExtension(filename, extensions);
}
代码示例来源:origin: org.apache.jena/jena-base
/** The filename without any compression extension, or the original filename.
* It tests for compression types handled by {@link #openFileEx}.
*/
static public String filenameNoCompression(String filename) {
if ( FilenameUtils.isExtension(filename, extensions) ) {
return FilenameUtils.removeExtension(filename);
}
return filename;
}
代码示例来源:origin: apache/jena
/** The filename without any compression extension, or the original filename.
* It tests for compression types handled by {@link #openFileEx}.
*/
static public String filenameNoCompression(String filename) {
if ( FilenameUtils.isExtension(filename, extensions) ) {
return FilenameUtils.removeExtension(filename);
}
return filename;
}
代码示例来源:origin: uk.gov.nationalarchives/droid-report
@Override
public boolean accept(File f) {
return FilenameUtils.isExtension(f.getName(), "xml");
}
};
代码示例来源:origin: org.apache.gobblin/gobblin-compaction
@Override
public boolean accept(Path path) {
return FilenameUtils.isExtension(path.getName(), "avro");
}
})) {
代码示例来源:origin: uk.gov.nationalarchives/droid-core-interfaces
@Override
public boolean accept(File f) {
return f.isFile() && FilenameUtils.isExtension(f.getName(), "tmp");
}
};
代码示例来源:origin: com.jaxio.celerio/celerio-engine
public static CommentStyle fromFilename(String filename) {
for (CommentStyle style : values()) {
if (FilenameUtils.isExtension(filename, style.getExtensions())) {
return style;
}
}
return null;
}
}
内容来源于网络,如有侵权,请联系作者删除!