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

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

本文整理了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:

InputStream in = ...;

Jdbc example:

Connection connection = ...;) 
.get(); 
}

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

InputStream in = ...;

Jdbc示例:

Connection connection = ...;) 
.get(); 
}

代码示例

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

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

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

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

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

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

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

@Override
 public void handle(final Request req, final Response rsp, final Optional<Throwable> cause) {
  if (handle.isClosed()) {
   logger.warn("closed handle: {}", handle);
  } else {
   logger.debug("closing handling: {}", handle);
   Try.of(handle)
     .run(h -> {
      if (h.isInTransaction()) {
       if (cause.isPresent()) {
        logger.debug("rollback transaction: {}", handle, cause.get());
        h.rollback();
       } else {
        logger.debug("commit transaction {}", handle);
        h.commit();
       }
      }
     }).throwException();
  }
 }
}

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

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

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

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

相关文章