001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one or more
003 *  contributor license agreements.  See the NOTICE file distributed with
004 *  this work for additional information regarding copyright ownership.
005 *  The ASF licenses this file to You under the Apache License, Version 2.0
006 *  (the "License"); you may not use this file except in compliance with
007 *  the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 *  Unless required by applicable law or agreed to in writing, software
012 *  distributed under the License is distributed on an "AS IS" BASIS,
013 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 *  See the License for the specific language governing permissions and
015 *  limitations under the License.
016 */
017package org.apache.commons.compress.parallel;
018
019import java.io.Closeable;
020import java.io.IOException;
021import java.io.InputStream;
022
023/**
024 * <p>
025 * Store intermediate payload in a scatter-gather scenario. Multiple threads write their payload to a backing store, which can subsequently be reversed to an
026 * {@link InputStream} to be used as input in the gather phase.
027 * </p>
028 *
029 * <p>
030 * It is the responsibility of the allocator of an instance of this class to close this. Closing it should clear off any allocated structures and preferably
031 * delete files.
032 * </p>
033 *
034 * @since 1.10
035 */
036public interface ScatterGatherBackingStore extends Closeable {
037
038    /**
039     * Closes this backing store for further writing.
040     *
041     * @throws IOException when something fails
042     */
043    void closeForWriting() throws IOException;
044
045    /**
046     * An input stream that contains the scattered payload
047     *
048     * @return An InputStream, should be closed by the caller of this method.
049     * @throws IOException when something fails
050     */
051    InputStream getInputStream() throws IOException;
052
053    /**
054     * Writes a piece of payload.
055     *
056     * @param data   the data to write
057     * @param offset offset inside data to start writing from
058     * @param length the amount of data to write
059     * @throws IOException when something fails
060     */
061    void writeOut(byte[] data, int offset, int length) throws IOException;
062}