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