Java Code Examples for java.nio.file.spi.FileTypeDetector#probeContentType()

The following examples show how to use java.nio.file.spi.FileTypeDetector#probeContentType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MCRContentTypes.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 2
Source File: Files.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
}
 
Example 3
Source File: Files.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
}
 
Example 4
Source File: Files.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
}
 
Example 5
Source File: Files.java    From jdk8u-dev-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 6
Source File: Files.java    From jdk-1.7-annotated with Apache License 2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 7
Source File: Files.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 8
Source File: Files.java    From jdk8u_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 9
Source File: Files.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 10
Source File: Files.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 11
Source File: Files.java    From hottub with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 12
Source File: Files.java    From Java8CN with Apache License 2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 13
Source File: Files.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 14
Source File: Files.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 15
Source File: Files.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 16
Source File: Files.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 17
Source File: Files.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 18
Source File: Files.java    From JDKSourceCode1.8 with MIT License 3 votes vote down vote up
/**
 * 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);
}
 
Example 19
Source File: Files.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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);
}