1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codehaus.plexus.archiver.resources;
17
18 import javax.annotation.Nonnull;
19
20 import java.io.File;
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.net.URL;
24
25 import org.codehaus.plexus.components.io.attributes.AttributeUtils;
26 import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes;
27 import org.codehaus.plexus.components.io.functions.ResourceAttributeSupplier;
28 import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResource;
29
30
31
32
33 public class PlexusIoVirtualFileResource extends AbstractPlexusIoResource implements ResourceAttributeSupplier {
34
35 private final File file;
36
37 protected PlexusIoVirtualFileResource(File file, String name) {
38 super(name, file.lastModified(), file.length(), file.isFile(), file.isDirectory(), file.exists());
39 this.file = file;
40 }
41
42 protected static String getName(File file) {
43 return file.getPath().replace('\\', '/');
44 }
45
46
47
48
49 public File getFile() {
50 return file;
51 }
52
53 @Nonnull
54 @Override
55 public InputStream getContents() throws IOException {
56 throw new UnsupportedOperationException("We're not really sure we can do this");
57 }
58
59 @Override
60 public URL getURL() throws IOException {
61 return getFile().toURI().toURL();
62 }
63
64 @Override
65 public long getSize() {
66 return getFile().length();
67 }
68
69 @Override
70 public boolean isDirectory() {
71 return getFile().isDirectory();
72 }
73
74 @Override
75 public boolean isExisting() {
76 return getFile().exists();
77 }
78
79 @Override
80 public boolean isFile() {
81 return getFile().isFile();
82 }
83
84 @Override
85 public PlexusIoResourceAttributes getAttributes() {
86 return null;
87 }
88
89 @Override
90 public long getLastModified() {
91 if (file.exists()) {
92 return AttributeUtils.getLastModified(getFile());
93 } else {
94 return System.currentTimeMillis();
95 }
96 }
97
98 @Override
99 public boolean isSymbolicLink() {
100 return getAttributes().isSymbolicLink();
101 }
102 }