if ( ! file.exists())
file.mkdirs();
baseDirectory=file;
useMemoryMapped = useMapped;
File allocatorFile=new File( file, "overhead");
overhead=new DiskAllocator( allocatorFile, INITIAL_REGION_SIZE,
FAVORED_CHUNK_SIZE, 204800, useMemoryMapped ? DiskAllocator.USE_MEMORY_MAPPED : 0);
overheadStreams=new StreamPair( overhead,
factory.getCustomizer( EntryPage.class));
rootModified=false;
offsets=new byte[INITIAL_REGION_SIZE];
if ( overhead.isNewFile())
{
classList=new ClassList();
entryList=new EntryPageList();
rootObject=null;
entryOffset=overheadStreams.writeObject( entryList, 0);
classOffset=overheadStreams.writeObject( classList, 0);
rootOffset=0;
}
else
{
int offset=overhead.getInitialRegion();
byte[] offsetBuffer=overhead.read( offset, INITIAL_REGION_SIZE);
int version=NetByte.quadToInt( offsetBuffer, 0);
if ( version!=DIR_ALLOC_VERSION)
{
throw new ObjectStoreException( "Mismatched version:" + version);
}
entryOffset=NetByte.quadToInt( offsetBuffer, 4);
classOffset=NetByte.quadToInt( offsetBuffer, 8);
rootOffset=NetByte.quadToInt( offsetBuffer, 12);
entryList=(EntryPageList)overheadStreams.readObject(
entryOffset);
entryList.initialize( overheadStreams);
classList=(ClassList)overheadStreams.readObject( classOffset);
if ( rootOffset!=0)
rootObject=(Serializable)overheadStreams.
readObject( rootOffset);
}
// Traverse class list; create class and index maps and stream
// pairs
classList.factory=factory;
classList.classMap=new HashMap();
classList.classChangeLock=new Semaphore();
classList.indexMap=new HashMap();
indexPageFlushLock=new Semaphore();
for ( Iterator i=classList.classEntries.iterator(); i.hasNext();)
{
ClassEntry entry=(ClassEntry)i.next();
classList.classMap.put( Class.forName( entry.className),
entry);
DiskAllocator allocator=createDiskAllocator(entry.fileName,128,DiskAllocator.FORCE_EXIST);
ObjectStreamCustomizer customizer=factory.getCustomizer(
Class.forName( entry.className));
entry.objectStreams=new StreamPair( allocator,
customizer);
if ( entry.indices.size()>0)