Java Code Examples for java.nio.file.spi.FileTypeDetector

The following examples show how to use java.nio.file.spi.FileTypeDetector. These examples are extracted from open source projects. 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 Project: jdk1.8-source-analysis   Source File: Files.java    License: Apache License 2.0 5 votes vote down vote up
private static FileTypeDetector createDefaultFileTypeDetector() {
    return AccessController
        .doPrivileged(new PrivilegedAction<FileTypeDetector>() {
            @Override public FileTypeDetector run() {
                return sun.nio.fs.DefaultFileTypeDetector.create();
        }});
}
 
Example 2
Source Project: jdk8u-dev-jdk   Source File: Files.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static List<FileTypeDetector> loadInstalledDetectors() {
    return AccessController
        .doPrivileged(new PrivilegedAction<List<FileTypeDetector>>() {
            @Override public List<FileTypeDetector> run() {
                List<FileTypeDetector> list = new ArrayList<>();
                ServiceLoader<FileTypeDetector> loader = ServiceLoader
                    .load(FileTypeDetector.class, ClassLoader.getSystemClassLoader());
                for (FileTypeDetector detector: loader) {
                    list.add(detector);
                }
                return list;
        }});
}
 
Example 3
Source Project: hottub   Source File: Files.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static FileTypeDetector createDefaultFileTypeDetector() {
    return AccessController
        .doPrivileged(new PrivilegedAction<FileTypeDetector>() {
            @Override public FileTypeDetector run() {
                return sun.nio.fs.DefaultFileTypeDetector.create();
        }});
}
 
Example 4
Source Project: dragonwell8_jdk   Source File: Files.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static FileTypeDetector createDefaultFileTypeDetector() {
    return AccessController
        .doPrivileged(new PrivilegedAction<FileTypeDetector>() {
            @Override public FileTypeDetector run() {
                return sun.nio.fs.DefaultFileTypeDetector.create();
        }});
}
 
Example 5
Source Project: dragonwell8_jdk   Source File: Files.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static List<FileTypeDetector> loadInstalledDetectors() {
    return AccessController
        .doPrivileged(new PrivilegedAction<List<FileTypeDetector>>() {
            @Override public List<FileTypeDetector> run() {
                List<FileTypeDetector> list = new ArrayList<>();
                ServiceLoader<FileTypeDetector> loader = ServiceLoader
                    .load(FileTypeDetector.class, ClassLoader.getSystemClassLoader());
                for (FileTypeDetector detector: loader) {
                    list.add(detector);
                }
                return list;
        }});
}
 
Example 6
@Override
FileTypeDetector getFileTypeDetector() {
    Path userMimeTypes = Paths.get(AccessController.doPrivileged(
        new GetPropertyAction("user.home")), ".mime.types");
    Path etcMimeTypes = Paths.get("/etc/mime.types");

    return chain(new GnomeFileTypeDetector(),
                 new MimeTypesFileTypeDetector(userMimeTypes),
                 new MimeTypesFileTypeDetector(etcMimeTypes),
                 new MagicFileTypeDetector());
}
 
Example 7
Source Project: openjdk-8   Source File: Files.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static List<FileTypeDetector> loadInstalledDetectors() {
    return AccessController
        .doPrivileged(new PrivilegedAction<List<FileTypeDetector>>() {
            @Override public List<FileTypeDetector> run() {
                List<FileTypeDetector> list = new ArrayList<>();
                ServiceLoader<FileTypeDetector> loader = ServiceLoader
                    .load(FileTypeDetector.class, ClassLoader.getSystemClassLoader());
                for (FileTypeDetector detector: loader) {
                    list.add(detector);
                }
                return list;
        }});
}
 
Example 8
Source Project: TencentKona-8   Source File: Files.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static FileTypeDetector createDefaultFileTypeDetector() {
    return AccessController
        .doPrivileged(new PrivilegedAction<FileTypeDetector>() {
            @Override public FileTypeDetector run() {
                return sun.nio.fs.DefaultFileTypeDetector.create();
        }});
}
 
Example 9
Source Project: TencentKona-8   Source File: Files.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static List<FileTypeDetector> loadInstalledDetectors() {
    return AccessController
        .doPrivileged(new PrivilegedAction<List<FileTypeDetector>>() {
            @Override public List<FileTypeDetector> run() {
                List<FileTypeDetector> list = new ArrayList<>();
                ServiceLoader<FileTypeDetector> loader = ServiceLoader
                    .load(FileTypeDetector.class, ClassLoader.getSystemClassLoader());
                for (FileTypeDetector detector: loader) {
                    list.add(detector);
                }
                return list;
        }});
}
 
Example 10
Source Project: openjdk-8   Source File: Files.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static FileTypeDetector createDefaultFileTypeDetector() {
    return AccessController
        .doPrivileged(new PrivilegedAction<FileTypeDetector>() {
            @Override public FileTypeDetector run() {
                return sun.nio.fs.DefaultFileTypeDetector.create();
        }});
}
 
Example 11
/**
 * Returns a {@code FileTypeDetector} for this platform.
 */
