當前位置: 首頁>>代碼示例>>Java>>正文


Java TikaInputStream.close方法代碼示例

本文整理匯總了Java中org.apache.tika.io.TikaInputStream.close方法的典型用法代碼示例。如果您正苦於以下問題:Java TikaInputStream.close方法的具體用法?Java TikaInputStream.close怎麽用?Java TikaInputStream.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.tika.io.TikaInputStream的用法示例。


在下文中一共展示了TikaInputStream.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getFullText

import org.apache.tika.io.TikaInputStream; //導入方法依賴的package包/類
private static String getFullText(final String filepath) throws IOException, SAXException, TikaException {
    StringWriter writer = new StringWriter();
    
    final TikaInputStream inputStream =  TikaInputStream.get(new File(filepath));
    try {
        final Detector detector = new DefaultDetector();
        final Parser parser = new AutoDetectParser(detector);

        final Metadata metadata = new Metadata();
        final ParseContext parseContext = new ParseContext();
        parseContext.set(Parser.class, parser);

        
        ContentHandler contentHandler = new BodyContentHandler(writer);
        parser.parse(inputStream, contentHandler, metadata, parseContext);
    }
    finally {
        inputStream.close();
    }
    
    return writer.toString();
}
 
開發者ID:CoEIA,項目名稱:DEM,代碼行數:23,代碼來源:ItemFactory.java

示例2: TikaProperties

import org.apache.tika.io.TikaInputStream; //導入方法依賴的package包/類
public TikaProperties(File file) throws IOException, SAXException,
		TikaException {
	TikaInputStream tikaStream = TikaInputStream.get(file);
	metadata = new Metadata();
	ContentHandler handler = new DefaultHandler();
	Parser parser = new AutoDetectParser();
	ParseContext context = new ParseContext();
	try {
		parser.parse(tikaStream, handler, metadata, context);
	} finally {
		try {
			tikaStream.close();
		} catch (Exception ie) {
			// ignore
		}
	}
}
 
開發者ID:fmui,項目名稱:ApacheChemistryInAction,代碼行數:18,代碼來源:TikaProperties.java

示例3: getMimeType

import org.apache.tika.io.TikaInputStream; //導入方法依賴的package包/類
public static String getMimeType(byte[] data, String fileName) throws Throwable {
	TikaInputStream tikaStream = null;
	Metadata metadata = new Metadata();
	metadata.add(Metadata.RESOURCE_NAME_KEY, fileName);
	try {
		tikaStream = TikaInputStream.get(data, metadata);
		return detector.detect(tikaStream, metadata).toString();
	} catch (Throwable t) {
		throw t;
	} finally {
		if (tikaStream != null) {
			try {
				tikaStream.close();
			} catch (IOException e) {
			}
		}
	}
}
 
開發者ID:phoenixctms,項目名稱:ctsms,代碼行數:19,代碼來源:ExecUtil.java

示例4: getMimeType

import org.apache.tika.io.TikaInputStream; //導入方法依賴的package包/類
public String getMimeType() throws IOException
{
	TikaInputStream tikaIS = null;
	try
	{
		tikaIS = TikaInputStream.get(file);

		return new DefaultDetector(MimeTypes.getDefaultMimeTypes()).detect(tikaIS, new Metadata()).toString();
	} finally
	{
		if (tikaIS != null)
		{
			tikaIS.close();
		}
	}
}
 
開發者ID:julianfalcionelli,項目名稱:SimpleRESTClientHandler,代碼行數:17,代碼來源:FileManager.java

示例5: handleEmbeddedResource

import org.apache.tika.io.TikaInputStream; //導入方法依賴的package包/類
protected void handleEmbeddedResource(TikaInputStream resource, String filename,
                                      String relationshipID, String mediaType, XHTMLContentHandler xhtml,
                                      boolean outputHtml)
throws IOException, SAXException, TikaException {
  try {
    Metadata metadata = new Metadata();
    if (filename != null) {
      metadata.set(Metadata.TIKA_MIME_FILE, filename);
      metadata.set(Metadata.RESOURCE_NAME_KEY, filename);
    }
    if (relationshipID != null) {
      metadata.set(Metadata.EMBEDDED_RELATIONSHIP_ID, relationshipID);
    }
    if (mediaType != null) {
      metadata.set(Metadata.CONTENT_TYPE, mediaType);
    }

    if (extractor.shouldParseEmbedded(metadata)) {
      extractor.parseEmbedded(resource, xhtml, metadata, outputHtml);
    }
  } finally {
    resource.close();
  }
}
 
開發者ID:kolbasa,項目名稱:OCRaptor,代碼行數:25,代碼來源:AbstractPOIFSExtractor.java

示例6: getImgInfo

