本文整理汇总了Java中java.nio.file.spi.FileTypeDetector类的典型用法代码示例。如果您正苦于以下问题:Java FileTypeDetector类的具体用法?Java FileTypeDetector怎么用?Java FileTypeDetector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileTypeDetector类属于java.nio.file.spi包,在下文中一共展示了FileTypeDetector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFileExtension
import java.nio.file.spi.FileTypeDetector; //导入依赖的package包/类
public void testFileExtension() throws IOException{
new FileTypeDetector() {
@Override
public String probeContentType(Path file) throws IOException {
String type;
// Basic check on the type using the filename
if (file.toString().lastIndexOf('.') != -1) {
type = file.toString().substring( file.toString().lastIndexOf('.') );
} else {
type = null;
}
return type;
}
};
}
示例2: createDefaultFileTypeDetector
import java.nio.file.spi.FileTypeDetector; //导入依赖的package包/类
private static FileTypeDetector createDefaultFileTypeDetector() {
return AccessController
.doPrivileged(new PrivilegedAction<FileTypeDetector>() {
@Override public FileTypeDetector run() {
return sun.nio.fs.DefaultFileTypeDetector.create();
}});
}
示例3: loadInstalledDetectors
import java.nio.file.spi.FileTypeDetector; //导入依赖的package包/类
private static List<FileTypeDetector> loadInstalledDetectors() {
return AccessController
.doPrivileged(new PrivilegedAction<List<FileTypeDetector>>() {
@Override public List<FileTypeDetector> run() {
List<FileTypeDetector> list = new ArrayList<>();
ServiceLoader<FileTypeDetector> loader = ServiceLoader
.load(FileTypeDetector.class, ClassLoader.getSystemClassLoader());
for (FileTypeDetector detector: loader) {
list.add(detector);
}
return list;
}});
}
示例4: getFileTypeDetector
import java.nio.file.spi.FileTypeDetector; //导入依赖的package包/类
/**
* Returns a {@code FileTypeDetector} for this platform.
*/
FileTypeDetector getFileTypeDetector() {
return new AbstractFileTypeDetector() {
@Override
public String implProbeContentType(Path file) {
return null;
}
};
}
示例5: chain
import java.nio.file.spi.FileTypeDetector; //导入依赖的package包/类
/**
* Returns a {@code FileTypeDetector} that chains the given array of file
* type detectors. When the {@code implProbeContentType} method is invoked
* then each of the detectors is invoked in turn, the result from the
* first to detect the file type is returned.
*/
final FileTypeDetector chain(final AbstractFileTypeDetector... detectors) {
return new AbstractFileTypeDetector() {
@Override
protected String implProbeContentType(Path file) throws IOException {
for (AbstractFileTypeDetector detector : detectors) {
String result = detector.implProbeContentType(file);
if (result != null && !result.isEmpty()) {
return result;
}
}
return null;
}
};
}
示例6: getFileTypeDetector
import java.nio.file.spi.FileTypeDetector; //导入依赖的package包/类
@Override
FileTypeDetector getFileTypeDetector() {
Path userMimeTypes = Paths.get(AccessController.doPrivileged(
new GetPropertyAction("user.home")), ".mime.types");
Path etcMimeTypes = Paths.get("/etc/mime.types");
return chain(new GnomeFileTypeDetector(),
new MimeTypesFileTypeDetector(userMimeTypes),
new MimeTypesFileTypeDetector(etcMimeTypes),
new MagicFileTypeDetector());
}
示例7: getFileTypeDetector
import java.nio.file.spi.FileTypeDetector; //导入依赖的package包/类
@Override
FileTypeDetector getFileTypeDetector() {
Path userMimeTypes = Paths.get(AccessController.doPrivileged(
new GetPropertyAction("user.home")), ".mime.types");
Path etcMimeTypes = Paths.get("/etc/mime.types");
return chain(new GnomeFileTypeDetector(),
new MimeTypesFileTypeDetector(userMimeTypes),
new MimeTypesFileTypeDetector(etcMimeTypes));
}
示例8: create
import java.nio.file.spi.FileTypeDetector; //导入依赖的package包/类
public static FileTypeDetector create()
{
return new AbstractFileTypeDetector() {
public String implProbeContentType(Path obj) throws IOException {
return null;
}
};
}
示例9: createDefaultFileTypeDetector
import java.nio.file.spi.FileTypeDetector; //导入依赖的package包/类
private static FileTypeDetector createDefaultFileTypeDetector() {
return AccessController
.doPrivileged(new PrivilegedAction<>() {
@Override public FileTypeDetector run() {
return sun.nio.fs.DefaultFileTypeDetector.create();
}});
}
示例10: loadInstalledDetectors
import java.nio.file.spi.FileTypeDetector; //导入依赖的package包/类
private static List<FileTypeDetector> loadInstalledDetectors() {
return AccessController
.doPrivileged(new PrivilegedAction<>() {
@Override public List<FileTypeDetector> run() {
List<FileTypeDetector> list = new ArrayList<>();
ServiceLoader<FileTypeDetector> loader = ServiceLoader
.load(FileTypeDetector.class, ClassLoader.getSystemClassLoader());
for (FileTypeDetector detector: loader) {
list.add(detector);
}
return list;
}});
}
示例11: getFileTypeDetector
import java.nio.file.spi.FileTypeDetector; //导入依赖的package包/类
@Override
FileTypeDetector getFileTypeDetector() {
String userHome = GetPropertyAction.privilegedGetProperty("user.home");
Path userMimeTypes = Paths.get(userHome, ".mime.types");
Path etcMimeTypes = Paths.get("/etc/mime.types");
return chain(new MimeTypesFileTypeDetector(userMimeTypes),
new MimeTypesFileTypeDetector(etcMimeTypes));
}
示例12: getFileTypeDetector
import java.nio.file.spi.FileTypeDetector; //导入依赖的package包/类
@Override
FileTypeDetector getFileTypeDetector() {
Path userMimeTypes = Paths.get(GetPropertyAction
.privilegedGetProperty("user.home"), ".mime.types");
return chain(new MimeTypesFileTypeDetector(userMimeTypes),
new UTIFileTypeDetector());
}
示例13: getFileTypeDetector
import java.nio.file.spi.FileTypeDetector; //导入依赖的package包/类
@Override
FileTypeDetector getFileTypeDetector() {
Path userMimeTypes = Paths.get(
GetPropertyAction.privilegedGetProperty("user.home"), ".mime.types");
Path etcMimeTypes = Paths.get("/etc/mime.types");
return chain(new MimeTypesFileTypeDetector(userMimeTypes),
new MimeTypesFileTypeDetector(etcMimeTypes));
}
示例14: getFileTypeDetector
import java.nio.file.spi.FileTypeDetector; //导入依赖的package包/类
@Override
FileTypeDetector getFileTypeDetector() {
String userHome = GetPropertyAction.privilegedGetProperty("user.home");
Path userMimeTypes = Paths.get(userHome, ".mime.types");
Path etcMimeTypes = Paths.get("/etc/mime.types");
return chain(new GioFileTypeDetector(),
new MimeTypesFileTypeDetector(userMimeTypes),
new MimeTypesFileTypeDetector(etcMimeTypes),
new MagicFileTypeDetector());
}
示例15: getFileTypeDetector
import java.nio.file.spi.FileTypeDetector; //导入依赖的package包/类
@Override
FileTypeDetector getFileTypeDetector() {
Path userMimeTypes = Paths.get(
GetPropertyAction.privilegedGetProperty("user.home"), ".mime.types");
Path etcMimeTypes = Paths.get("/etc/mime.types");
return chain(new GioFileTypeDetector(),
new MimeTypesFileTypeDetector(userMimeTypes),
new MimeTypesFileTypeDetector(etcMimeTypes));
}