#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#AdditionalJar: c:/temp/guava-21.0.jar
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Dim MediaType As JavaObject
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.Show
MediaType.InitializeStatic("com.google.common.net.MediaType")
' see https://google.github.io/guava/releases/23.0/api/docs/com/google/common/net/MediaType.html for types
Dim fileType As String = asJO(Me).RunMethod("getType",Array("c:/temp/hannah.jpg")) ' the file to examine
'what nio sees it as
Log(fileType)
' use guava to group them into types of file video, image, text etc
If fileType<>"null" Then
If MediaType.RunMethodJO("parse",Array(fileType)).RunMethod("is",Array(MediaType.GetField("ANY_IMAGE_TYPE"))) Then
Log("Image file")
else if MediaType.RunMethodJO("parse",Array(fileType)).RunMethod("is",Array(MediaType.GetField("ANY_VIDEO_TYPE"))) Then
Log("Video file")
else if MediaType.RunMethodJO("parse",Array(fileType)).RunMethod("is",Array(MediaType.GetField("ANY_TEXT_TYPE"))) Then
Log("Text file")
Else
Log("File is : "&MediaType.RunMethod("parse",Array(fileType)))
End If
End If
End Sub
Sub asJO(o As JavaObject)As JavaObject
Return o
End Sub
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
#if java
import java.nio.file.*;
import java.io.*;
public static String getType(String filePath) throws IOException , SecurityException{
return Files.probeContentType(Paths.get(filePath));
}
#End If