Top Description Fields Constructors Methods
org.codehaus.commons.compiler.util.resource

public Class MapResourceFinder

extends ListableResourceFinder
Class Inheritance
Imports
java.io.ByteArrayInputStream, .InputStream, java.util.Collection, .Collections, .HashMap, .Map, .Map.Entry, org.codehaus.commons.compiler.util.Predicate, org.codehaus.commons.compiler.util.iterator.Iterables, org.codehaus.commons.nullanalysis.Nullable

A org.codehaus.commons.compiler.util.resource.ResourceFinder that provides access to resource stored as byte arrays in a java.util.Map.

Field Summary

Modifier and TypeField and Description
private long
private final Map<String, Resource>

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public Resource

Returns:

The resource that was previously associated with the fileName, or null
addResource
(final String fileName, final byte[] data)

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

public Resource

Returns:

The resource that was previously associated with the fileName, or null
addResource
(String fileName, String
The text to store (in platform default encoding)
data
)

public Resource

Returns:

The resource that was previously associated with the fileName, or null
addResource
(final Resource resource)

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

public final Resource
findResource(final String
Designates the resource; typically structured by slashes ("/") like "com/foo/pkg/Bar.class"
resourceName
)

Implements abstract org.codehaus.commons.compiler.util.resource.ResourceFinder.findResource.

Finds a resource by name and return it as a Resource object.
public Iterable<Resource>
list(final String
E.g. "" or "java/lang/"
resourceNamePrefix
,
final boolean recurse)

Implements abstract org.codehaus.commons.compiler.util.resource.ListableResourceFinder.list.

Returns all resources who's names start with a given string.
public Collection<Resource>

Returns:

All resources that were previously added with addResource(Resource)
resources
()

public final void
setLastModified(long
The return value of Resource#lastModified() for the next resources added
lastModified
)

Field Detail

lastModifiedback to summary
private long lastModified
mapback to summary
private final Map<String, Resource> map

Constructor Detail

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

Method Detail

addResourceback to summary
public Resource addResource(final String fileName, final byte[] data)

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

Returns:Resource

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

Annotations
@Nullable
addResourceback to summary
public Resource addResource(String fileName, String data)
Parameters
data:String

The text to store (in platform default encoding)

Returns:Resource

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

Annotations
@Nullable
addResourceback to summary
public Resource addResource(final Resource resource)

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

Returns:Resource

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

findResourceback to summary
public final Resource findResource(final String resourceName)

Implements abstract org.codehaus.commons.compiler.util.resource.ResourceFinder.findResource.

Doc from org.codehaus.commons.compiler.util.resource.ResourceFinder.findResource.

Finds a resource by name and return it as a Resource object.

Parameters
resourceName:String

Designates the resource; typically structured by slashes ("/") like "com/foo/pkg/Bar.class"

Returns:Resource

null if the resource could not be found

Annotations
@Override
@Nullable
listback to summary
public Iterable<Resource> list(final String resourceNamePrefix, final boolean recurse)

Implements abstract org.codehaus.commons.compiler.util.resource.ListableResourceFinder.list.

Doc from org.codehaus.commons.compiler.util.resource.ListableResourceFinder.list.

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
Parameters
resourceNamePrefix:String

E.g. "" or "java/lang/"

Returns:Iterable<Resource>

All resources who's name starts with the given prefix; null iff a location designated by the resourceNamePrefix does not exist

Annotations
@Override
@Nullable
resourcesback to summary
public Collection<Resource> resources()
Returns:Collection<Resource>

All resources that were previously added with addResource(Resource)

setLastModifiedback to summary
public final void setLastModified(long lastModified)
Parameters
lastModified:long

The return value of Resource#lastModified() for the next resources added