View Javadoc
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  
20  package org.apache.commons.compress.archivers.sevenz;
21  
22  import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
23  import static org.junit.jupiter.api.Assertions.assertTrue;
24  
25  import java.io.InputStream;
26  import java.nio.file.Files;
27  import java.nio.file.Path;
28  import java.nio.file.Paths;
29  import java.util.List;
30  import java.util.concurrent.Callable;
31  import java.util.concurrent.ExecutorService;
32  import java.util.concurrent.Executors;
33  import java.util.concurrent.Future;
34  import java.util.stream.Collectors;
35  import java.util.stream.IntStream;
36  
37  import org.junit.jupiter.api.Test;
38  
39  class Compress679Test {
40  
41      @Test
42      void testCompress679() {
43          final Path origin = Paths.get("src/test/resources/org/apache/commons/compress/COMPRESS-679/file.7z");
44          assertTrue(Files.exists(origin));
45          final Callable<Boolean> runnable = () -> {
46              try (SevenZFile sevenZFile = SevenZFile.builder().setPath(origin).get()) {
47                  SevenZArchiveEntry sevenZArchiveEntry;
48                  while ((sevenZArchiveEntry = sevenZFile.getNextEntry()) != null) {
49                      if ("file4.txt".equals(sevenZArchiveEntry.getName())) { // The entry must not be the first of the ZIP archive to reproduce
50                          final InputStream inputStream = sevenZFile.getInputStream(sevenZArchiveEntry);
51                          // treatments...
52                          break;
53                      }
54                  }
55              }
56              return Boolean.TRUE;
57          };
58          final ExecutorService threadPool = Executors.newFixedThreadPool(10);
59          try {
60              final List<Future<Boolean>> futures = IntStream.range(0, 30).mapToObj(i -> threadPool.submit(runnable)).collect(Collectors.toList());
61              futures.forEach(f -> assertDoesNotThrow(() -> f.get()));
62          } finally {
63              threadPool.shutdownNow();
64          }
65      }
66  }