mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Make MimeType top level check related methods more robust
Throwing an IllegalArgumentException doesn't help the method signature. PiperOrigin-RevId: 234579722
This commit is contained in:
parent
8e7ae9201a
commit
774c01d020
1 changed files with 7 additions and 29 deletions
|
|
@ -120,42 +120,22 @@ public final class MimeTypes {
|
||||||
customMimeTypes.add(customMimeType);
|
customMimeTypes.add(customMimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Returns whether the given string is an audio mime type. */
|
||||||
* Whether the top-level type of {@code mimeType} is audio.
|
|
||||||
*
|
|
||||||
* @param mimeType The mimeType to test.
|
|
||||||
* @return Whether the top level type is audio.
|
|
||||||
*/
|
|
||||||
public static boolean isAudio(@Nullable String mimeType) {
|
public static boolean isAudio(@Nullable String mimeType) {
|
||||||
return BASE_TYPE_AUDIO.equals(getTopLevelType(mimeType));
|
return BASE_TYPE_AUDIO.equals(getTopLevelType(mimeType));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Returns whether the given string is a video mime type. */
|
||||||
* Whether the top-level type of {@code mimeType} is video.
|
|
||||||
*
|
|
||||||
* @param mimeType The mimeType to test.
|
|
||||||
* @return Whether the top level type is video.
|
|
||||||
*/
|
|
||||||
public static boolean isVideo(@Nullable String mimeType) {
|
public static boolean isVideo(@Nullable String mimeType) {
|
||||||
return BASE_TYPE_VIDEO.equals(getTopLevelType(mimeType));
|
return BASE_TYPE_VIDEO.equals(getTopLevelType(mimeType));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Returns whether the given string is a text mime type. */
|
||||||
* Whether the top-level type of {@code mimeType} is text.
|
|
||||||
*
|
|
||||||
* @param mimeType The mimeType to test.
|
|
||||||
* @return Whether the top level type is text.
|
|
||||||
*/
|
|
||||||
public static boolean isText(@Nullable String mimeType) {
|
public static boolean isText(@Nullable String mimeType) {
|
||||||
return BASE_TYPE_TEXT.equals(getTopLevelType(mimeType));
|
return BASE_TYPE_TEXT.equals(getTopLevelType(mimeType));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Returns whether the given string is an application mime type. */
|
||||||
* Whether the top-level type of {@code mimeType} is application.
|
|
||||||
*
|
|
||||||
* @param mimeType The mimeType to test.
|
|
||||||
* @return Whether the top level type is application.
|
|
||||||
*/
|
|
||||||
public static boolean isApplication(@Nullable String mimeType) {
|
public static boolean isApplication(@Nullable String mimeType) {
|
||||||
return BASE_TYPE_APPLICATION.equals(getTopLevelType(mimeType));
|
return BASE_TYPE_APPLICATION.equals(getTopLevelType(mimeType));
|
||||||
}
|
}
|
||||||
|
|
@ -384,10 +364,8 @@ public final class MimeTypes {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the top-level type of {@code mimeType}.
|
* Returns the top-level type of {@code mimeType}, or null if {@code mimeType} is null or does not
|
||||||
*
|
* contain a forward slash character ({@code '/'}).
|
||||||
* @param mimeType The mimeType whose top-level type is required.
|
|
||||||
* @return The top-level type, or null if the mimeType is null.
|
|
||||||
*/
|
*/
|
||||||
private static @Nullable String getTopLevelType(@Nullable String mimeType) {
|
private static @Nullable String getTopLevelType(@Nullable String mimeType) {
|
||||||
if (mimeType == null) {
|
if (mimeType == null) {
|
||||||
|
|
@ -395,7 +373,7 @@ public final class MimeTypes {
|
||||||
}
|
}
|
||||||
int indexOfSlash = mimeType.indexOf('/');
|
int indexOfSlash = mimeType.indexOf('/');
|
||||||
if (indexOfSlash == -1) {
|
if (indexOfSlash == -1) {
|
||||||
throw new IllegalArgumentException("Invalid mime type: " + mimeType);
|
return null;
|
||||||
}
|
}
|
||||||
return mimeType.substring(0, indexOfSlash);
|
return mimeType.substring(0, indexOfSlash);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue