Class FileValidatorUtil
java.lang.Object
com.evolveum.midpoint.web.component.input.validator.FileValidatorUtil
Contains methods for file validation.
E.g. compares file contentType with list of allowed ones or checks if given file starts with magic number of expected contentType.
- Author:
- matisovaa
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic List<jakarta.activation.MimeType>getMimeTypes(List<String> stringMimeTypes) Converts list of String mime type names (e.g.static booleanisValidContentType(String contentType, List<jakarta.activation.MimeType> allowedTypes) Validates if given content type name is in the list of allowed MimeTypes.static booleanisValidMagicNumber(String contentType, InputStream inputStream) Validates if given inputStream begins with magic number of given contentType.
-
Constructor Details
-
FileValidatorUtil
public FileValidatorUtil()
-
-
Method Details
-
getMimeTypes
Converts list of String mime type names (e.g. "image/jpeg") to list of MimeType objects.- Parameters:
stringMimeTypes- list of String mime type names (e.g. "image/jpeg")- Returns:
- list of MimeType objects creates from input list of String mime type names (e.g. "image/jpeg")
-
isValidContentType
public static boolean isValidContentType(String contentType, List<jakarta.activation.MimeType> allowedTypes) throws jakarta.activation.MimeTypeParseException Validates if given content type name is in the list of allowed MimeTypes.- Parameters:
contentType- to check if it is allowedallowedTypes- the list of allowed MimeTypes- Returns:
- true if given contentType is in the list of allowed MimeTypes, false otherwise
- Throws:
jakarta.activation.MimeTypeParseException- if it is not possible to convert given contentType to MimeType
-
isValidMagicNumber
public static boolean isValidMagicNumber(String contentType, InputStream inputStream) throws IOException Validates if given inputStream begins with magic number of given contentType.- Parameters:
contentType- expected contentType of data in given inputStreaminputStream- stream of data to check contentType based on its magic number- Returns:
- true if given inputStream begins with magic number of given contentType, false otherwise
- Throws:
IOException- if there is problem to read bytes from given inputStream
-