import org.apache.tika.io.TikaInputStream; //導入方法依賴的package包/類
public Metadata getImgInfo(String urlStr) throws Exception {
    if (StringUtils.isBlank(urlStr)) return null;
    URL url = new URL(urlStr);
    Metadata md = new Metadata();
    StringWriter htmlBuffer = new StringWriter();
    Parser parser = new  AutoDetectParser();
    imageParser= new ImageSavingParser(parser);
    TikaInputStream stream = TikaInputStream.get(url, md);
    try {
        ContentHandler handler = new TeeContentHandler(getHtmlHandler(htmlBuffer));
        parser.parse(stream, handler, md, new ParseContext());
    } finally {
        stream.close();
    }
    return md;
}
 
開發者ID:zhishan332,項目名稱:hunt4j,代碼行數:17,代碼來源:TikaHelper.java

示例7: process

import org.apache.tika.io.TikaInputStream; //導入方法依賴的package包/類
private EmbeddedObjectCollections process(String filename, ContainerExtractor extractor) throws Exception {
    TikaInputStream stream = getTikaInputStream(filename);
    EmbeddedObjectCollections handler = null;
    
    try {
        // Process it
        handler = new EmbeddedObjectCollections(this.destination, this.type);
        
        if( type == OBJECT_TYPE.CONTAINER) { // recursive extractor to get all items inside document
            extractor.extract(stream, extractor, handler);
        } else if ( type == OBJECT_TYPE.ARCHIVE ) { // extract all object inside document
            extractor.extract(stream, null, handler);
        }
    } finally {
        stream.close();
    }
    
    // handler will contain all information about the extracted object and they path
    return handler;
}
 
開發者ID:CoEIA,項目名稱:DEM,代碼行數:21,代碼來源:TikaObjectExtractor.java

示例8: testEmbeddedFilesInChildren

import org.apache.tika.io.TikaInputStream; //導入方法依賴的package包/類
public void testEmbeddedFilesInChildren() throws Exception {
    String xml = getXML("/testPDF_childAttachments.pdf").xml;
    //"regressiveness" exists only in Unit10.doc not in the container pdf document
    assertTrue(xml.contains("regressiveness"));

    TrackingHandler tracker = new TrackingHandler();
    TikaInputStream tis = null;
    ContainerExtractor ex = new ParserContainerExtractor();
    try{
        tis= TikaInputStream.get(
            getResourceAsStream("/test-documents/testPDF_childAttachments.pdf"));
        ex.extract(tis, ex, tracker);
    } finally {
        if (tis != null){
            tis.close();
        }
    }
    assertEquals(2, tracker.filenames.size());
    assertEquals(2, tracker.mediaTypes.size());
    assertEquals("Press Quality(1).joboptions", tracker.filenames.get(0));
    assertEquals("Unit10.doc", tracker.filenames.get(1));
    assertEquals(TYPE_TEXT, tracker.mediaTypes.get(0));
    assertEquals(TYPE_DOC, tracker.mediaTypes.get(1));
}
 
開發者ID:kanrourou,項目名稱:software-testing,代碼行數:25,代碼來源:PDFParserTest.java

示例9: extractMeta

import org.apache.tika.io.TikaInputStream; //導入方法依賴的package包/類
public static String extractMeta(String uri, String contentType) throws Exception {
	final AutoDetectParser parser = createParser();
	final Metadata metadata = new Metadata();

	fillMetadata(parser, metadata, contentType, uri);

	final TikaInputStream inputStream = createInputStream(uri, metadata);

	parser.parse(inputStream, new DefaultHandler(), metadata);

	Map meta = new HashMap();
	for (String name : metadata.names()) {
		String[] values = metadata.getValues(name);
		meta.put(name, values);
	}

	inputStream.close();

	return new Gson().toJson(meta);
}
 
開發者ID:ICIJ,項目名稱:node-tika,代碼行數:21,代碼來源:NodeTika.java

示例10: detectContentType

import org.apache.tika.io.TikaInputStream; //導入方法依賴的package包/類
public static String detectContentType(String uri) throws FileNotFoundException, IOException, TikaException {
	final Detector detector = config.getDetector();
	final TikaInputStream inputStream = createInputStream(uri);
	final Metadata metadata = new Metadata();

	// Set the file name. This provides some level of type-hinting.
	metadata.add(TikaMetadataKeys.RESOURCE_NAME_KEY, new File(uri).getName());

	// Detect the content type.
	String contentType = detector.detect(inputStream, metadata).toString();

	inputStream.close();

	// Return the default content-type if undetermined.
	if (contentType == null || contentType.isEmpty()) {
		return MediaType.OCTET_STREAM.toString();
	}

	return contentType;
}
 
開發者ID:ICIJ,項目名稱:node-tika,代碼行數:21,代碼來源:NodeTika.java

示例11: detectMimeType

