2525import org .apache .commons .io .FileUtils ;
2626import org .xml .sax .ContentHandler ;
2727
28- import org .apache .tika .config .TikaConfig ;
28+ import org .apache .tika .config .loader . TikaLoader ;
2929import org .apache .tika .detect .Detector ;
3030import org .apache .tika .io .TikaInputStream ;
3131import org .apache .tika .langdetect .optimaize .OptimaizeLangDetector ;
5050public class MyFirstTika {
5151 public static void main (String [] args ) throws Exception {
5252 String filename = args [0 ];
53- TikaConfig tikaConfig = TikaConfig . getDefaultConfig ();
53+ TikaLoader tikaLoader = TikaLoader . loadDefault ();
5454
5555 Metadata metadata = new Metadata ();
56- String text = parseUsingComponents (filename , tikaConfig , metadata );
56+ String text = parseUsingComponents (filename , tikaLoader , metadata );
5757 System .out .println ("Parsed Metadata: " );
5858 System .out .println (metadata );
5959 System .out .println ("Parsed Text: " );
@@ -62,25 +62,25 @@ public static void main(String[] args) throws Exception {
6262 System .out .println ("-------------------------" );
6363
6464 metadata = new Metadata ();
65- text = parseUsingAutoDetect (filename , tikaConfig , metadata );
65+ text = parseUsingAutoDetect (filename , tikaLoader , metadata );
6666 System .out .println ("Parsed Metadata: " );
6767 System .out .println (metadata );
6868 System .out .println ("Parsed Text: " );
6969 System .out .println (text );
7070 }
7171
72- public static String parseUsingAutoDetect (String filename , TikaConfig tikaConfig , Metadata metadata ) throws Exception {
72+ public static String parseUsingAutoDetect (String filename , TikaLoader tikaLoader , Metadata metadata ) throws Exception {
7373 System .out .println ("Handling using AutoDetectParser: [" + filename + "]" );
7474
75- AutoDetectParser parser = new AutoDetectParser ( tikaConfig );
75+ Parser parser = tikaLoader . loadAutoDetectParser ( );
7676 ContentHandler handler = new BodyContentHandler ();
7777 TikaInputStream stream = TikaInputStream .get (Paths .get (filename ), metadata );
7878 parser .parse (stream , handler , metadata , new ParseContext ());
7979 return handler .toString ();
8080 }
8181
82- public static String parseUsingComponents (String filename , TikaConfig tikaConfig , Metadata metadata ) throws Exception {
83- MimeTypes mimeRegistry = tikaConfig . getMimeRepository ();
82+ public static String parseUsingComponents (String filename , TikaLoader tikaLoader , Metadata metadata ) throws Exception {
83+ MimeTypes mimeRegistry = tikaLoader . getMimeTypes ();
8484
8585 System .out .println ("Examining: [" + filename + "]" );
8686
@@ -91,7 +91,7 @@ public static String parseUsingComponents(String filename, TikaConfig tikaConfig
9191 System .out .println ("The MIME type (based on MAGIC) is: [" + mimeRegistry .detect (stream , metadata ) + "]" );
9292
9393 stream = TikaInputStream .get (Paths .get (filename ));
94- Detector detector = tikaConfig . getDetector ();
94+ Detector detector = tikaLoader . loadDetectors ();
9595 System .out .println ("The MIME type (based on the Detector interface) is: [" + detector .detect (stream , metadata ) + "]" );
9696
9797 LanguageDetector langDetector = new OptimaizeLangDetector ().loadModels ();
@@ -100,7 +100,7 @@ public static String parseUsingComponents(String filename, TikaConfig tikaConfig
100100 System .out .println ("The language of this content is: [" + lang .getLanguage () + "]" );
101101
102102 // Get a non-detecting parser that handles all the types it can
103- Parser parser = tikaConfig . getParser ();
103+ Parser parser = tikaLoader . loadParsers ();
104104 // Tell it what we think the content is
105105 MediaType type = detector .detect (stream , metadata );
106106 metadata .set (Metadata .CONTENT_TYPE , type .toString ());
0 commit comments