private static void copy(final InputStream in, final OutputStream out) { Try.of(in, out) .run(ByteStreams::copy) .throwException(); }
private static <T> T newObject(final Class<T> klass) { return throwingSupplier(klass::newInstance).get(); }
private Throwing.Runnable sync(final Throwing.Runnable task) { return () -> { synchronized (this) { task.run(); } }; }
/** * Execute the given nodejs callback and automatically releaseNow v8 and nodejs resources. * * @param basedir Base dir where to deploy a library. * @param callback Nodejs callback. */ public static void run(final File basedir, final Throwing.Consumer<Nodejs> callback) { Nodejs node = new Nodejs(basedir); Try.run(() -> callback.accept(node)) .onComplete(node::release) .throwException(); } }
/** * Decode a path by delegating to {@link URLDecoder#decode(String, String)}. * * @param path Path to decoded. * @return Decode a path by delegating to {@link URLDecoder#decode(String, String)}. */ static String decode(String path) { return Try.apply(() -> URLDecoder.decode(path, "UTF-8")).get(); }
@Override public Object map(final T value) throws Throwable { return fn.apply(value); }
private static WriteConcern writeConcern(final String value) { return when(value.toUpperCase()) .is("W1", WriteConcern.W1) .is("W2", WriteConcern.W2) .is("W3", WriteConcern.W3) .is("ACKNOWLEDGED", WriteConcern.ACKNOWLEDGED) .is("MAJORITY", WriteConcern.MAJORITY) .orElseThrow(() -> new IllegalArgumentException("writeConcern: " + value)); }
static Class loadType(final ClassLoader loader, final String name) { return when(name) .<Class>is("boolean", boolean.class) .is("char", char.class) .is("byte", byte.class) .is("short", short.class) .is("int", int.class) .is("long", long.class) .is("float", float.class) .is("double", double.class) .orElseGet(() -> loader.loadClass(name.replace("/", "."))); }
public MappedHandler(final Throwing.Function2<Request, Response, Object> supplier, final Route.Mapper mapper) { this((req, rsp, chain) -> supplier.apply(req, rsp), mapper); }
@Override public Scheduler getComputationScheduler() { return schedulers.apply("computation"); }
@Override public Scheduler getNewThreadScheduler() { return schedulers.apply("newThread"); }
@Override public Scheduler getIOScheduler() { return schedulers.apply("io"); }