Example usage for java.util.function Consumer accept

List of usage examples for java.util.function Consumer accept

Introduction

In this page you can find the example usage for java.util.function Consumer accept.

Prototype

void accept(T t);

Source Link

Document

Performs this operation on the given argument.

Usage

From source file:org.eclipse.packagedrone.utils.rpm.build.PayloadRecorder.java

public Result addFile(final String targetPath, final ByteBuffer data,
        final Consumer<CpioArchiveEntry> customizer) throws IOException {
    final long size = data.remaining();

    final CpioArchiveEntry entry = new CpioArchiveEntry(targetPath);
    entry.setSize(size);/*w w w  .j  a  v a  2  s .c  om*/

    if (customizer != null) {
        customizer.accept(entry);
    }

    this.archiveStream.putArchiveEntry(entry);

    // record digest

    MessageDigest digest;
    try {
        digest = createDigest();
        digest.update(data.slice());
    } catch (final NoSuchAlgorithmException e) {
        throw new IOException(e);
    }

    // write data

    final WritableByteChannel channel = Channels.newChannel(this.archiveStream);
    while (data.hasRemaining()) {
        channel.write(data);
    }

    // close archive entry

    this.archiveStream.closeArchiveEntry();

    return new Result(size, digest.digest());
}

From source file:io.viewserver.adapters.csv.CsvDataAdapter.java

protected int getRecordsFromInputStream(InputStream stream, Consumer<IRecord> consumer) {
    int recordsLoaded = 0;
    try {//from  ww  w .j  av a  2s .com
        UTF8StreamReader reader = new UTF8StreamReader();
        reader.setInput(stream);
        try {
            CSVParser parser = getCsvFormat().parse(reader);

            for (final CSVRecord record : parser) {
                for (int z = 0; z < multiple; z++) {
                    recordWrapper.setRecord(record);
                    consumer.accept(recordWrapper);
                    recordsLoaded++;
                    if (recordsLoaded % 100000 == 0) {
                        log.debug("{} records loaded", recordsLoaded);
                    }
                }
            }
        } finally {
            reader.close();
        }

        log.info(String.format("Loaded %s rows from %s", recordsLoaded, this.fileName));
    } catch (Throwable e) {
        log.error("Failed to load CSV data", e);
    }

    return recordsLoaded;
}

From source file:org.eclipse.packagedrone.utils.rpm.build.PayloadRecorder.java

public Result addFile(final String targetPath, final Path path, final Consumer<CpioArchiveEntry> customizer)
        throws IOException {
    final long size = Files.size(path);

    final CpioArchiveEntry entry = new CpioArchiveEntry(targetPath);
    entry.setSize(size);//  w  w  w . j  a  v  a2s. c  o m

    if (customizer != null) {
        customizer.accept(entry);
    }

    this.archiveStream.putArchiveEntry(entry);

    MessageDigest digest;
    try {
        digest = createDigest();
    } catch (final NoSuchAlgorithmException e) {
        throw new IOException(e);
    }

    try (InputStream in = new BufferedInputStream(Files.newInputStream(path))) {
        ByteStreams.copy(new DigestInputStream(in, digest), this.archiveStream);
    }

    this.archiveStream.closeArchiveEntry();

    return new Result(size, digest.digest());
}

From source file:at.gridtec.lambda4j.function.bi.BiByteFunction.java

/**
 * Returns a composed {@link BiByteConsumer} that fist applies this function to its input, and then consumes the
 * result using the given {@link Consumer}. If evaluation of either operation throws an exception, it is relayed to
 * the caller of the composed operation.
 *
 * @param consumer The operation which consumes the result from this operation
 * @return A composed {@code BiByteConsumer} that first applies this function to its input, and then consumes the
 * result using the given {@code Consumer}.
 * @throws NullPointerException If given argument is {@code null}
 *//*from   ww w .java2s  .  com*/
@Nonnull
default BiByteConsumer consume(@Nonnull final Consumer<? super R> consumer) {
    Objects.requireNonNull(consumer);
    return (value1, value2) -> consumer.accept(apply(value1, value2));
}

From source file:at.gridtec.lambda4j.function.bi.BiCharFunction.java

/**
 * Returns a composed {@link BiCharConsumer} that fist applies this function to its input, and then consumes the
 * result using the given {@link Consumer}. If evaluation of either operation throws an exception, it is relayed to
 * the caller of the composed operation.
 *
 * @param consumer The operation which consumes the result from this operation
 * @return A composed {@code BiCharConsumer} that first applies this function to its input, and then consumes the
 * result using the given {@code Consumer}.
 * @throws NullPointerException If given argument is {@code null}
 */// ww w .j  a v a2s  .  co m
