org.apache.tika.io.IOUtils.toString()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(189)

本文整理了Java中org.apache.tika.io.IOUtils.toString()方法的一些代码示例,展示了IOUtils.toString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.toString()方法的具体详情如下:
包路径:org.apache.tika.io.IOUtils
类名称:IOUtils
方法名:toString

IOUtils.toString介绍

[英]Get the contents of an InputStream as a String using the default character encoding of the platform.

This method buffers the input internally, so there is no need to use a BufferedInputStream.
[中]使用平台的默认字符编码以字符串形式获取InputStream的内容。
此方法在内部缓冲输入,因此无需使用BufferedInputStream

代码示例

代码示例来源:origin: apache/tika

/**
 * Translate the given text InputStream to the given language, attempting to auto-detect the source language.
 * This does not close the stream, so the caller has the responsibility of closing it.
 * @see org.apache.tika.language.translate.Translator
 * @param text The text to translate.
 * @param targetLanguage The desired output language (for example, "en").
 * @return The translated text. If translation is unavailable (client keys not set), returns the same text back.
 */
public String translate(InputStream text, String targetLanguage){
  try {
    return translator.translate(IOUtils.toString(text), targetLanguage);
  } catch (Exception e){
    throw new IllegalStateException("Error translating data.", e);
  }
}

代码示例来源:origin: apache/tika

/**
 * Translate the given text InputStream to and from the given languages.
 * @see org.apache.tika.language.translate.Translator
 * @param text The text to translate.
 * @param sourceLanguage The input text language (for example, "hi").
 * @param targetLanguage The desired output language (for example, "fr").
 * @return The translated text. If translation is unavailable (client keys not set), returns the same text back.
 */
public String translate(InputStream text, String sourceLanguage, String targetLanguage){
  try {
    return translator.translate(IOUtils.toString(text), sourceLanguage, targetLanguage);
  } catch (Exception e){
    throw new IllegalStateException("Error translating data.", e);
  }
}

代码示例来源:origin: apache/tika

private String readStream(InputStream stream) throws IOException {
  return IOUtils.toString(stream, UTF_8.name());
}

代码示例来源:origin: apache/tika

/**
 * Loads the class to
 *
 * @param stream label index stream
 * @return Map of integer -> label name
 * @throws IOException    when the stream breaks unexpectedly
 * @throws ParseException when the input doesn't contain a valid JSON map
 */
public Map<Integer, String> loadClassIndex(InputStream stream)
    throws IOException, ParseException {
  String content = IOUtils.toString(stream);
  JSONObject jIndex = (JSONObject) new JSONParser().parse(content);
  Map<Integer, String> classMap = new HashMap<>();
  for (Object key : jIndex.keySet()) {
    JSONArray names = (JSONArray) jIndex.get(key);
    classMap.put(Integer.parseInt(key.toString()),
        names.get(names.size() - 1).toString());
  }
  return classMap;
}

代码示例来源:origin: apache/tika

public static void main(String[] args) throws IOException, JSONException {
    if (args.length != 1) {
      System.err.println("Error: Invalid Args");
      System.err.println("This tool finds names inside text");
      System.err.println("Usage: <path/to/text/file>");
      return;
    }

    try (FileInputStream stream = new FileInputStream(args[0])) {
      String text = IOUtils.toString(stream);
      CoreNLPNERecogniser ner = new CoreNLPNERecogniser();
      Map<String, Set<String>> names = ner.recognise(text);
      JSONObject jNames = new JSONObject(names);
      System.out.println(jNames.toString(2));
    }
  }
}

代码示例来源:origin: apache/tika

