import java.io.IOException;
import java.io.InputStream;
import org.apache.tika.detect.DefaultDetector;
import org.apache.tika.detect.Detector;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.mime.MediaType;
public class FileypeDetection {
public static void main(String[] args) throws IOException {
InputStream stream = FileypeDetection.class.getClassLoader()
.getResourceAsStream("C:\\template.pdf");
System.out.println(detectDocTypeUsingDetector(stream));
}
public static String detectDocTypeUsingDetector(InputStream stream)
throws IOException {
Detector detector = new DefaultDetector();
Metadata metadata = new Metadata();
MediaType mediaType = detector.detect(stream, metadata);
return mediaType.toString();
}
}
Throughout my professional and personal journey in software development, I've come across various technical challenges to tackle. These instances serve as valuable examples that I wish to retain. My hope is that they prove beneficial to fellow developers facing similar hurdles.
Monday, 11 May 2020
Security File Type Detection with Apache Tikka - OWASP
Thursday, 23 April 2020
Subscribe to:
Posts (Atom)
AWS Certificate Manager - Import Certificate
How to import a certificate. Use Key Store Explorer to open the cert and export keypair in PEM format This will save a file cert.pem. Make ...

-
Code to validate a model POJO using jackson using annotations import java.io.IOException; import java.util.ArrayList; import java.util.Lis...
-
This is possible issue when the multiple jars of bouncy castle are loaded within the server. Steps to follow. 1) Make sure right correc...
-
Below code was used to consume a rest service Used this implementation to inject a factory bean with a trustFactory into my JaxWS spring b...