import org.apache.tika.io.TikaInputStream; //導入方法依賴的package包/類
public static String detectMimeType(final String filePath) {
    TikaInputStream tikaIS = null;
    try {
        File targetFile = new File(filePath);
        tikaIS = TikaInputStream.get(targetFile);

    /*
     * You might not want to provide the file's name. If you provide an Excel
     * document with a .xls extension, it will get it correct right away; but
     * if you provide an Excel document with .doc extension, it will guess it
     * to be a Word document
     */
        final Metadata metadata = new Metadata();
        metadata.set(Metadata.RESOURCE_NAME_KEY, targetFile.getName());

        return DETECTOR.detect(tikaIS, metadata).toString();
    } catch (IOException ex) {
        return "UNKNOWN";
    } finally {
        if (tikaIS != null) {
            try {
                tikaIS.close();
            } catch (IOException e) {
                Timber.d(e, e.getMessage(), LOG_TAG);
            }
        }
    }
}
 
開發者ID:crysehillmes,項目名稱:smoothnovelreader,代碼行數:29,代碼來源:NovelBookShelfFragment.java

示例12: parse

import org.apache.tika.io.TikaInputStream; //導入方法依賴的package包/類
/**
 * Parsa una immagine
 * @param image immagine
 * @param handler handler
 * @param metadata metadata
 * @param context contesto
 * @throws IOException eccezione di scrittura
 * @throws SAXException eccezione di sax
 * @throws TikaException eccezione di tika
 */
public void parse(Image image, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException,
        SAXException, TikaException {

    TemporaryResources tmp = new TemporaryResources();
    FileOutputStream fos = null;
    TikaInputStream tis = null;
    try {
        int w = image.getWidth(null);
        int h = image.getHeight(null);
        BufferedImage bImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        File file = tmp.createTemporaryFile();
        fos = new FileOutputStream(file);
        ImageIO.write(bImage, "png", fos);
        tis = TikaInputStream.get(file);
        parse(tis, handler, metadata, context);

    } finally {
        tmp.dispose();
        if (tis != null) {
            tis.close();
        }
        if (fos != null) {
            fos.close();
        }
    }

}
 
開發者ID:fiohol,項目名稱:theSemProject,代碼行數:38,代碼來源:TesseractOCRParser.java

示例13: processEmbeddedDocNames

import org.apache.tika.io.TikaInputStream; //導入方法依賴的package包/類
private void processEmbeddedDocNames(
  Map<String, COSObjectable> embeddedFileNames,
  EmbeddedDocumentExtractor embeddedExtractor) throws IOException,
  SAXException, TikaException {
  if (embeddedFileNames == null) {
    return;
  }
  for (Map.Entry<String, COSObjectable> ent : embeddedFileNames.entrySet()) {
    PDComplexFileSpecification spec = (PDComplexFileSpecification) ent
                                      .getValue();
    PDEmbeddedFile file = spec.getEmbeddedFile();

    Metadata metadata = new Metadata();
    // TODO: other metadata?
    metadata.set(Metadata.RESOURCE_NAME_KEY, ent.getKey());
    metadata.set(Metadata.CONTENT_TYPE, file.getSubtype());
    metadata.set(Metadata.CONTENT_LENGTH, Long.toString(file.getSize()));

    if (embeddedExtractor.shouldParseEmbedded(metadata)) {
      TikaInputStream stream = TikaInputStream.get(file.createInputStream());
      try {
        embeddedExtractor.parseEmbedded(stream, new EmbeddedContentHandler(
                                          handler), metadata, false);
      } finally {
        stream.close();
      }
    }
  }
}
 
開發者ID:kolbasa,項目名稱:OCRaptor,代碼行數:30,代碼來源:PDF2XHTML.java

示例14: getMetaInfo

import org.apache.tika.io.TikaInputStream; //導入方法依賴的package包/類
public Metadata getMetaInfo(String urlStr) throws Exception {
    if (StringUtils.isBlank(urlStr)) return null;
    URL url = new URL(urlStr);
    Metadata md = new Metadata();
    TikaInputStream stream = TikaInputStream.get(url, md);
    try {
        ContentHandler handler = new TeeContentHandler();
        Parser parser = new AutoDetectParser();
        parser.parse(stream, handler, md, new ParseContext());
    } finally {
        stream.close();
    }
    return md;
}
 
開發者ID:zhishan332,項目名稱:hunt4j,代碼行數:15,代碼來源:TikaHelper.java

示例15: openURL

import org.apache.tika.io.TikaInputStream; //導入方法依賴的package包/類
public  void openURL(URL url) {
    try {
        Metadata metadata = new Metadata();
        TikaInputStream stream = TikaInputStream.get(url, metadata);
        try {
            handleStream(stream, metadata);
        } finally {
            stream.close();
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
 
開發者ID:zhishan332,項目名稱:hunt4j,代碼行數:14,代碼來源:TestUrl.java


注:本文中的org.apache.tika.io.TikaInputStream.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。