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.archivers.zip; 018 019import java.io.InputStream; 020 021import org.apache.commons.compress.parallel.InputStreamSupplier; 022 023/** 024 * A Thread-safe representation of a ZipArchiveEntry that is used to add entries to parallel archives. 025 * 026 * @since 1.10 027 */ 028public class ZipArchiveEntryRequest { 029 030 /** 031 * Creates a ZipArchiveEntryRequest 032 * @param zipArchiveEntry The entry to use 033 * @param payloadSupplier The payload that will be added to the ZIP entry. 034 * @return The newly created request 035 */ 036 public static ZipArchiveEntryRequest createZipArchiveEntryRequest(final ZipArchiveEntry zipArchiveEntry, final InputStreamSupplier payloadSupplier) { 037 return new ZipArchiveEntryRequest(zipArchiveEntry, payloadSupplier); 038 } 039 040 /** 041 * The ZIPArchiveEntry is not thread safe, and cannot be safely accessed by the getters of this class. It is safely accessible during the construction part 042 * of this class and also after the thread pools have been shut down. 043 */ 044 private final ZipArchiveEntry zipArchiveEntry; 045 private final InputStreamSupplier payloadSupplier; 046 047 048 private final int method; 049 050 private ZipArchiveEntryRequest(final ZipArchiveEntry zipArchiveEntry, final InputStreamSupplier payloadSupplier) { 051 // this constructor has "safe" access to all member variables on zipArchiveEntry 052 this.zipArchiveEntry = zipArchiveEntry; 053 this.payloadSupplier = payloadSupplier; 054 this.method = zipArchiveEntry.getMethod(); 055 } 056 057 /** 058 * Gets the compression method to use 059 * @return The compression method to use 060 */ 061 public int getMethod(){ 062 return method; 063 } 064 065 /** 066 * Gets the payload that will be added to this ZIP entry 067 * @return The input stream. 068 */ 069 public InputStream getPayloadStream() { 070 return payloadSupplier.get(); 071 } 072 073 074 /** 075 * Gets the underlying entry. Do not use this method from threads that did not create the instance itself ! 076 * @return the zipArchiveEntry that is basis for this request 077 */ 078 ZipArchiveEntry getZipArchiveEntry() { 079 return zipArchiveEntry; 080 } 081}