1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * https://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.commons.compress.archivers.zip; 20 21 import java.io.InputStream; 22 23 import org.apache.commons.compress.parallel.InputStreamSupplier; 24 25 /** 26 * A Thread-safe representation of a ZipArchiveEntry that is used to add entries to parallel archives. 27 * 28 * @since 1.10 29 */ 30 public class ZipArchiveEntryRequest { 31 32 /** 33 * Creates a ZipArchiveEntryRequest 34 * 35 * @param zipArchiveEntry The entry to use 36 * @param payloadSupplier The payload that will be added to the ZIP entry. 37 * @return The newly created request 38 */ 39 public static ZipArchiveEntryRequest createZipArchiveEntryRequest(final ZipArchiveEntry zipArchiveEntry, final InputStreamSupplier payloadSupplier) { 40 return new ZipArchiveEntryRequest(zipArchiveEntry, payloadSupplier); 41 } 42 43 /** 44 * 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 45 * of this class and also after the thread pools have been shut down. 46 */ 47 private final ZipArchiveEntry zipArchiveEntry; 48 private final InputStreamSupplier payloadSupplier; 49 50 private final int method; 51 52 private ZipArchiveEntryRequest(final ZipArchiveEntry zipArchiveEntry, final InputStreamSupplier payloadSupplier) { 53 // this constructor has "safe" access to all member variables on zipArchiveEntry 54 this.zipArchiveEntry = zipArchiveEntry; 55 this.payloadSupplier = payloadSupplier; 56 this.method = zipArchiveEntry.getMethod(); 57 } 58 59 /** 60 * Gets the compression method to use 61 * 62 * @return The compression method to use 63 */ 64 public int getMethod() { 65 return method; 66 } 67 68 /** 69 * Gets the payload that will be added to this ZIP entry 70 * 71 * @return The input stream. 72 */ 73 public InputStream getPayloadStream() { 74 return payloadSupplier.get(); 75 } 76 77 /** 78 * Gets the underlying entry. Do not use this method from threads that did not create the instance itself ! 79 * 80 * @return the zipArchiveEntry that is basis for this request 81 */ 82 ZipArchiveEntry getZipArchiveEntry() { 83 return zipArchiveEntry; 84 } 85 }