src/java.base/macosx/classes/sun/nio/fs/UTIFileTypeDetector.java
author redestad
Wed, 17 Jul 2019 12:35:46 +0200
changeset 55693 9a97b1393e72
parent 47216 71c04702a3d5
permissions -rw-r--r--
8227587: Add internal privileged System.loadLibrary Reviewed-by: rriggs, mchung, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31450
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
     1
/*
55693
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
     2
 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
31450
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
     4
 *
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    10
 *
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    15
 * accompanied this code).
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    16
 *
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    20
 *
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    23
 * questions.
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    24
 */
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    25
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    26
package sun.nio.fs;
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    27
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    28
import java.io.IOException;
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    29
import java.nio.file.Path;
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    30
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    31
/**
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    32
 * File type detector that uses a file extension to look up its MIME type
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    33
 * via the Apple Uniform Type Identifier interfaces.
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    34
 */
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    35
class UTIFileTypeDetector extends AbstractFileTypeDetector {
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    36
    UTIFileTypeDetector() {
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    37
        super();
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    38
    }
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    39
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    40
    private native String probe0(String fileExtension) throws IOException;
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    41
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    42
    @Override
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    43
    protected String implProbeContentType(Path path) throws IOException {
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    44
        Path fn = path.getFileName();
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    45
        if (fn == null)
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    46
            return null;  // no file name
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    47
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    48
        String ext = getExtension(fn.toString());
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    49
        if (ext.isEmpty())
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    50
            return null;  // no extension
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    51
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    52
        return probe0(ext);
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    53
    }
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    54
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    55
    static {
55693
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    56
        jdk.internal.loader.BootLoader.loadLibrary("nio");
31450
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    57
    }
35fe554da3fb 8129632: (fs) Files.probeContentType returns null on Mac OS X
bpb
parents:
diff changeset
    58
}