8004288: (fs) Files.probeContentType problems
Reviewed-by: ahgross, sherman
This commit is contained in:
parent
14d39ee359
commit
013fa331c6
@ -1485,10 +1485,19 @@ public final class Files {
|
|||||||
// lazy loading of default and installed file type detectors
|
// lazy loading of default and installed file type detectors
|
||||||
private static class FileTypeDetectors{
|
private static class FileTypeDetectors{
|
||||||
static final FileTypeDetector defaultFileTypeDetector =
|
static final FileTypeDetector defaultFileTypeDetector =
|
||||||
sun.nio.fs.DefaultFileTypeDetector.create();
|
createDefaultFileTypeDetector();
|
||||||
static final List<FileTypeDetector> installeDetectors =
|
static final List<FileTypeDetector> installeDetectors =
|
||||||
loadInstalledDetectors();
|
loadInstalledDetectors();
|
||||||
|
|
||||||
|
// creates the default file type detector
|
||||||
|
private static FileTypeDetector createDefaultFileTypeDetector() {
|
||||||
|
return AccessController
|
||||||
|
.doPrivileged(new PrivilegedAction<FileTypeDetector>() {
|
||||||
|
@Override public FileTypeDetector run() {
|
||||||
|
return sun.nio.fs.DefaultFileTypeDetector.create();
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
// loads all installed file type detectors
|
// loads all installed file type detectors
|
||||||
private static List<FileTypeDetector> loadInstalledDetectors() {
|
private static List<FileTypeDetector> loadInstalledDetectors() {
|
||||||
return AccessController
|
return AccessController
|
||||||
|
@ -67,6 +67,8 @@ public class GnomeFileTypeDetector
|
|||||||
NativeBuffer buffer = NativeBuffers.asNativeBuffer(path.getByteArrayForSysCalls());
|
NativeBuffer buffer = NativeBuffers.asNativeBuffer(path.getByteArrayForSysCalls());
|
||||||
try {
|
try {
|
||||||
if (gioAvailable) {
|
if (gioAvailable) {
|
||||||
|
// GIO may access file so need permission check
|
||||||
|
path.checkRead();
|
||||||
byte[] type = probeUsingGio(buffer.address());
|
byte[] type = probeUsingGio(buffer.address());
|
||||||
return (type == null) ? null : new String(type);
|
return (type == null) ? null : new String(type);
|
||||||
} else {
|
} else {
|
||||||
@ -76,7 +78,6 @@ public class GnomeFileTypeDetector
|
|||||||
String s = new String(type);
|
String s = new String(type);
|
||||||
return s.equals(GNOME_VFS_MIME_TYPE_UNKNOWN) ? null : s;
|
return s.equals(GNOME_VFS_MIME_TYPE_UNKNOWN) ? null : s;
|
||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
buffer.release();
|
buffer.release();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user