1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.assembly.io;
20
21 import java.io.File;
22 import java.io.IOException;
23 import java.net.URL;
24 import java.nio.file.Files;
25
26 import org.apache.commons.io.IOUtils;
27
28
29
30
31
32 class URLLocation extends FileLocation {
33
34 private final URL url;
35
36 private final String tempFilePrefix;
37
38 private final String tempFileSuffix;
39
40 private final boolean tempFileDeleteOnExit;
41
42
43
44
45
46
47
48
49 URLLocation(
50 URL url, String specification, String tempFilePrefix, String tempFileSuffix, boolean tempFileDeleteOnExit) {
51 super(specification);
52
53 this.url = url;
54 this.tempFilePrefix = tempFilePrefix;
55 this.tempFileSuffix = tempFileSuffix;
56 this.tempFileDeleteOnExit = tempFileDeleteOnExit;
57 }
58
59 @Override
60 protected void initFile() throws IOException {
61 if (unsafeGetFile() == null) {
62 File tempFile = Files.createTempFile(tempFilePrefix, tempFileSuffix).toFile();
63
64 if (tempFileDeleteOnExit) {
65 tempFile.deleteOnExit();
66 }
67
68 IOUtils.copy(url, tempFile);
69
70 setFile(tempFile);
71 }
72 }
73 }