View Javadoc
1   package org.codehaus.plexus.components.io.resources;
2   
3   import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes;
4   import org.codehaus.plexus.components.io.functions.ContentSupplier;
5   import org.codehaus.plexus.components.io.functions.InputStreamTransformer;
6   
7   import java.io.File;
8   import java.io.IOException;
9   
10  import static org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributeUtils.getFileAttributes;
11  import static org.codehaus.plexus.components.io.resources.PlexusIoFileResource.getName;
12  
13  /**
14   * @author Kristian Rosenvold
15   */
16  public class ResourceFactory
17  {
18      public static PlexusIoResource createResource( File f )
19          throws IOException
20      {
21          return createResource( f, getName( f ), null, null, getFileAttributes( f ) );
22      }
23  
24      public static PlexusIoResource createResource( File f, String name )
25          throws IOException
26      {
27          return createResource( f, name, null, null, getFileAttributes( f ) );
28      }
29  
30      public static PlexusIoResource createResource( File f, String name, final ContentSupplier contentSupplier,
31                                                     PlexusIoResourceAttributes attributes )
32          throws IOException
33      {
34          return createResource( f, name, contentSupplier, null, attributes );
35      }
36  
37      public static PlexusIoResource createResource( File f, InputStreamTransformer inputStreamTransformer )
38          throws IOException
39      {
40          return createResource( f, getName( f ), null, inputStreamTransformer, getFileAttributes( f ) );
41      }
42  
43      public static PlexusIoResource createResource( File f, String name, final ContentSupplier contentSupplier,
44                                                     InputStreamTransformer inputStreamTransformer )
45          throws IOException
46      {
47          return createResource( f, name, contentSupplier, inputStreamTransformer, getFileAttributes( f ) );
48      }
49  
50      public static PlexusIoResource createResource( File f, String name, final ContentSupplier contentSupplier,
51                                                     InputStreamTransformer inputStreamTransformer,
52                                                     PlexusIoResourceAttributes attributes )
53          throws IOException
54      {
55          boolean symbolicLink = attributes.isSymbolicLink();
56          return symbolicLink ? new PlexusIoSymlinkResource( f, name, attributes )
57              :  new PlexusIoFileResource(f, name, attributes, contentSupplier, inputStreamTransformer);
58      }
59  
60  }