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