TikaCLI { public static void main(String[] args) throws Exception { TikaCLI cli = new TikaCLI(); if (!isConfigured()) { try (InputStream is = cli.getClass().getResourceAsStream("/log4j.properties")) { PropertyConfigurator.configure(is); } } if (cli.testForHelp(args)) { cli.usage(); return; } else if (cli.testForBatch(args)) { String[] batchArgs = BatchCommandLineBuilder.build(args); BatchProcessDriverCLI batchDriver = new BatchProcessDriverCLI(batchArgs); batchDriver.execute(); return; } if (args.length > 0) { for (int i = 0; i < args.length; i++) { cli.process(args[i]); } if (cli.pipeMode) { cli.process("-"); } } else { if (System.in.available() == 0) { Thread.sleep(100); } if (System.in.available() > 0) { cli.process("-"); } else { cli.process("--gui"); } } } TikaCLI(); static void main(String[] args); void process(String arg);  }
@Test public void testContentAllOutput() throws Exception{ String[] params = {"-A", resourcePrefix + "testJsonMultipleInts.html"}; TikaCLI.main(params); String out = outContent.toString(UTF_8.name()); assertTrue(out.contains("this is a title")); assertTrue(out.contains("body")); }
@Test public void testExtractTgz() throws Exception { File tempFile = File.createTempFile("tika-test-", ""); assertTrue(tempFile.delete()); assertTrue(tempFile.mkdir()); try { String[] params = {"--extract-dir="+tempFile.getAbsolutePath(),"-z", resourcePrefix + "/test-documents.tgz"}; TikaCLI.main(params); String[] tempFileNames = tempFile.list(); assertNotNull(tempFileNames); String allFiles = String.join(" : ", tempFileNames); File expectedTAR = new File(tempFile, "test-documents.tar"); assertExtracted(expectedTAR, allFiles); } finally { FileUtils.deleteDirectory(tempFile); } }
@Test public void testExtractInlineImages() throws Exception { File tempFile = File.createTempFile("tika-test-", ""); assertTrue(tempFile.delete()); assertTrue(tempFile.mkdir()); try { String[] params = {"--extract-dir="+tempFile.getAbsolutePath(),"-z", resourcePrefix + "/testPDF_childAttachments.pdf"}; TikaCLI.main(params); String[] tempFileNames = tempFile.list(); assertNotNull(tempFileNames); String allFiles = String.join(" : ", tempFileNames); File jpeg = new File(tempFile, "image0.jpg"); File jobOptions = new File(tempFile, "Press Quality(1).joboptions"); File doc = new File(tempFile, "Unit10.doc"); assertExtracted(jpeg, allFiles); assertExtracted(jobOptions, allFiles); assertExtracted(doc, allFiles); } finally { FileUtils.deleteDirectory(tempFile); } }
@Test public void testDefaultConfigException() throws Exception { String[] params = {resourcePrefix + "bad_xml.xml"}; boolean tikaEx = false; try { TikaCLI.main(params); } catch (TikaException e) { tikaEx = true; } assertTrue(tikaEx); }