    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>Store intermediate payload in a scatter-gather scenario.
    025 * Multiple threads write their payload to a backing store, which can
    026 * subsequently be reversed to an {@link InputStream} to be used as input in the
    027 * gather phase.</p>
    028 *
    029 * <p>It is the responsibility of the allocator of an instance of this class
    030 * to close this. Closing it should clear off any allocated structures
    031 * and preferably delete files.</p>
    032 *
    033 * @since 1.10
    034 */
    035public interface ScatterGatherBackingStore extends Closeable {
    036
    037    /**
    038     * Closes this backing store for further writing.
    039     * @throws IOException when something fails
    040     */
    041    void closeForWriting() throws IOException;
    042
    043    /**
    044     * An input stream that contains the scattered payload
    045     *
    046     * @return An InputStream, should be closed by the caller of this method.
    047     * @throws IOException when something fails
    048     */
    049    InputStream getInputStream() throws IOException;
    050
    051    /**
    052     * Writes a piece of payload.
    053     *
    054     * @param data the data to write
    055     * @param offset offset inside data to start writing from
    056     * @param length the amount of data to write
    057     * @throws IOException when something fails
    058     */
    059    void writeOut(byte[] data, int offset, int length) throws IOException;
    060}