FileTypeDetector getFileTypeDetector() {
    return new AbstractFileTypeDetector() {
        @Override
        public String implProbeContentType(Path file) {
            return null;
        }
    };
}
 
Example 12
/**
 * Returns a {@code FileTypeDetector} that chains the given array of file
 * type detectors. When the {@code implProbeContentType} method is invoked
 * then each of the detectors is invoked in turn, the result from the
 * first to detect the file type is returned.
 */
final FileTypeDetector chain(final AbstractFileTypeDetector... detectors) {
    return new AbstractFileTypeDetector() {
        @Override
        protected String implProbeContentType(Path file) throws IOException {
            for (AbstractFileTypeDetector detector : detectors) {
                String result = detector.implProbeContentType(file);
                if (result != null && !result.isEmpty()) {
                    return result;
                }
            }
            return null;
        }
    };
}
 
Example 13
@Override
FileTypeDetector getFileTypeDetector() {
    Path userMimeTypes = Paths.get(AccessController.doPrivileged(
        new GetPropertyAction("user.home")), ".mime.types");
    Path etcMimeTypes = Paths.get("/etc/mime.types");

    return chain(new GnomeFileTypeDetector(),
                 new MimeTypesFileTypeDetector(userMimeTypes),
                 new MimeTypesFileTypeDetector(etcMimeTypes),
                 new MagicFileTypeDetector());
}
 
Example 14
Source Project: hottub   Source File: Files.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static List<FileTypeDetector> loadInstalledDetectors() {
    return AccessController
        .doPrivileged(new PrivilegedAction<List<FileTypeDetector>>() {
            @Override public List<FileTypeDetector> run() {
                List<FileTypeDetector> list = new ArrayList<>();
                ServiceLoader<FileTypeDetector> loader = ServiceLoader
                    .load(FileTypeDetector.class, ClassLoader.getSystemClassLoader());
                for (FileTypeDetector detector: loader) {
                    list.add(detector);
                }
                return list;
        }});
}
 
Example 15
Source Project: jdk8u60   Source File: Files.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static List<FileTypeDetector> loadInstalledDetectors() {
    return AccessController
        .doPrivileged(new PrivilegedAction<List<FileTypeDetector>>() {
            @Override public List<FileTypeDetector> run() {
                List<FileTypeDetector> list = new ArrayList<>();
                ServiceLoader<FileTypeDetector> loader = ServiceLoader
                    .load(FileTypeDetector.class, ClassLoader.getSystemClassLoader());
                for (FileTypeDetector detector: loader) {
                    list.add(detector);
                }
                return list;
        }});
}
 
Example 16
/**
 * Returns a {@code FileTypeDetector} that chains the given array of file
 * type detectors. When the {@code implProbeContentType} method is invoked
 * then each of the detectors is invoked in turn, the result from the
 * first to detect the file type is returned.
 */
final FileTypeDetector chain(final AbstractFileTypeDetector... detectors) {
    return new AbstractFileTypeDetector() {
        @Override
        protected String implProbeContentType(Path file) throws IOException {
            for (AbstractFileTypeDetector detector : detectors) {
                String result = detector.implProbeContentType(file);
                if (result != null && !result.isEmpty()) {
                    return result;
                }
            }
            return null;
        }
    };
}
 
Example 17
/**
 * Returns a {@code FileTypeDetector} for this platform.
 */
FileTypeDetector getFileTypeDetector() {
    return new AbstractFileTypeDetector() {
        @Override
        public String implProbeContentType(Path file) {
            return null;
        }
    };
}
 
Example 18
/**
 * Returns a {@code FileTypeDetector} that chains the given array of file
 * type detectors. When the {@code implProbeContentType} method is invoked
 * then each of the detectors is invoked in turn, the result from the
 * first to detect the file type is returned.
 */
final FileTypeDetector chain(final AbstractFileTypeDetector... detectors) {
    return new AbstractFileTypeDetector() {
        @Override
        protected String implProbeContentType(Path file) throws IOException {
            for (AbstractFileTypeDetector detector : detectors) {
                String result = detector.implProbeContentType(file);
                if (result != null && !result.isEmpty()) {
                    return result;
                }
            }
            return null;
        }
    };
}
 
Example 19
/**
 * Returns a {@code FileTypeDetector} for this platform.
 */
FileTypeDetector getFileTypeDetector() {
    return new AbstractFileTypeDetector() {
        @Override
        public String implProbeContentType(Path file) {
            return null;
        }
    };
}
 
Example 20
Source Project: JDKSourceCode1.8   Source File: Files.java    License: MIT License 5 votes vote down vote up
private static FileTypeDetector createDefaultFileTypeDetector() {
    return AccessController
        .doPrivileged(new PrivilegedAction<FileTypeDetector>() {
            @Override public FileTypeDetector run() {
                return sun.nio.fs.DefaultFileTypeDetector.create();
        }});
}
 
Example 21
Source Project: JDKSourceCode1.8   Source File: Files.java    License: MIT License 5 votes vote down vote up
private static List<FileTypeDetector> loadInstalledDetectors() {
    return AccessController
        .doPrivileged(new PrivilegedAction<List<FileTypeDetector>>() {
            @Override public List<FileTypeDetector> run() {
                List<FileTypeDetector> list = new ArrayList<>();
                ServiceLoader<FileTypeDetector> loader = ServiceLoader
                    .load(FileTypeDetector.class, ClassLoader.getSystemClassLoader());
                for (FileTypeDetector detector: loader) {
                    list.add(detector);
                }
                return list;
        }});
}
 
Example 22
Source Project: jdk-1.7-annotated   Source File: Files.java    License: Apache License 2.0 5 votes vote down vote up
private static List<FileTypeDetector> loadInstalledDetectors() {
    return AccessController
        .doPrivileged(new PrivilegedAction<List<FileTypeDetector>>() {
            @Override public List<FileTypeDetector> run() {
                List<FileTypeDetector> list = new ArrayList<>();
                ServiceLoader<FileTypeDetector> loader = ServiceLoader
                    .load(FileTypeDetector.class, ClassLoader.getSystemClassLoader());
                for (FileTypeDetector detector: loader) {
                    list.add(detector);
                }
                return list;
        }});
}
 
Example 23
Source Project: openjdk-jdk8u   Source File: Files.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static List<FileTypeDetector> loadInstalledDetectors() {
    return AccessController
        .doPrivileged(new PrivilegedAction<List<FileTypeDetector>>() {
            @Override public List<FileTypeDetector> run() {
                List<FileTypeDetector> list = new ArrayList<>();
                ServiceLoader<FileTypeDetector> loader = ServiceLoader
                    .load(FileTypeDetector.class, ClassLoader.getSystemClassLoader());
                for (FileTypeDetector detector: loader) {
                    list.add(detector);
                }
                return list;
        }});
}
 
Example 24
@Override
FileTypeDetector getFileTypeDetector() {
    Path userMimeTypes = Paths.get(AccessController.doPrivileged(
        new GetPropertyAction("user.home")), ".mime.types");
    Path etcMimeTypes = Paths.get("/etc/mime.types");

    return chain(new GnomeFileTypeDetector(),
                 new MimeTypesFileTypeDetector(userMimeTypes),
                 new MimeTypesFileTypeDetector(etcMimeTypes),
                 new MagicFileTypeDetector());
}
 
Example 25
@Override
FileTypeDetector getFileTypeDetector() {
    Path userMimeTypes = Paths.get(AccessController.doPrivileged(
        new GetPropertyAction("user.home")), ".mime.types");
    Path etcMimeTypes = Paths.get("/etc/mime.types");

    return chain(new GnomeFileTypeDetector(),
                 new MimeTypesFileTypeDetector(userMimeTypes),
                 new MimeTypesFileTypeDetector(etcMimeTypes));
}
 
Example 26
@Override
FileTypeDetector getFileTypeDetector() {
    Path userMimeTypes = Paths.get(AccessController.doPrivileged(
        new GetPropertyAction("user.home")), ".mime.types");
    Path etcMimeTypes = Paths.get("/etc/mime.types");

    return chain(new GnomeFileTypeDetector(),
                 new MimeTypesFileTypeDetector(userMimeTypes),
                 new MimeTypesFileTypeDetector(etcMimeTypes),
                 new MagicFileTypeDetector());
}
 
Example 27
@Override
FileTypeDetector getFileTypeDetector() {
    Path userMimeTypes = Paths.get(AccessController.doPrivileged(
        new GetPropertyAction("user.home")), ".mime.types");
    Path etcMimeTypes = Paths.get("/etc/mime.types");

    return chain(new GnomeFileTypeDetector(),
                 new MimeTypesFileTypeDetector(userMimeTypes),
                 new MimeTypesFileTypeDetector(etcMimeTypes));
}
 
Example 28
Source Project: jdk8u-dev-jdk   Source File: Files.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static FileTypeDetector createDefaultFileTypeDetector() {
    return AccessController
        .doPrivileged(new PrivilegedAction<FileTypeDetector>() {
            @Override public FileTypeDetector run() {
                return sun.nio.fs.DefaultFileTypeDetector.create();
        }});
}
 
Example 29
Source Project: openjdk-jdk8u-backup   Source File: Files.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static FileTypeDetector createDefaultFileTypeDetector() {
    return AccessController
        .doPrivileged(new PrivilegedAction<FileTypeDetector>() {
            @Override public FileTypeDetector run() {
                return sun.nio.fs.DefaultFileTypeDetector.create();
        }});
}
 
Example 30
Source Project: openjdk-jdk8u-backup   Source File: Files.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static List<FileTypeDetector> loadInstalledDetectors() {
    return AccessController
        .doPrivileged(new PrivilegedAction<List<FileTypeDetector>>() {
            @Override public List<FileTypeDetector> run() {
                List<FileTypeDetector> list = new ArrayList<>();
                ServiceLoader<FileTypeDetector> loader = ServiceLoader
                    .load(FileTypeDetector.class, ClassLoader.getSystemClassLoader());
                for (FileTypeDetector detector: loader) {
                    list.add(detector);
                }
                return list;
        }});
}