本文整理汇总了Java中com.google.common.io.Files.getFileExtension方法的典型用法代码示例。如果您正苦于以下问题:Java Files.getFileExtension方法的具体用法?Java Files.getFileExtension怎么用?Java Files.getFileExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.io.Files
的用法示例。
在下文中一共展示了Files.getFileExtension方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createAndInitializeInfo
import com.google.common.io.Files; //导入方法依赖的package包/类
/**
* Initializes dictionary information for given application from application bundle file (or xml/sdef dictionary file)
* and saves generated dictionary file for later use by {@link ApplicationDictionary} PSI class
*
* @param applicationIoFile File of the application bundle or dictionary file (.app, .osax, .xml, .sdef extensions
* are supported)
* @param applicationName Name of the Mac OS X application
* @return {@link DictionaryInfo} of the generated, saved and initialized dictionary for the application
*/
@Nullable
public synchronized DictionaryInfo createAndInitializeInfo(@NotNull File applicationIoFile,
@NotNull String applicationName) {
// if (isNotScriptable(applicationName)) return null;
String appExtension = Files.getFileExtension(applicationIoFile.getPath());
if (!ApplicationDictionaryImpl.extensionSupported(appExtension)) return null;
if (!applicationIoFile.exists()) return null;
if (getDictionaryInfo(applicationName) != null) {
LOG.warn("Dictionary for application " + applicationName + " was already initialized. Generating new dictionary file any way.");
}
final DictionaryInfo createdDictionaryInfo = createDictionaryInfoForApplication(applicationName, applicationIoFile);
if (createdDictionaryInfo != null) {
if (initializeDictionaryFromInfo(createdDictionaryInfo))
return createdDictionaryInfo;
}
return null;
}
示例2: handleAndroidFile
import com.google.common.io.Files; //导入方法依赖的package包/类
private void handleAndroidFile(CredentialDetail detail, MultipartFile file) throws IOException {
if (!(detail instanceof AndroidCredentialDetail)) {
return;
}
if (file == null || file.isEmpty()) {
return;
}
AndroidCredentialDetail androidDetail = (AndroidCredentialDetail) detail;
String extension = Files.getFileExtension(file.getOriginalFilename());
if (!ANDROID_EXTENSIONS.contains(extension)) {
throw new IllegalParameterException("Illegal android cert file");
}
String destFileName = getFileName(file.getOriginalFilename());
Path destPath = credentailFilePath(destFileName);
file.transferTo(destPath.toFile());
androidDetail.setFile(new FileResource(file.getOriginalFilename(), destPath.toString()));
}
示例3: getUniqueContentName
import com.google.common.io.Files; //导入方法依赖的package包/类
/**
* Returns a unique name for a file with a given content hash.
*
* <p>Directory paths are removed. Example:
* <pre>
* dir="a/b/c/d", contentHash="f000" => d-f000.jar
* file="a/b/c/d.txt", contentHash="f000" => d-f000.txt
* file="a/b/c/d", contentHash="f000" => d-f000
* </pre>
*/
private static String getUniqueContentName(File classpathElement, String contentHash) {
String fileName = Files.getNameWithoutExtension(classpathElement.getAbsolutePath());
String fileExtension = Files.getFileExtension(classpathElement.getAbsolutePath());
if (classpathElement.isDirectory()) {
return fileName + "-" + contentHash + ".jar";
} else if (fileExtension.isEmpty()) {
return fileName + "-" + contentHash;
}
return fileName + "-" + contentHash + "." + fileExtension;
}
示例4: FileCollectionBackedArchiveTextResource
import com.google.common.io.Files; //导入方法依赖的package包/类
public FileCollectionBackedArchiveTextResource(final FileOperations fileOperations,
final TemporaryFileProvider tempFileProvider,
final FileCollection fileCollection,
final String path, Charset charset) {
super(tempFileProvider, new LazilyInitializedFileCollection() {
@Override
public String getDisplayName() {
return String.format("entry '%s' in archive %s", path, fileCollection);
}
@Override
public FileCollection createDelegate() {
File archiveFile = fileCollection.getSingleFile();
String fileExtension = Files.getFileExtension(archiveFile.getName());
FileTree archiveContents = fileExtension.equals("jar") || fileExtension.equals("zip")
? fileOperations.zipTree(archiveFile) : fileOperations.tarTree(archiveFile);
PatternSet patternSet = new PatternSet();
patternSet.include(path);
return archiveContents.matching(patternSet);
}
@Override
public void visitDependencies(TaskDependencyResolveContext context) {
context.add(fileCollection);
}
}, charset);
}
示例5: ResourcePackManager
import com.google.common.io.Files; //导入方法依赖的package包/类
public ResourcePackManager(File path) {
if (!path.exists()) {
path.mkdirs();
} else if (!path.isDirectory()) {
throw new IllegalArgumentException(Server.getInstance().getLanguage()
.translateString("nukkit.resources.invalid-path", path.getName()));
}
List<ResourcePack> loadedResourcePacks = new ArrayList<>();
for (File pack : path.listFiles()) {
try {
ResourcePack resourcePack = null;
if (!pack.isDirectory()) { //directory resource packs temporarily unsupported
switch (Files.getFileExtension(pack.getName())) {
case "zip":
case "mcpack":
resourcePack = new ZippedResourcePack(pack);
break;
default:
Server.getInstance().getLogger().warning(Server.getInstance().getLanguage()
.translateString("nukkit.resources.unknown-format", pack.getName()));
break;
}
}
if (resourcePack != null) {
loadedResourcePacks.add(resourcePack);
this.resourcePacksById.put(resourcePack.getPackId(), resourcePack);
}
} catch (IllegalArgumentException e) {
Server.getInstance().getLogger().warning(Server.getInstance().getLanguage()
.translateString("nukkit.resources.fail", pack.getName(), e.getMessage()));
}
}
this.resourcePacks = loadedResourcePacks.toArray(new ResourcePack[loadedResourcePacks.size()]);
Server.getInstance().getLogger().info(Server.getInstance().getLanguage()
.translateString("nukkit.resources.success", String.valueOf(this.resourcePacks.length)));
}
示例6: handle
import com.google.common.io.Files; //导入方法依赖的package包/类
public void handle(int level, String path, File file) {
String extension = Files.getFileExtension(file.getName());
if (extension.equals("java")){
handleJava(level, path, file);
}else if(extension.equals("xml") && isLayoutResourceDir(path)){
handleLayoutXML(level, path, file);
}
}
示例7: loadPortScannerResult
import com.google.common.io.Files; //导入方法依赖的package包/类
@Override
public PortScannerResult loadPortScannerResult(@NonNull final String _filename,
@NonNull final PortScannerResult _defaultPortScannerResult) {
final File file = new File(_filename);
try {
@Cleanup final FileInputStream fis = new FileInputStream(file);
log.info("Loading file: " + _filename);
final String extension = Files.getFileExtension(file.getPath());
final IoPlugin ioPluginForExtension = pluginConfiguration.getIoPluginByExtension(extension);
if (ioPluginForExtension != null) {
// extra mapping meta-data required by YAML plugin, ignored by JSON plugin
// (Jackson is much smarter with regard to inferring types it seems)
final MapProperty openHostsMapProperty = new MapProperty(NetworkResult.class, "openHosts", String.class, OpenHost.class);
final MapProperty openPortsMapProperty = new MapProperty(OpenHost.class, "openPorts", Integer.class, Port.class);
final PortScannerResult portScannerResult = ioPluginForExtension.load(fis, PortScannerResult.class, Collections.emptyList(), Arrays.asList(openHostsMapProperty, openPortsMapProperty));
if (portScannerResult != null) {
log.info("Port scan result loaded.");
return portScannerResult;
} else {
log.warn("Unable to deserialize scan result.");
}
} else {
log.warn("Unable to find registered I/O plugin for extension: " + extension);
}
} catch (IOException _e) {
log.warn("Failed to load port scan result", _e);
}
return _defaultPortScannerResult;
}
示例8: ResourcePackManager
import com.google.common.io.Files; //导入方法依赖的package包/类
public ResourcePackManager(File path) {
if (!path.exists()) {
path.mkdirs();
} else if (!path.isDirectory()) {
throw new IllegalArgumentException(Server.getInstance().getLanguage()
.translateString("nukkit.resources.invalid-path", path.getName()));
}
List<ResourcePack> loadedResourcePacks = new ArrayList<>();
for (File pack : path.listFiles()) {
try {
ResourcePack resourcePack = null;
if (!pack.isDirectory()) { //directory resource packs temporarily unsupported
switch (Files.getFileExtension(pack.getName())) {
case "zip":
resourcePack = new ZippedResourcePack(pack);
break;
default:
Server.getInstance().getLogger().warning(Server.getInstance().getLanguage()
.translateString("nukkit.resources.unknown-format", pack.getName()));
break;
}
}
if (resourcePack != null) {
loadedResourcePacks.add(resourcePack);
this.resourcePacksById.put(resourcePack.getPackId(), resourcePack);
}
} catch (IllegalArgumentException e) {
Server.getInstance().getLogger().warning(Server.getInstance().getLanguage()
.translateString("nukkit.resources.fail", pack.getName(), e.getMessage()));
}
}
this.resourcePacks = loadedResourcePacks.toArray(new ResourcePack[loadedResourcePacks.size()]);
Server.getInstance().getLogger().info(Server.getInstance().getLanguage()
.translateString("nukkit.resources.success", String.valueOf(this.resourcePacks.length)));
}
示例9: getFilter
import com.google.common.io.Files; //导入方法依赖的package包/类
private static FilenameFilter getFilter(final Set<String> fileExtensions) {
checkArgument(!fileExtensions.isEmpty(), "No file extension provided", fileExtensions);
return (dir, name) -> {
String ext = Files.getFileExtension(name);
return fileExtensions.contains(ext);
};
}
示例10: forFile
import com.google.common.io.Files; //导入方法依赖的package包/类
public static AttributeContainer forFile(File file) {
String extension = Files.getFileExtension(file.getName());
return createAttributes(extension, extension, "");
}
示例11: ResourcePackManager
import com.google.common.io.Files; //导入方法依赖的package包/类
public ResourcePackManager(File path) {
if (!path.exists()) {
path.mkdirs();
} else if (!path.isDirectory()) {
throw new IllegalArgumentException(Server.getInstance().getLanguage()
.translateString("nukkit.resources.invalid-path", path.getName()));
}
List<ResourcePack> loadedResourcePacks = new ArrayList<>();
for (File pack : path.listFiles()) {
try {
ResourcePack resourcePack = null;
if (!pack.isDirectory()) { //directory resource packs temporarily unsupported
switch (Files.getFileExtension(pack.getName())) {
case "zip":
case "mcpack":
resourcePack = new ZippedResourcePack(pack);
break;
default:
Server.getInstance().getLogger().warning(Server.getInstance().getLanguage()
.translateString("nukkit.resources.unknown-format", pack.getName()));
break;
}
}
if (resourcePack != null) {
loadedResourcePacks.add(resourcePack);
this.resourcePacksById.put(resourcePack.getPackId(), resourcePack);
}
} catch (IllegalArgumentException e) {
Server.getInstance().getLogger().warning(Server.getInstance().getLanguage()
.translateString("nukkit.resources.fail", pack.getName(), e.getMessage()));
e.printStackTrace();
}
}
this.resourcePacks = loadedResourcePacks.toArray(new ResourcePack[loadedResourcePacks.size()]);
Server.getInstance().getLogger().info(Server.getInstance().getLanguage()
.translateString("nukkit.resources.success", String.valueOf(this.resourcePacks.length)));
}
示例12: getFileExtension
import com.google.common.io.Files; //导入方法依赖的package包/类
/**
* 获取文件名的扩展名部分(不包含.)
*/
public static String getFileExtension(File file) {
return Files.getFileExtension(file.getName());
}
示例13: getFileExtension
import com.google.common.io.Files; //导入方法依赖的package包/类
/**
* Get the extension of the specified file.
*
* @param file The file
* @return The extension of the file
*/
public static String getFileExtension(String file) {
return Files.getFileExtension(file);
}