p2ps.imp.discovery.cache
Class CacheFile
java.lang.Object
p2ps.imp.discovery.cache.CacheFile
- public class CacheFile
- extends java.lang.Object
A wrapper for a cache file containing sequentially stored byte arrays. When
a byte array is deleted, the index of that byte array is added to a deleted
list corresponding to its size. When a byte array is added, the index of
a slot large enough for that byte array is retrieved from the relevant deleted
list. If no suitable slot exists then the cache file is expanded.
- Version:
- $Revision: 295 $
- Author:
- Ian Wang
|
Constructor Summary |
CacheFile(java.io.File file)
|
CacheFile(java.io.File file,
int maxsize,
int blocksize)
|
CacheFile(java.io.File file,
int maxsize,
int blocksize,
int tolerance)
|
|
Method Summary |
int |
add(byte[] bytes)
Adds a byte array to the cache file. |
void |
close()
Close the cach file |
byte[] |
get(int id)
|
int |
getBlockSize()
|
static void |
main(java.lang.String[] args)
|
byte[] |
remove(int id)
Removes the byte[] with the specified id |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DEFAULT_FILE_BLOCK_SIZE
public static final int DEFAULT_FILE_BLOCK_SIZE
- See Also:
- Constant Field Values
DEFAULT_FILE_BLOCK_TOLERANCE
public static final int DEFAULT_FILE_BLOCK_TOLERANCE
- See Also:
- Constant Field Values
DEFAULT_MAXIMUM_ITEM_SIZE
public static final int DEFAULT_MAXIMUM_ITEM_SIZE
- See Also:
- Constant Field Values
CacheFile
public CacheFile(java.io.File file)
throws java.io.FileNotFoundException,
java.io.IOException
CacheFile
public CacheFile(java.io.File file,
int maxsize,
int blocksize)
throws java.io.FileNotFoundException,
java.io.IOException
CacheFile
public CacheFile(java.io.File file,
int maxsize,
int blocksize,
int tolerance)
throws java.io.FileNotFoundException,
java.io.IOException
getBlockSize
public int getBlockSize()
- Returns:
- the file block size
add
public int add(byte[] bytes)
throws java.io.IOException
- Adds a byte array to the cache file.
- Returns:
- the id for the byte[]
- Throws:
java.io.IOException
remove
public byte[] remove(int id)
- Removes the byte[] with the specified id
get
public byte[] get(int id)
- Returns:
- the byte[] with the specified id or null if invalid id
close
public void close()
- Close the cach file
main
public static void main(java.lang.String[] args)
throws java.io.IOException
- Throws:
java.io.IOException