Lines 99-104
Link Here
|
99 |
|
99 |
|
100 |
private static final Logger LOG = Logger.getLogger(FileUtil.class.getName()); |
100 |
private static final Logger LOG = Logger.getLogger(FileUtil.class.getName()); |
101 |
|
101 |
|
|
|
102 |
private static final String MIME_CONTENT_UNKNOWN = "content/unknown"; |
103 |
|
102 |
/** Normal header for ZIP files. */ |
104 |
/** Normal header for ZIP files. */ |
103 |
private static byte[] ZIP_HEADER_1 = {0x50, 0x4b, 0x03, 0x04}; |
105 |
private static byte[] ZIP_HEADER_1 = {0x50, 0x4b, 0x03, 0x04}; |
104 |
/** Also seems to be used at least in apisupport/project/test/unit/data/example-external-projects/suite3/nbplatform/random/modules/ext/stuff.jar; not known why */ |
106 |
/** Also seems to be used at least in apisupport/project/test/unit/data/example-external-projects/suite3/nbplatform/random/modules/ext/stuff.jar; not known why */ |
Lines 1318-1329
Link Here
|
1318 |
* the FileObject is unrecognized. It may return {@code content/unknown} instead of {@code null}. |
1320 |
* the FileObject is unrecognized. It may return {@code content/unknown} instead of {@code null}. |
1319 |
* It is possible for the resulting MIME type to not be a member of given list. |
1321 |
* It is possible for the resulting MIME type to not be a member of given list. |
1320 |
* @since 7.13 |
1322 |
* @since 7.13 |
|
|
1323 |
* @deprecated Use {@link #checkMIMEType(FileObject, String...)} instead. |
1321 |
*/ |
1324 |
*/ |
|
|
1325 |
@Deprecated |
1322 |
public static String getMIMEType(FileObject fo, String... withinMIMETypes) { |
1326 |
public static String getMIMEType(FileObject fo, String... withinMIMETypes) { |
1323 |
Parameters.notNull("withinMIMETypes", withinMIMETypes); //NOI18N |
1327 |
Parameters.notNull("withinMIMETypes", withinMIMETypes); //NOI18N |
1324 |
return MIMESupport.findMIMEType(fo, withinMIMETypes); |
1328 |
return MIMESupport.findMIMEType(fo, withinMIMETypes); |
1325 |
} |
1329 |
} |
1326 |
|
1330 |
|
|
|
1331 |
/** |
1332 |
* Check whether FileObject has one of specified MIME types. |
1333 |
* |
1334 |
* <p> |
1335 |
* Note: Checking MIME type "content/unknown" (or null) may be more |
1336 |
* expensive than checking specific MIME types, because all resolvers need |
1337 |
* to be queried. |
1338 |
* </p> |
1339 |
* |
1340 |
* @param fo The FileObject to check. |
1341 |
* @param mimeTypes Array of MIME types. It can also contain null or value |
1342 |
* "content/unknown", which means that the method will return value |
1343 |
* "content/unknown" if MIME type of {@code fo} is unrecognized. |
1344 |
* @return The actual MIME type if MIME type of {@code fo} is equal to one |
1345 |
* of values in {@code mimeTypes}; or value "content/unknown" if the MIME |
1346 |
* type of {@code fo} is unrecognized and {@code mimeTypes} contains null or |
1347 |
* value "content/unknown". Null otherwise (i.e. MIME type of the file is |
1348 |
* not contained in {@code mimeTypes}) |
1349 |
*/ |
1350 |
public static String checkMIMEType(FileObject fo, String... mimeTypes) { |
1351 |
|
1352 |
// If we want to check that the MIME type is unrecognized, we need |
1353 |
// to query all resolvers. |
1354 |
boolean checkUnrecognized = false; |
1355 |
|
1356 |
String theMime = getMIMEType(fo, mimeTypes); |
1357 |
for (String oneOfTypes : mimeTypes) { |
1358 |
if (oneOfTypes == null || oneOfTypes.equals(MIME_CONTENT_UNKNOWN)) { |
1359 |
checkUnrecognized = true; |
1360 |
} else if (oneOfTypes.equals(theMime)) { |
1361 |
return theMime; |
1362 |
} |
1363 |
} |
1364 |
if (checkUnrecognized) { |
1365 |
String checkAllResult = getMIMEType(fo); |
1366 |
if (checkAllResult == null |
1367 |
|| checkAllResult.equals(MIME_CONTENT_UNKNOWN)) { |
1368 |
return MIME_CONTENT_UNKNOWN; |
1369 |
} |
1370 |
} |
1371 |
return null; |
1372 |
} |
1373 |
|
1327 |
/** Registers specified extension to be recognized as specified MIME type. |
1374 |
/** Registers specified extension to be recognized as specified MIME type. |
1328 |
* If MIME type parameter is null, it cancels previous registration. |
1375 |
* If MIME type parameter is null, it cancels previous registration. |
1329 |
* Note that you may register a case-sensitive extension if that is |
1376 |
* Note that you may register a case-sensitive extension if that is |