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