use of org.cactoos.io.BytesOf in project cactoos-http by yegor256.
the class HtWire method send.
@Override
public Input send(final Input input) throws IOException {
try (final Socket socket = new Socket(this.address, this.port);
final InputStream source = input.stream();
final InputStream ins = socket.getInputStream();
final OutputStream ous = socket.getOutputStream()) {
final byte[] buf = new byte[HtWire.LENGTH];
while (true) {
final int len = source.read(buf);
if (len < 0) {
break;
}
ous.write(buf, 0, len);
}
return new InputOf(new BytesOf(ins).asBytes());
}
}
use of org.cactoos.io.BytesOf in project wring by yegor256.
the class Cycle method exec.
@Override
public void exec(final Pipe pipe) throws Exception {
final XePrint print = new XePrint(pipe.asXembly());
final Events events = this.base.user(print.text("{/pipe/urn/text()}")).events();
final String json = print.text("{/pipe/json/text()}");
new UncheckedFunc<>(new FuncWithFallback<String, JsonObject>(str -> Json.createReader(new ReaderOf(str)).readObject(), new FuncOf<>(error -> events.post(Cycle.class.getCanonicalName(), String.format("Failed to parse JSON:\n%s\n\n%s", json, new TextOf(new BytesOf(error)).asString()))), obj -> {
if (obj != null) {
new Exec(new JsonAgent(this.base, obj), new IgnoreEvents(new BoostEvents(events, obj), obj), pipe).run();
}
return obj;
})).apply(json);
}
Aggregations