com.simiacryptus.util.Util.cacheLocal()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(3.4k)|赞(0)|评价(0)|浏览(172)

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

Util.cacheLocal介绍

[英]Cache input stream.
[中]缓存输入流。

代码示例

代码示例来源:origin: com.simiacryptus/java-util

/**
 * Cache input stream.
 *
 * @param file the file
 * @param url  the url
 * @return the input stream
 * @throws IOException the io exception
 */
public static InputStream cacheLocal(String file, URI url) throws IOException {
 return cacheLocal(file, getStreamSupplier(url));
}

代码示例来源:origin: com.simiacryptus/char-trie

private static void read() {
  try {
   InputStream in = Util.cacheLocal(file, new URI(url));
   String txt = new String(IOUtils.toByteArray(in), "UTF-8").replaceAll("\r", "");
   for (String paragraph : txt.split("\n\\s*\n")) {
    queue.add(new Shakespeare(paragraph));
   }
  } catch (final IOException e) {
   // Ignore... end of stream
  } catch (final RuntimeException e) {
   if (!(e.getCause() instanceof InterruptedException)) throw e;
  } catch (final Exception e) {
   throw new RuntimeException(e);
  }
 }
}

代码示例来源:origin: com.simiacryptus/char-trie

private static void read() {
  try {
   InputStream in = Util.cacheLocal(file, new URI(url));
   String txt = new String(IOUtils.toByteArray(in), "UTF-8").replaceAll("\r", "");
   List<CharSequence> list = Arrays.stream(txt.split("\n")).map(x -> x.replaceAll("[^\\w]", "")).collect(Collectors.toList());
   Collections.shuffle(list);
   for (CharSequence paragraph : list) {
    queue.add(new EnglishWords(paragraph));
   }
  } catch (final IOException e) {
   // Ignore... end of stream
  } catch (final RuntimeException e) {
   if (!(e.getCause() instanceof InterruptedException)) throw e;
  } catch (final Exception e) {
   throw new RuntimeException(e);
  }
 }
}

代码示例来源:origin: com.simiacryptus/char-trie

private static void read() {
  try {
   InputStream load = Util.cacheLocal(file, new URI(url));
   try (final ZipInputStream in = new ZipInputStream(load)) {
    ZipEntry entry = in.getNextEntry();
    try (final BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
     CharSequence[] header = reader.readLine().split(",");
     String read;
     while (null != (read = reader.readLine())) {
      String[] values = read.split(",");
      queue.add(new TweetSentiment(values[3].trim(), Integer.parseInt(values[1].trim())));
     }
    }
   }
  } catch (final IOException e) {
   // Ignore... end of stream
  } catch (final RuntimeException e) {
   if (!(e.getCause() instanceof InterruptedException)) throw e;
  } catch (final Exception e) {
   throw new RuntimeException(e);
  }
 }
}

代码示例来源:origin: com.simiacryptus/char-trie

private void read() {
 try {
  try (final InputStream in = Util.cacheLocal(file, new URI(url))) {
   String txt = new String(IOUtils.toByteArray(in), "UTF-8").replaceAll("\r", "");
   CharSequence[] list = txt.split("\n");
   String activeItem = "";
   for (CharSequence item : list) {
    if (item.toString().startsWith("$")) {
     activeItem = item.toString().substring(1);
    } else {
     queue.add(new Misspelling(activeItem, item));
    }
   }
  }
 } catch (final RuntimeException e) {
  if (!(e.getCause() instanceof InterruptedException)) e.printStackTrace();
 } catch (final Exception e) {
  e.printStackTrace();
 } finally {
  System.err.println("Read thread exit");
 }
}

代码示例来源:origin: com.simiacryptus/char-trie

@Override
protected void read(List<WikiArticle> queue) {
 try {
  try (final InputStream in = new BZip2CompressorInputStream(Util.cacheLocal(file, new URI(url)), true)) {
   final SAXParserFactory spf = SAXParserFactory.newInstance();
   spf.setNamespaceAware(false);

相关文章