< prev index next >

src/java.base/unix/classes/sun/nio/fs/MimeTypesFileTypeDetector.java

Print this page




  89         if (name != null && !name.isEmpty()) {
  90             int dot = name.indexOf('.');
  91             if ((dot >= 0) && (dot < name.length() - 1)) {
  92                 ext = name.substring(dot + 1);
  93             }
  94         }
  95         return ext;
  96     }
  97 
  98     /**
  99      * Parse the mime types file, and store the type-extension mappings into
 100      * mimeTypeMap. The mime types file is not loaded until the first probe
 101      * to achieve the lazy initialization. It adopts double-checked locking
 102      * optimization to reduce the locking overhead.
 103      */
 104     private void loadMimeTypes() {
 105         if (!loaded) {
 106             synchronized (this) {
 107                 if (!loaded) {
 108                     List<String> lines = AccessController.doPrivileged(
 109                         new PrivilegedAction<List<String>>() {
 110                             @Override
 111                             public List<String> run() {
 112                                 try {
 113                                     return Files.readAllLines(mimeTypesFile,
 114                                                               Charset.defaultCharset());
 115                                 } catch (IOException ignore) {
 116                                     return Collections.emptyList();
 117                                 }
 118                             }
 119                         });
 120 
 121                     mimeTypeMap = new HashMap<>(lines.size());
 122                     String entry = "";
 123                     for (String line : lines) {
 124                         entry += line;
 125                         if (entry.endsWith("\\")) {
 126                             entry = entry.substring(0, entry.length() - 1);
 127                             continue;
 128                         }
 129                         parseMimeEntry(entry);




  89         if (name != null && !name.isEmpty()) {
  90             int dot = name.indexOf('.');
  91             if ((dot >= 0) && (dot < name.length() - 1)) {
  92                 ext = name.substring(dot + 1);
  93             }
  94         }
  95         return ext;
  96     }
  97 
  98     /**
  99      * Parse the mime types file, and store the type-extension mappings into
 100      * mimeTypeMap. The mime types file is not loaded until the first probe
 101      * to achieve the lazy initialization. It adopts double-checked locking
 102      * optimization to reduce the locking overhead.
 103      */
 104     private void loadMimeTypes() {
 105         if (!loaded) {
 106             synchronized (this) {
 107                 if (!loaded) {
 108                     List<String> lines = AccessController.doPrivileged(
 109                         new PrivilegedAction<>() {
 110                             @Override
 111                             public List<String> run() {
 112                                 try {
 113                                     return Files.readAllLines(mimeTypesFile,
 114                                                               Charset.defaultCharset());
 115                                 } catch (IOException ignore) {
 116                                     return Collections.emptyList();
 117                                 }
 118                             }
 119                         });
 120 
 121                     mimeTypeMap = new HashMap<>(lines.size());
 122                     String entry = "";
 123                     for (String line : lines) {
 124                         entry += line;
 125                         if (entry.endsWith("\\")) {
 126                             entry = entry.substring(0, entry.length() - 1);
 127                             continue;
 128                         }
 129                         parseMimeEntry(entry);


< prev index next >