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

global.namespace.archive.io.api.ArchiveFileSource Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) 2013-2018 Schlichtherle IT Services.
 * All rights reserved. Use is subject to license terms.
 */
package global.namespace.archive.io.api;

import global.namespace.fun.io.api.Socket;
import global.namespace.fun.io.api.function.XConsumer;
import global.namespace.fun.io.api.function.XFunction;

/**
 * An abstraction for safe reading of archive entries from an archive file without leaking resources.
 * An archive file source provides a {@linkplain #input() socket} for safe access to an {@link ArchiveFileInput}.
 *
 * @author Christian Schlichtherle
 */
public interface ArchiveFileSource {

    /** Returns the underlying archive file input socket for reading the archive entries. */
    Socket> input();

    /**
     * Loans an archive file input from the underlying {@linkplain #input() socket} to the given consumer.
     * The archive file input will be closed upon return from this method.
     */
    default void acceptReader(XConsumer> reader) throws Exception { input().accept(reader); }

    /**
     * Loans an archive file input from the underlying {@linkplain #input() socket} to the given function
     * and returns its value.
     * The archive file input will be closed upon return from this method.
     * 

* It is an error to return the loaned archive file input from the given function or any other object which holds * on to it. */ default U applyReader(XFunction, ? extends U> reader) throws Exception { return input().apply(reader); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy