org.jooby.funzy.Try.of()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(2.4k)|赞(0)|评价(0)|浏览(298)

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

Try.of介绍

[英]Functional try-with-resources:

  1. InputStream in = ...;

Jdbc example:

  1. Connection connection = ...;)
  2. .get();
  3. }

[中]使用资源进行功能性尝试:

  1. InputStream in = ...;

Jdbc示例:

  1. Connection connection = ...;)
  2. .get();
  3. }

代码示例

代码示例来源:origin: jooby-project/jooby

  1. @Override
  2. public void send(final ByteBuffer buffer) throws Exception {
  3. Try.of(Channels.newChannel(rsp.getOutputStream()))
  4. .run(channel -> channel.write(buffer))
  5. .onSuccess(() -> committed = true);
  6. }

代码示例来源:origin: jooby-project/jooby

  1. private void onSyncPackageJson(Config conf, Path workDirectory, Throwing.Consumer<String> action)
  2. throws IOException {
  3. Path tmp = Paths.get(conf.getString("application.tmpdir"), "package.json");
  4. Files.createDirectories(tmp);
  5. String sha1 = Hashing.sha256()
  6. .hashBytes(Files.readAllBytes(workDirectory.resolve("package.json")))
  7. .toString();
  8. Path lastSha1 = tmp.resolve(sha1);
  9. if (!Files.exists(lastSha1) || !Files.exists(workDirectory.resolve("node_modules"))) {
  10. action.accept("install");
  11. Try.of(Files.walk(tmp))
  12. .run(files -> files.filter(f -> !f.equals(tmp)).forEach(throwingConsumer(Files::deleteIfExists)));
  13. Files.write(tmp.resolve(lastSha1), Arrays.asList(""));
  14. }
  15. }

代码示例来源:origin: jooby-project/jooby

  1. private static void copy(final InputStream in, final OutputStream out) {
  2. Try.of(in, out)
  3. .run(ByteStreams::copy)
  4. .throwException();
  5. }

代码示例来源:origin: jooby-project/jooby

  1. @Override
  2. public void handle(final Request req, final Response rsp, final Optional<Throwable> cause) {
  3. if (handle.isClosed()) {
  4. logger.warn("closed handle: {}", handle);
  5. } else {
  6. logger.debug("closing handling: {}", handle);
  7. Try.of(handle)
  8. .run(h -> {
  9. if (h.isInTransaction()) {
  10. if (cause.isPresent()) {
  11. logger.debug("rollback transaction: {}", handle, cause.get());
  12. h.rollback();
  13. } else {
  14. logger.debug("commit transaction {}", handle);
  15. h.commit();
  16. }
  17. }
  18. }).throwException();
  19. }
  20. }
  21. }

代码示例来源:origin: org.jooby/jooby-servlet

  1. @Override
  2. public void send(final ByteBuffer buffer) throws Exception {
  3. Try.of(Channels.newChannel(rsp.getOutputStream()))
  4. .run(channel -> channel.write(buffer))
  5. .onSuccess(() -> committed = true);
  6. }

代码示例来源:origin: org.jooby/jooby

  1. private static void copy(final InputStream in, final OutputStream out) {
  2. Try.of(in, out)
  3. .run(ByteStreams::copy)
  4. .throwException();
  5. }

相关文章