1 package org.apache.maven.shared.io.location;
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.maven.shared.utils.io.FileUtils;
27
28
29
30
31
32 public 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 public 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
63 protected void initFile()
64 throws IOException
65 {
66
67 if ( unsafeGetFile() == null )
68 {
69 File tempFile = File.createTempFile( tempFilePrefix, tempFileSuffix );
70
71 if ( tempFileDeleteOnExit )
72 {
73 tempFile.deleteOnExit();
74 }
75
76 FileUtils.copyURLToFile( url, tempFile );
77
78 setFile( tempFile );
79 }
80 }
81
82 }