Package org.codehaus.commons.compiler.util.resource

# Class MapResourceFinder

java.lang.Object
org.codehaus.commons.compiler.util.resource.ResourceFinder
org.codehaus.commons.compiler.util.resource.ListableResourceFinder
org.codehaus.commons.compiler.util.resource.MapResourceFinder

public class MapResourceFinder extends ListableResourceFinder
A `ResourceFinder` that provides access to resource stored as byte arrays in a `Map`.

## Field Summary

### Fields inherited from class org.codehaus.commons.compiler.util.resource.ResourceFinder

`EMPTY_RESOURCE_FINDER`

## Constructor Summary

Constructors
Constructor
Description
`MapResourceFinder()`
`MapResourceFinder(Map<String,byte[]> map)`

## Method Summary

Modifier and Type
Method
Description
`Resource`
`addResource(String fileName, byte[] data)`
Adds another `Resource`, so that it can later be found with `findResource(String)`, `ResourceFinder.findResourceAsStream(String)` and `resources()`.
`Resource`
`addResource(String fileName, String data)`
`Resource`
`addResource(Resource resource)`
Adds another `Resource`, so that it can later be found with `findResource(String)`, `ResourceFinder.findResourceAsStream(String)` and `resources()`.
`final Resource`
`findResource(String resourceName)`
Finds a resource by name and return it as a `Resource` object.
`Iterable<Resource>`
`list(String resourceNamePrefix, boolean recurse)`
Returns all resources who's names start with a given string.
`Collection<Resource>`
`resources()`
`final void`
`setLastModified(long lastModified)`

### Methods inherited from class org.codehaus.commons.compiler.util.resource.ResourceFinder

`findResourceAsStream`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### MapResourceFinder

public MapResourceFinder()

### MapResourceFinder

public MapResourceFinder(Map<String,byte[]> map)

## Method Details

### addResource

@Nullable public Resource addResource(String fileName, byte[] data)
Adds another `Resource`, so that it can later be found with `findResource(String)`, `ResourceFinder.findResourceAsStream(String)` and `resources()`.

Returns:
  The resource that was previously associated with the fileName, or `null`

### addResource

@Nullable public Resource addResource(String fileName, String data)

Parameters:
  `data` - The text to store (in platform default encoding)
Returns:
  The resource that was previously associated with the fileName, or `null`

### addResource

public Resource addResource(Resource resource)
Adds another `Resource`, so that it can later be found with `findResource(String)`, `ResourceFinder.findResourceAsStream(String)` and `resources()`.

Returns:
  The resource that was previously associated with the fileName, or `null`

### resources

public Collection<Resource> resources()

Returns:
  All resources that were previously added with `addResource(Resource)`

### setLastModified

public final void setLastModified(long lastModified)

Parameters:
  `lastModified` - The return value of `Resource.lastModified()` for the next resources added

### findResource

@Nullable public final Resource findResource(String resourceName)
Description copied from class: `ResourceFinder`
Finds a resource by name and return it as a `Resource` object.

Specified by:
  `findResource` in class `ResourceFinder`
Parameters:
  `resourceName` - Designates the resource; typically structured by slashes ("/") like "`com/foo/pkg/Bar.class`"
Returns:
  `null` if the resource could not be found

### list

@Nullable public Iterable<Resource> list(String resourceNamePrefix, boolean recurse)
Description copied from class: `ListableResourceFinder`
Returns all resources who's names start with a given string. Only resources with a content are included, no "special entries" of any kind, e.g. directories.

If the prefix string ends with "/", you will get a proper directory listing (recurse`=false`) or directory tree (recurse`=true`). Example:

       resourceFinder.list("dir/", true) =>
         dir/
         dir/afile
         dir/bfile
         dir/adir/
         dir/adir/file
         dir/bdir/
         dir/bdir/file

Otherwise, you will get a strange subset of a directory listing, resp. directory tree, as follows:

       resourceFinder.list("dir/a", true) =>
         dir/afile
         dir/adir/
         dir/adir/file

Specified by:
  `list` in class `ListableResourceFinder`
Parameters:
  `resourceNamePrefix` - E.g. `""` or `"java/lang/"`
Returns:
  All resources who's name starts with the given prefix; `null` iff a location designated by the resourceNamePrefix does not exist