All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.permazen.util.Streams Maven / Gradle / Ivy

There is a newer version: 5.1.0
Show newest version

/*
 * Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
 */

package io.permazen.util;

import com.google.common.base.Preconditions;

import java.util.stream.Stream;

/**
 * {@link Stream} utility methods.
 */
public final class Streams {

    private Streams() {
    }

    /**
     * Read and discard everything from the given {@link Stream}.
     *
     * 

* This method also ensures that the stream is always closed, even if an exception is thrown. * * @param stream stream to exhaust * @throws IllegalArgumentException if {@code stream} is null */ public static void exhaust(Stream stream) { Preconditions.checkArgument(stream != null, "null stream"); try (Stream stream2 = stream) { stream2.iterator().forEachRemaining(s -> { }); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy