    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one
    003 * or more contributor license agreements.  See the NOTICE file
    004 * distributed with this work for additional information
    005 * regarding copyright ownership.  The ASF licenses this file
    006 * to you under the Apache License, Version 2.0 (the
    007 * "License"); you may not use this file except in compliance
    008 * with the License.  You may obtain a copy of the License at
    009 *
    010 *   https://www.apache.org/licenses/LICENSE-2.0
    011 *
    012 * Unless required by applicable law or agreed to in writing,
    013 * software distributed under the License is distributed on an
    014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    015 * KIND, either express or implied.  See the License for the
    016 * specific language governing permissions and limitations
    017 * under the License.
    018 */
    019package org.apache.commons.compress.parallel;
    020
    021import java.io.Closeable;
    022import java.io.IOException;
    023import java.io.InputStream;
    024
    025/**
    026 * Store intermediate payload in a scatter-gather scenario. Multiple threads write their payload to a backing store, which can subsequently be reversed to an
    027 * {@link InputStream} to be used as input in the gather phase.
    028 * <p>
    029 * 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
    030 * delete files.
    031 * </p>
    032 *
    033 * @since 1.10
    034 */
    035public interface ScatterGatherBackingStore extends Closeable {
    036
    037    /**
    038     * Closes this backing store for further writing.
    039     *
    040     * @throws IOException if an I/O error occurs.
    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 if an I/O error occurs.
    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 if an I/O error occurs.
    059     */
    060    void writeOut(byte[] data, int offset, int length) throws IOException;
    061}