String replyMessage = IOUtils.toString(reply);
if (response.getStatusLine().getStatusCode() == 200) {
  JSONObject jReply = (JSONObject) new JSONParser().parse(replyMessage);

代码示例来源:origin: apache/tika

String replyMessage = IOUtils.toString(reply);
if (response.getStatusLine().getStatusCode() == 200) {
  JSONObject jReply = new JSONObject(replyMessage);

代码示例来源:origin: apache/tika

private List<Metadata> generateListFromTextFile(Reader reader,
                            FileSuffixes fileSuffixes) throws IOException {
  List<Metadata> metadataList = new ArrayList<>();
  String content = IOUtils.toString(reader);
  Metadata m = new Metadata();
  m.set(AbstractRecursiveParserWrapperHandler.TIKA_CONTENT, content);
  if (fileSuffixes.format == FileSuffixes.FORMAT.HTML) {
    m.set(RecursiveParserWrapperHandler.TIKA_CONTENT_HANDLER, ToXMLContentHandler.class.getSimpleName());
  } else if (fileSuffixes.format == FileSuffixes.FORMAT.TXT) {
    m.set(RecursiveParserWrapperHandler.TIKA_CONTENT_HANDLER, ToTextContentHandler.class.getSimpleName());
  }
  //Let's hope the file name has a suffix that can
  //be used to determine the mime.  Could be wrong or missing,
  //but better than nothing.
  m.set(TikaCoreProperties.RESOURCE_NAME_KEY, fileSuffixes.originalFileName);
  MediaType mimeType = tikaConfig.getMimeRepository().detect(null, m);
  if (mimeType != null) {
    m.set(Metadata.CONTENT_TYPE, mimeType.toString());
  }
  metadataList.add(m);
  return metadataList;
}

代码示例来源:origin: apache/tika

contents = IOUtils.toString(reader);

代码示例来源:origin: com.github.lafa.tikaNoExternal/tika-core

/**
 * Translate the given text InputStream to and from the given languages.
 * @see org.apache.tika.language.translate.Translator
 * @param text The text to translate.
 * @param sourceLanguage The input text language (for example, "hi").
 * @param targetLanguage The desired output language (for example, "fr").
 * @return The translated text. If translation is unavailable (client keys not set), returns the same text back.
 */
public String translate(InputStream text, String sourceLanguage, String targetLanguage){
  try {
    return translator.translate(IOUtils.toString(text), sourceLanguage, targetLanguage);
  } catch (Exception e){
    throw new IllegalStateException("Error translating data.", e);
  }
}

代码示例来源:origin: com.github.lafa.tikaNoExternal/tika-core

/**
 * Translate the given text InputStream to the given language, attempting to auto-detect the source language.
 * This does not close the stream, so the caller has the responsibility of closing it.
 * @see org.apache.tika.language.translate.Translator
 * @param text The text to translate.
 * @param targetLanguage The desired output language (for example, "en").
 * @return The translated text. If translation is unavailable (client keys not set), returns the same text back.
 */
public String translate(InputStream text, String targetLanguage){
  try {
    return translator.translate(IOUtils.toString(text), targetLanguage);
  } catch (Exception e){
    throw new IllegalStateException("Error translating data.", e);
  }
}

代码示例来源:origin: org.apache.tika/tika-core

/**
 * Translate the given text InputStream to and from the given languages.
 * @see org.apache.tika.language.translate.Translator
 * @param text The text to translate.
 * @param sourceLanguage The input text language (for example, "hi").
 * @param targetLanguage The desired output language (for example, "fr").
 * @return The translated text. If translation is unavailable (client keys not set), returns the same text back.
 */
public String translate(InputStream text, String sourceLanguage, String targetLanguage){
  try {
    return translator.translate(IOUtils.toString(text), sourceLanguage, targetLanguage);
  } catch (Exception e){
    throw new IllegalStateException("Error translating data.", e);
  }
}

代码示例来源:origin: org.apache.tika/tika-core

/**
 * Translate the given text InputStream to the given language, attempting to auto-detect the source language.
 * This does not close the stream, so the caller has the responsibility of closing it.
 * @see org.apache.tika.language.translate.Translator
 * @param text The text to translate.
 * @param targetLanguage The desired output language (for example, "en").
 * @return The translated text. If translation is unavailable (client keys not set), returns the same text back.
 */
public String translate(InputStream text, String targetLanguage){
  try {
    return translator.translate(IOUtils.toString(text), targetLanguage);
  } catch (Exception e){
    throw new IllegalStateException("Error translating data.", e);
  }
}

代码示例来源:origin: com.github.lafa.tikaNoExternal/tika-parsers

public static void main(String[] args) throws IOException {
    if (args.length != 1) {
      System.err.println("Error: Invalid Args");
      System.err.println("This tool finds names inside text");
      System.err.println("Usage: <path/to/text/file>");
      return;
    }

    try (FileInputStream stream = new FileInputStream(args[0])) {
      String text = IOUtils.toString(stream);
      CoreNLPNERecogniser ner = new CoreNLPNERecogniser();
      Map<String, Set<String>> names = ner.recognise(text);
      JSONObject jNames = new JSONObject(names);
      System.out.println(jNames.toString(2));
    }
  }
}

代码示例来源:origin: org.apache.tika/tika-parsers

public static void main(String[] args) throws IOException, JSONException {
    if (args.length != 1) {
      System.err.println("Error: Invalid Args");
      System.err.println("This tool finds names inside text");
      System.err.println("Usage: <path/to/text/file>");
      return;
    }

    try (FileInputStream stream = new FileInputStream(args[0])) {
      String text = IOUtils.toString(stream);
      CoreNLPNERecogniser ner = new CoreNLPNERecogniser();
      Map<String, Set<String>> names = ner.recognise(text);
      JSONObject jNames = new JSONObject(names);
      System.out.println(jNames.toString(2));
    }
  }
}

代码示例来源:origin: info.magnolia/magnolia-4-5-migration

static String htmlHeader(String title) {
  String header = "<html>\n";
  header += "  <head>\n";
  header += "    <title>Migration report" + (StringUtils.isBlank(title) ? "" : ": " + title) + "</title>\n";
  String style = null;
  try {
    String[] resources = ClasspathResourcesUtil.findResources("/report-generator/migration-report.css");
    if (resources != null && resources.length > 0) {
      InputStream in = DefaultReportGenerator.class.getResourceAsStream(resources[0]);
      style = IOUtils.toString(in);
      IOUtils.closeQuietly(in);
    }
  } catch (IOException e) {
    log.error("Cannot load CSS style: "+e.getMessage());
    log.debug("Cannot load CSS style.", e);
  }
  if (style!=null) {
    header += "<style>\n";
    header += style;
    header += "</style>\n";
  }
  header += "  </head>\n";
  header += "  <body>\n";
  header += "  <h1>Migration report</h1>\n\n";
  return header;
}

代码示例来源:origin: com.bstek.urule/urule-console

public List<String> getReferenceFiles(Node rootNode,String path,String searchText) throws Exception{
  List<String> referenceFiles=new ArrayList<String>();
  List<String> files=getFiles(rootNode, path);
  for(String nodePath:files){
    InputStream inputStream=repositoryService.readFile(nodePath,null);
    try {
      String content = IOUtils.toString(inputStream);
      inputStream.close();
      boolean containPath=content.contains(path);
      boolean containText=content.contains(searchText);
      if(containPath && containText){
        referenceFiles.add(nodePath);
      }
    } catch (IOException e) {
      throw new RuleException(e);
    }
  }
  return referenceFiles;
}

代码示例来源:origin: com.github.lafa.tikaNoExternal/tika-external

String replyMessage = IOUtils.toString(reply);
if (response.getStatusLine().getStatusCode() == 200) {
  JSONObject jReply = new JSONObject(replyMessage);

代码示例来源:origin: org.apache.tika/tika-parsers

String replyMessage = IOUtils.toString(reply);
if (response.getStatusLine().getStatusCode() == 200) {
  JSONObject jReply = (JSONObject) new JSONParser().parse(replyMessage);

代码示例来源:origin: org.apache.tika/tika-parsers

String replyMessage = IOUtils.toString(reply);
if (response.getStatusLine().getStatusCode() == 200) {
  JSONObject jReply = new JSONObject(replyMessage);

相关文章