本文整理了Java中org.jooby.funzy.Try.of()
方法的一些代码示例,展示了Try.of()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Try.of()
方法的具体详情如下:
包路径:org.jooby.funzy.Try
类名称: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();
}
内容来源于网络,如有侵权,请联系作者删除!