⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plaintexthandler.java

📁 Lucene in Action 中文版代码下载
💻 JAVA
字号:
package lia.handlingtypes.text;import lia.handlingtypes.framework.DocumentHandler;import lia.handlingtypes.framework.DocumentHandlerException;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;import java.io.File;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.FileInputStream;public class PlainTextHandler implements DocumentHandler {  public Document getDocument(InputStream is)    throws DocumentHandlerException {    String bodyText = "";    try {      BufferedReader br =        new BufferedReader(new InputStreamReader(is));      String line = null;      while ((line = br.readLine()) != null) {        bodyText += line;      }      br.close();    }    catch(IOException e) {      throw new DocumentHandlerException(        "Cannot read the text document", e);    }    if (!bodyText.equals("")) {      Document doc = new Document();      doc.add(Field.UnStored("body", bodyText));      return doc;    }    return null;  }  public static void main(String[] args) throws Exception {    PlainTextHandler handler = new PlainTextHandler();    Document doc = handler.getDocument(      new FileInputStream(new File(args[0])));    System.out.println(doc);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -