Top Description Fields Constructors Methods
org.apache.catalina.webresources

public final Class JarContents

extends Object
Class Inheritance
Imports
java.util.BitSet, .Enumeration, java.util.jar.JarEntry, .JarFile

This class represents the contents of a jar by determining whether a given resource might be in the cache, based on a bloom filter. This is not a general-purpose bloom filter because it contains logic to strip out characters from the beginning of the key. The hash methods are simple but good enough for this purpose.

Field Summary

Modifier and TypeField and Description
private final BitSet
private final BitSet
private static final int
HASH_PRIME_1

Constant used by a typical hashing method.

private static final int
HASH_PRIME_2

Constant used by a typical hashing method.

private static final int
TABLE_SIZE

Size of the fixed-length bit table.

Constructor Summary

AccessConstructor and Description
public
JarContents(JarFile
the JAR file
jar
)

Parses the passed-in jar and populates the bit array.

Method Summary

Modifier and TypeMethod and Description
private int

Returns:

hashcode of the range.
hashcode
(String
Wrapping String.
content
,
int
First character in the range.
startPos
,
int hashPrime)

Simple hashcode of a portion of the string.

private int
hashcode(String content, int startPos, int endPos, int hashPrime)

public boolean

Returns:

Whether the prefix of the path is known to be in this jar.
mightContainResource
(String
Requested path. Sometimes starts with "/WEB-INF/classes".
path
,
String
The value of the webapp location, which can be stripped from the path. Typically is "/WEB-INF/classes".
webappRoot
)

Method that identifies whether a given path MIGHT be in this jar.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bits1back to summary
private final BitSet bits1
bits2back to summary
private final BitSet bits2
HASH_PRIME_1back to summary
private static final int HASH_PRIME_1

Constant used by a typical hashing method.

HASH_PRIME_2back to summary
private static final int HASH_PRIME_2

Constant used by a typical hashing method.

TABLE_SIZEback to summary
private static final int TABLE_SIZE

Size of the fixed-length bit table. Larger reduces false positives, smaller saves memory.

Constructor Detail

JarContentsback to summary
public JarContents(JarFile jar)

Parses the passed-in jar and populates the bit array.

Parameters
jar:JarFile

the JAR file

Method Detail

hashcodeback to summary
private int hashcode(String content, int startPos, int hashPrime)

Simple hashcode of a portion of the string. Typically we would use substring, but memory and runtime speed are critical.

Parameters
content:String

Wrapping String.

startPos:int

First character in the range.

Returns:int

hashcode of the range.

hashcodeback to summary
private int hashcode(String content, int startPos, int endPos, int hashPrime)
mightContainResourceback to summary
public boolean mightContainResource(String path, String webappRoot)

Method that identifies whether a given path MIGHT be in this jar. Uses the Bloom filter mechanism.

Parameters
path:String

Requested path. Sometimes starts with "/WEB-INF/classes".

webappRoot:String

The value of the webapp location, which can be stripped from the path. Typically is "/WEB-INF/classes".

Returns:boolean

Whether the prefix of the path is known to be in this jar.