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

com.swak.license.api.io.GenSource Maven / Gradle / Ivy

The newest version!

package com.swak.license.api.io;


import com.swak.license.api.io.function.XConsumer;
import com.swak.license.api.io.function.XFunction;

/**
 * A generic abstraction for safe access to some closeable input resource - DO NOT USE THIS DIRECTLY!
 * This type primarily exists to enforce consistency between {@link Source} and {@link ArchiveSource}.
 *
 * @author Christian Schlichtherle
 */
@FunctionalInterface
public interface GenSource {

    /**
     * Returns an input socket for safe access to some closeable input resource.
     */
    Socket input();

    /**
     * Loans a closeable resource from the {@linkplain #input() input socket} to the given consumer.
     * The loaned resource will be closed upon return from this method.
     */
    default void acceptReader(XConsumer reader) throws Exception {
        input().accept(reader);
    }

    /**
     * Loans a closeable resource from the {@linkplain #input() input socket} to the given function and returns its
     * value.
     * The loaned resource will be closed upon return from this method.
     * It is an error to return the loaned resource from the given function or any other object which holds on to it.
     */
    default  U applyReader(XFunction reader) throws Exception {
        return input().apply(reader);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy