1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.commons.compress.compressors.pack200;
21
22 import java.io.FilterInputStream;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.nio.file.Files;
26 import java.nio.file.Path;
27
28
29
30
31
32
33 final class TempFileCachingStreamBridge extends AbstractStreamBridge {
34
35 private final Path path;
36
37 TempFileCachingStreamBridge() throws IOException {
38 this.path = Files.createTempFile("commons-compress", "packtemp");
39 this.path.toFile().deleteOnExit();
40 this.out = Files.newOutputStream(path);
41 }
42
43 @SuppressWarnings("resource")
44 @Override
45 InputStream createInputStream() throws IOException {
46 out.close();
47 return new FilterInputStream(Files.newInputStream(path)) {
48 @Override
49 public void close() throws IOException {
50 try {
51 super.close();
52 } finally {
53 try {
54 Files.deleteIfExists(path);
55 } catch (final IOException ignored) {
56
57 }
58 }
59 }
60 };
61 }
62 }