View Javadoc
1   package org.codehaus.plexus.archiver.zip;
2   
3   import javax.annotation.Nonnull;
4   
5   import java.io.File;
6   import java.io.IOException;
7   import java.io.InputStream;
8   import java.net.URL;
9   
10  import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResource;
11  
12  public class AnonymousResource extends AbstractPlexusIoResource {
13  
14      private final File file;
15  
16      public AnonymousResource(File file) {
17          this(file, getName(file));
18      }
19  
20      public AnonymousResource(File file, String name) {
21          super(name, file.lastModified(), file.length(), file.isFile(), file.isDirectory(), file.exists());
22          this.file = file;
23      }
24  
25      @Nonnull
26      @Override
27      public InputStream getContents() throws IOException {
28          throw new UnsupportedOperationException("not supp");
29      }
30  
31      @Override
32      public URL getURL() throws IOException {
33          return file.toURI().toURL();
34      }
35  
36      private static String getName(File file) {
37          return file.getPath().replace('\\', '/');
38      }
39  }