com.alienfactory.javamappy.loader
Class ChunkLoader

java.lang.Object
  extended by com.alienfactory.javamappy.loader.ChunkLoader
Direct Known Subclasses:
ChunkLoaderANDT, ChunkLoaderATHR, ChunkLoaderBGFX, ChunkLoaderBKDT, ChunkLoaderBODY, ChunkLoaderCMAP, ChunkLoaderFORM, ChunkLoaderMPHD, ChunkLoaderOBDT, ChunkLoaderOBFN, ChunkLoaderTSTR, MapLoader.DefaultChunkLoader

public abstract class ChunkLoader
extends java.lang.Object

This is the base class for all ChunkLoaders.

Author:
Steve Eynon

Constructor Summary
ChunkLoader()
           
 
Method Summary
protected  byte getByte(int index)
          Returns the byte at the given index without affecting the 'inputStream'.
 int getBytesRemaining()
          Returns the number of bytes yet to be read for this chunk.
 int getChunkLength()
          Returns the total number of bytes in this chunk.
 java.lang.String getChunkName()
          Returns the 4 character name of the chunk.
protected  boolean isLSB()
          Returns true if shorts and int are stored Least Significant Byte first in the inputStream.
abstract  void loadChunk(Map map)
          The method invoked to load the chunk.
protected  byte readByte()
          Reads the next byte from the input stream.
protected  int readInt()
          Reads the next 4 bytes from the Map input stream and turns them into an int.
protected  short readShort()
          Reads the next 2 bytes from the Map input stream and turns them into a short.
protected  java.lang.String readString()
          Reads characters until it find a terminating zero and returns the string.
protected  java.lang.String readString(int noOfChars)
          Reads the next n bytes from the Map input stream and turns them into a String.
protected  int readUByte()
          Reads the next byte from the input stream and returns it as an unsigned int.
protected  void skip(int noOfBytes)
          Skips the next n bytes from the Map input stream.
protected  void throwChunkException(java.lang.Object objMessage)
          Throws a ChunkLoadException with a formatted message.
 java.lang.String toString()
          Pretty print.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChunkLoader

public ChunkLoader()
Method Detail

getChunkLength

public int getChunkLength()
Returns the total number of bytes in this chunk.


getChunkName

public java.lang.String getChunkName()
Returns the 4 character name of the chunk. E.g. ANDT, BODY.


getBytesRemaining

public int getBytesRemaining()
Returns the number of bytes yet to be read for this chunk.

Returns:
the number of bytes left to read

toString

public java.lang.String toString()
Pretty print.

Overrides:
toString in class java.lang.Object

loadChunk

public abstract void loadChunk(Map map)
                        throws ChunkLoadException
The method invoked to load the chunk. All data loaded should by placed in the given Map.

Throws:
ChunkLoadException - should be thrown should anything be wrong with the data you are loading

isLSB

protected boolean isLSB()
Returns true if shorts and int are stored Least Significant Byte first in the inputStream. I advise using the readShort() or readInt() methods as these take care of LSB effects for you.


getByte

protected byte getByte(int index)
Returns the byte at the given index without affecting the 'inputStream'.


throwChunkException

protected void throwChunkException(java.lang.Object objMessage)
                            throws ChunkLoadException
Throws a ChunkLoadException with a formatted message.

Parameters:
objMessage - the error message
Throws:
ChunkLoadException - always.

readString

protected java.lang.String readString(int noOfChars)
                               throws java.lang.IllegalArgumentException,
                                      ChunkLoadException
Reads the next n bytes from the Map input stream and turns them into a String.

Parameters:
noOfChars - the number of bytes to read and turn into a String
Returns:
a String, read from the Map input stream
Throws:
java.lang.IllegalArgumentException - if intNoOfChars is less than zero
ChunkLoadException - if there are no more bytes left to read in the Chunk

readString

protected java.lang.String readString()
Reads characters until it find a terminating zero and returns the string. Note the zero is consumed.

Returns:
a String, read from the Map input stream

readByte

protected byte readByte()
                 throws ChunkLoadException
Reads the next byte from the input stream.

Returns:
the next byte (signed) from the Map input stream
Throws:
ChunkLoadException - if there are no more bytes left to read in the Chunk

readUByte

protected int readUByte()
                 throws ChunkLoadException
Reads the next byte from the input stream and returns it as an unsigned int.

Returns:
the next byte (unsigned) from the Map input stream
Throws:
ChunkLoadException - if there are no more bytes left to read in the Chunk

readShort

protected short readShort()
                   throws ChunkLoadException
Reads the next 2 bytes from the Map input stream and turns them into a short.

Returns:
the next short from the Map input stream
Throws:
ChunkLoadException - if there are no more bytes left to read in the Chunk

readInt

protected int readInt()
               throws ChunkLoadException
Reads the next 4 bytes from the Map input stream and turns them into an int.

Returns:
the next int from the Map input stream
Throws:
ChunkLoadException - if there are no more bytes left to read in the Chunk

skip

protected void skip(int noOfBytes)
             throws java.lang.IllegalArgumentException,
                    ChunkLoadException
Skips the next n bytes from the Map input stream.

Parameters:
noOfBytes - the number of bytes to skip
Throws:
java.lang.IllegalArgumentException - if lngNoOfBytes is less than zero
ChunkLoadException - if there are no more bytes left to read in the Chunk


Copyright © 2001-2009 Alien-Factory Ltd. All Rights Reserved.