Merge pull request 'fix(utils): remove JMI for MimeType' (#3) from dev into master

Reviewed-on: https://git.poupouche.fr/Thibaut/ffsaf-site/pulls/3
This commit is contained in:
Thibaut Valentin 2025-01-10 16:02:50 +01:00
commit b070bb5767

View File

@ -11,6 +11,7 @@ import java.io.*;
import java.net.URISyntaxException;
import java.net.URLConnection;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.CompletableFuture;
@ -77,12 +78,14 @@ public class Utils {
try (InputStream is = new BufferedInputStream(new ByteArrayInputStream(input))) {
String mimeType = URLConnection.guessContentTypeFromStream(is);
System.out.println(mimeType);
/*try {
mimeType = Magic.getMagicMatch(input, false).getMimeType();
} catch (MagicParseException | MagicMatchNotFoundException | MagicException e) {
mimeType = URLConnection.guessContentTypeFromStream(is);
}*/
String[] detectedExtensions = MimeTypes.findExtensionsByMimeTypes(mimeType, false);
System.out.println(Arrays.toString(detectedExtensions));
if (detectedExtensions.length == 0)
throw new IOException("Fail to detect file extension for MIME type " + mimeType);