try
{
// load the map header
chkMapHeader = createChunkLoader(inputStream);
if (!chkMapHeader.getChunkName().equals("FORM"))
throw new JavaMappyException("Map does not start with chunk [FORM] :: Chunk ID = [" + chkMapHeader.getChunkName() + "]");
// find out how many bytes are contained in the map data
chkMapHeader.loadChunk(null);
lngBytesToRead = chkMapHeader.getChunkLength() - 4;
// read chunks while there's still chunks to read
while (lngBytesToRead > 0)
{
ChunkLoader chunkLoader;
// find and create the next chunk loader
chunkLoader = createChunkLoader(inputStream);
// load the chunk
chunkLoader.loadChunk(map);
// check that all the data was loaded
if (chunkLoader.getBytesRemaining() > 0)
{
log.warn("Chunk [" + chunkLoader.getChunkName() + "] still has [" + chunkLoader.getBytesRemaining() + "] bytes remaining, skipping...");
}
// the countdown continues
lngBytesToRead -= 8; // for the chunk header
lngBytesToRead -= chunkLoader.getChunkLength();
}
}
catch (JavaMappyException jme)
{
// let map exceptions trickle through
throw jme;
}
catch (Exception e)
{
throw new JavaMappyException("Could not load map", e);
}
log.trace("loadMap() - Done.");
return map;