java.nio.file.spi.FileTypeDetector#probeContentType ( )源码实例Demo

下面列出了java.nio.file.spi.FileTypeDetector#probeContentType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: mycore   文件: MCRContentTypes.java
/**
 * 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 项目: jdk1.8-source-analysis   文件: Files.java
/**
 * 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&nbsp;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 项目: dragonwell8_jdk   文件: Files.java
/**
 * 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&nbsp;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);
}
 
源代码4 项目: TencentKona-8   文件: Files.java
/**
 * 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&nbsp;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);
}
 
源代码5 项目: jdk8u60   文件: Files.java
/**
 * 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&nbsp;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);
}
 
源代码6 项目: JDKSourceCode1.8   文件: Files.java
/**
 * 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&nbsp;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);
}
 
源代码7 项目: openjdk-jdk8u   文件: Files.java
/**
 * 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&nbsp;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);
}
 
源代码8 项目: openjdk-jdk8u-backup   文件: Files.java
/**
 * 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&nbsp;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);
}
 
源代码9 项目: Bytecoder   文件: Files.java
/**
 * 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&nbsp;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);
}
 
源代码10 项目: openjdk-jdk9   文件: Files.java
/**
 * 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&nbsp;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);
}
 
源代码11 项目: jdk8u-jdk   文件: Files.java
/**
 * 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&nbsp;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);
}
 
源代码12 项目: Java8CN   文件: Files.java
/**
 * 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&nbsp;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);
}
 
源代码13 项目: hottub   文件: Files.java
/**
 * 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&nbsp;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);
}
 
源代码14 项目: openjdk-8-source   文件: Files.java
/**
 * 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&nbsp;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);
}
 
源代码15 项目: openjdk-8   文件: Files.java
/**
 * 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&nbsp;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);
}
 
源代码16 项目: jdk8u_jdk   文件: Files.java
/**
 * 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&nbsp;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);
}
 
源代码17 项目: jdk8u-jdk   文件: Files.java
/**
 * 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&nbsp;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);
}
 
源代码18 项目: jdk-1.7-annotated   文件: Files.java
/**
 * 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&nbsp;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);
}
 
源代码19 项目: jdk8u-dev-jdk   文件: Files.java
/**
 * 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&nbsp;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);
}
 
 同类方法