本文整理汇总了Java中java.nio.file.spi.FileTypeDetector.probeContentType方法的典型用法代码示例。如果您正苦于以下问题:Java FileTypeDetector.probeContentType方法的具体用法?Java FileTypeDetector.probeContentType怎么用?Java FileTypeDetector.probeContentType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.spi.FileTypeDetector
的用法示例。
在下文中一共展示了FileTypeDetector.probeContentType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: probeContentType
import java.nio.file.spi.FileTypeDetector; //导入方法依赖的package包/类
/**
* Probes the content type of a file.
*
* Same as {@link Files#probeContentType(Path)} but uses context class loader.
* @param path
* the path to the file to probe
* @return The content type of the file, or null if the content type cannot be determined
* @throws IOException if an I/O error occurs
*/
public static String probeContentType(Path path) throws IOException {
LOGGER.debug("Probing content type: {}", path);
for (FileTypeDetector fileTypeDetector : fileTypeDetectors) {
LOGGER.debug("Using type detector: {}", fileTypeDetector.getClass());
String contentType = fileTypeDetector.probeContentType(path);
if (contentType != null) {
LOGGER.debug("Content type: {}", contentType);
return contentType;
}
}
return Files.probeContentType(path);
}
示例2: probeContentType
import java.nio.file.spi.FileTypeDetector; //导入方法依赖的package包/类
/**
* Probes the content type of a file.
*
* <p> This method uses the installed {@link FileTypeDetector} implementations
* to probe the given file to determine its content type. Each file type
* detector's {@link FileTypeDetector#probeContentType probeContentType} is
* invoked, in turn, to probe the file type. If the file is recognized then
* the content type is returned. If the file is not recognized by any of the
* installed file type detectors then a system-default file type detector is
* invoked to guess the content type.
*
* <p> A given invocation of the Java virtual machine maintains a system-wide
* list of file type detectors. Installed file type detectors are loaded
* using the service-provider loading facility defined by the {@link ServiceLoader}
* class. Installed file type detectors are loaded using the system class
* loader. If the system class loader cannot be found then the extension class
* loader is used; If the extension class loader cannot be found then the
* bootstrap class loader is used. File type detectors are typically installed
* by placing them in a JAR file on the application class path or in the
* extension directory, the JAR file contains a provider-configuration file
* named {@code java.nio.file.spi.FileTypeDetector} in the resource directory
* {@code META-INF/services}, and the file lists one or more fully-qualified
* names of concrete subclass of {@code FileTypeDetector } that have a zero
* argument constructor. If the process of locating or instantiating the
* installed file type detectors fails then an unspecified error is thrown.
* The ordering that installed providers are located is implementation
* specific.
*
* <p> The return value of this method is the string form of the value of a
* Multipurpose Internet Mail Extension (MIME) content type as
* defined by <a href="http://www.ietf.org/rfc/rfc2045.txt"><i>RFC 2045:
* Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet
* Message Bodies</i></a>. The string is guaranteed to be parsable according
* to the grammar in the RFC.
*
* @param path
* the path to the file to probe
*
* @return The content type of the file, or {@code null} if the content
* type cannot be determined
*
* @throws IOException
* if an I/O error occurs
* @throws SecurityException
* If a security manager is installed and it denies an unspecified
* permission required by a file type detector implementation.
*/
public static String probeContentType(Path path)
throws IOException
{
// try installed file type detectors
for (FileTypeDetector detector: FileTypeDetectors.installeDetectors) {
String result = detector.probeContentType(path);
if (result != null)
return result;
}
// fallback to default
return FileTypeDetectors.defaultFileTypeDetector.probeContentType(path);
}
示例3: probeContentType
import java.nio.file.spi.FileTypeDetector; //导入方法依赖的package包/类
/**
* Probes the content type of a file.
*
* <p> This method uses the installed {@link FileTypeDetector} implementations
* to probe the given file to determine its content type. Each file type
* detector's {@link FileTypeDetector#probeContentType probeContentType} is
* invoked, in turn, to probe the file type. If the file is recognized then
* the content type is returned. If the file is not recognized by any of the
* installed file type detectors then a system-default file type detector is
* invoked to guess the content type.
*
* <p> A given invocation of the Java virtual machine maintains a system-wide
* list of file type detectors. Installed file type detectors are loaded
* using the service-provider loading facility defined by the {@link ServiceLoader}
* class. Installed file type detectors are loaded using the system class
* loader. If the system class loader cannot be found then the platform class
* loader is used. File type detectors are typically installed
* by placing them in a JAR file on the application class path,
* the JAR file contains a provider-configuration file
* named {@code java.nio.file.spi.FileTypeDetector} in the resource directory
* {@code META-INF/services}, and the file lists one or more fully-qualified
* names of concrete subclass of {@code FileTypeDetector } that have a zero
* argument constructor. If the process of locating or instantiating the
* installed file type detectors fails then an unspecified error is thrown.
* The ordering that installed providers are located is implementation
* specific.
*
* <p> The return value of this method is the string form of the value of a
* Multipurpose Internet Mail Extension (MIME) content type as
* defined by <a href="http://www.ietf.org/rfc/rfc2045.txt"><i>RFC 2045:
* Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet
* Message Bodies</i></a>. The string is guaranteed to be parsable according
* to the grammar in the RFC.
*
* @param path
* the path to the file to probe
*
* @return The content type of the file, or {@code null} if the content
* type cannot be determined
*
* @throws IOException
* if an I/O error occurs
* @throws SecurityException
* If a security manager is installed and it denies an unspecified
* permission required by a file type detector implementation.
*/
public static String probeContentType(Path path)
throws IOException
{
// try installed file type detectors
for (FileTypeDetector detector: FileTypeDetectors.installedDetectors) {
String result = detector.probeContentType(path);
if (result != null)
return result;
}
// fallback to default
return FileTypeDetectors.defaultFileTypeDetector.probeContentType(path);
}