This commit is contained in:
地平线
2015-09-23 14:01:05 +08:00
parent 6962861132
commit 2c97f696da

View File

@@ -208,7 +208,6 @@ public class MimeType {
public static void add(String extension, String contentType) { public static void add(String extension, String contentType) {
if (extension != null && extension.length() != 0 if (extension != null && extension.length() != 0
&& contentType != null && contentType.length() != 0) { && contentType != null && contentType.length() != 0) {
contentTypes.put(extension, contentType); contentTypes.put(extension, contentType);
} }
} }
@@ -220,12 +219,7 @@ public class MimeType {
*/ */
public static String getByFilename(String fileName) { public static String getByFilename(String fileName) {
String extn = getExtension(fileName); String extn = getExtension(fileName);
if (extn != null) { return extn == null ? null : get(extn);
return get(extn);
} else {
// no extension, no content type
return null;
}
} }
/** /**
@@ -237,19 +231,10 @@ public class MimeType {
int length = fileName.length(); int length = fileName.length();
int newEnd = fileName.lastIndexOf('#'); int newEnd = fileName.lastIndexOf('#');
if (newEnd == -1) { if (newEnd == -1) newEnd = length;
newEnd = length;
}
// Instead of creating a new string. // Instead of creating a new string.
// if (i != -1) { // if (i != -1) fileName = fileName.substring(0, i);
// fileName = fileName.substring(0, i);
// }
int i = fileName.lastIndexOf('.', newEnd); int i = fileName.lastIndexOf('.', newEnd);
if (i != -1) { return i == -1 ? null : fileName.substring(i + 1, newEnd);
return fileName.substring(i + 1, newEnd);
} else {
// no extension, no content type
return null;
}
} }
} }