@Nonnull
default BiCharConsumer consume(@Nonnull final Consumer<? super R> consumer) {
    Objects.requireNonNull(consumer);
    return (value1, value2) -> consumer.accept(apply(value1, value2));
}

From source file:at.gridtec.lambda4j.function.bi.BiFloatFunction.java

/**
 * Returns a composed {@link BiFloatConsumer} that fist applies this function to its input, and then consumes the
 * result using the given {@link Consumer}. If evaluation of either operation throws an exception, it is relayed to
 * the caller of the composed operation.
 *
 * @param consumer The operation which consumes the result from this operation
 * @return A composed {@code BiFloatConsumer} that first applies this function to its input, and then consumes the
 * result using the given {@code Consumer}.
 * @throws NullPointerException If given argument is {@code null}
 *///from  ww w  .  j a  v a 2s.c o  m
@Nonnull
default BiFloatConsumer consume(@Nonnull final Consumer<? super R> consumer) {
    Objects.requireNonNull(consumer);
    return (value1, value2) -> consumer.accept(apply(value1, value2));
}

From source file:at.gridtec.lambda4j.function.bi.BiIntFunction.java

/**
 * Returns a composed {@link BiIntConsumer} that fist applies this function to its input, and then consumes the
 * result using the given {@link Consumer}. If evaluation of either operation throws an exception, it is relayed to
 * the caller of the composed operation.
 *
 * @param consumer The operation which consumes the result from this operation
 * @return A composed {@code BiIntConsumer} that first applies this function to its input, and then consumes the
 * result using the given {@code Consumer}.
 * @throws NullPointerException If given argument is {@code null}
 *///  w ww  . j  a v a  2s .c  o m
@Nonnull
default BiIntConsumer consume(@Nonnull final Consumer<? super R> consumer) {
    Objects.requireNonNull(consumer);
    return (value1, value2) -> consumer.accept(apply(value1, value2));
}

From source file:at.gridtec.lambda4j.function.bi.BiShortFunction.java

/**
 * Returns a composed {@link BiShortConsumer} that fist applies this function to its input, and then consumes the
 * result using the given {@link Consumer}. If evaluation of either operation throws an exception, it is relayed to
 * the caller of the composed operation.
 *
 * @param consumer The operation which consumes the result from this operation
 * @return A composed {@code BiShortConsumer} that first applies this function to its input, and then consumes the
 * result using the given {@code Consumer}.
 * @throws NullPointerException If given argument is {@code null}
 *///w w  w.ja  v  a 2  s .c  om
@Nonnull
default BiShortConsumer consume(@Nonnull final Consumer<? super R> consumer) {
    Objects.requireNonNull(consumer);
    return (value1, value2) -> consumer.accept(apply(value1, value2));
}

From source file:at.gridtec.lambda4j.function.bi.BiBooleanFunction.java

/**
 * Returns a composed {@link BiBooleanConsumer} that fist applies this function to its input, and then consumes the
 * result using the given {@link Consumer}. If evaluation of either operation throws an exception, it is relayed to
 * the caller of the composed operation.
 *
 * @param consumer The operation which consumes the result from this operation
 * @return A composed {@code BiBooleanConsumer} that first applies this function to its input, and then consumes the
 * result using the given {@code Consumer}.
 * @throws NullPointerException If given argument is {@code null}
 *//*from   w ww.  ja  v a  2  s .  co  m*/
@Nonnull
default BiBooleanConsumer consume(@Nonnull final Consumer<? super R> consumer) {
    Objects.requireNonNull(consumer);
    return (value1, value2) -> consumer.accept(apply(value1, value2));
}

From source file:at.gridtec.lambda4j.function.bi.BiLongFunction.java

/**
 * Returns a composed {@link BiLongConsumer} that fist applies this function to its input, and then consumes the
 * result using the given {@link Consumer}. If evaluation of either operation throws an exception, it is relayed to
 * the caller of the composed operation.
 *
 * @param consumer The operation which consumes the result from this operation
 * @return A composed {@code BiLongConsumer} that first applies this function to its input, and then consumes the
 * result using the given {@code Consumer}.
 * @throws NullPointerException If given argument is {@code null}
 *///from   ww w  .j a  v a 2 s.  co  m
@Nonnull
default BiLongConsumer consume(@Nonnull final Consumer<? super R> consumer) {
    Objects.requireNonNull(consumer);
    return (value1, value2) -> consumer.accept(apply(value1, value2));
}