@Override public void send(final ByteBuffer buffer) throws Exception { Try.of(Channels.newChannel(rsp.getOutputStream())) .run(channel -> channel.write(buffer)) .onSuccess(() -> committed = true); }
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("")); } }
private static void copy(final InputStream in, final OutputStream out) { Try.of(in, out) .run(ByteStreams::copy) .throwException(); }
@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(); } } }
@Override public void send(final ByteBuffer buffer) throws Exception { Try.of(Channels.newChannel(rsp.getOutputStream())) .run(channel -> channel.write(buffer)) .onSuccess(() -> committed = true); }
private static void copy(final InputStream in, final OutputStream out) { Try.of(in, out) .run(ByteStreams::copy) .throwException(); }