GTGE API

com.golden.gamedev.engine
Class BaseIO

java.lang.Object
  extended by com.golden.gamedev.engine.BaseIO

public class BaseIO
extends Object

Class to get external resources object, such as java.io.File, java.io.InputStream, and java.net.URL.

There are four types mode of how BaseIO getting the external resources object :

By default BaseIO class is using CLASS_URL.


Field Summary
static int CLASS_LOADER
          IO mode constant for class loader.
static int CLASS_URL
          IO mode constant for class url.
static int SYSTEM_LOADER
          IO mode constant for system loader.
static int WORKING_DIRECTORY
          IO mode constant for working directory.
 
Constructor Summary
BaseIO(Class base)
          Construct new BaseIO with specified class as the base loader using CLASS_URL mode as the default.
BaseIO(Class base, int mode)
          Construct new BaseIO with specified class as the base loader, and specified IO mode (one of CLASS_URL, WORKING_DIRECTORY, CLASS_LOADER, or SYSTEM_LOADER).
 
Method Summary
 Class getBase()
          Returns the base class where the resources will be taken from.
protected  String getException(String path, int mode, String method)
          Returns exception string used whenever resource can not be found.
 File getFile(String path)
          Returns file from specified path with this BaseIO default mode.
 File getFile(String path, int mode)
          Return file from specified path with specified mode.
 ClassLoader getLoader()
          Returns the class loader associated with this BaseIO.
 int getMode()
          Returns the default IO mode used for getting the resources.
 String getModeString(int mode)
          Returns the official statement of specified IO mode, or [UNKNOWN-MODE] if the IO mode is undefined.
 String getRootPath(int mode)
          Returns the root path of this BaseIO if using specified mode.
 InputStream getStream(String path)
          Returns input stream from specified path with this BaseIO default mode.
 InputStream getStream(String path, int mode)
          Returns input stream from specified path with specified mode.
 URL getURL(String path)
          Returns URL from specified path with this BaseIO default mode.
 URL getURL(String path, int mode)
          Returns URL from specified path with specified mode.
 void setBase(Class base)
          Sets the base class where the resources will be taken from.
 File setFile(String path)
          Returns file on specified path with this BaseIO default mode for processing.
 File setFile(String path, int mode)
          Returns file on specified path with specified mode for processing.
 void setMode(int i)
          Sets the default IO mode used for getting the resources.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLASS_URL

public static final int CLASS_URL
IO mode constant for class url.

See Also:
Constant Field Values

WORKING_DIRECTORY

public static final int WORKING_DIRECTORY
IO mode constant for working directory.

See Also:
Constant Field Values

CLASS_LOADER

public static final int CLASS_LOADER
IO mode constant for class loader.

See Also:
Constant Field Values

SYSTEM_LOADER

public static final int SYSTEM_LOADER
IO mode constant for system loader.

See Also:
Constant Field Values
Constructor Detail

BaseIO

public BaseIO(Class base,
              int mode)
Construct new BaseIO with specified class as the base loader, and specified IO mode (one of CLASS_URL, WORKING_DIRECTORY, CLASS_LOADER, or SYSTEM_LOADER).

Parameters:
base - the base class loader
mode - one of IO mode constants
See Also:
CLASS_URL, WORKING_DIRECTORY, CLASS_LOADER, SYSTEM_LOADER

BaseIO

public BaseIO(Class base)
Construct new BaseIO with specified class as the base loader using CLASS_URL mode as the default.

Parameters:
base - the base class loader
Method Detail

getURL

public URL getURL(String path,
                  int mode)
Returns URL from specified path with specified mode.


getURL

public URL getURL(String path)
Returns URL from specified path with this BaseIO default mode.


getStream

public InputStream getStream(String path,
                             int mode)
Returns input stream from specified path with specified mode.


getStream

public InputStream getStream(String path)
Returns input stream from specified path with this BaseIO default mode.


getFile

public File getFile(String path,
                    int mode)
Return file from specified path with specified mode.


getFile

public File getFile(String path)
Returns file from specified path with this BaseIO default mode.

File object usually used only for writing to disk.

Caution: always try to avoid using java.io.File object (this method), because java.io.File is system dependent and not working inside jar file, use java.net.URL OR java.io.InputStream instead.

See Also:
getURL(String), getStream(String), setFile(String)

setFile

public File setFile(String path,
                    int mode)
Returns file on specified path with specified mode for processing.


setFile

public File setFile(String path)
Returns file on specified path with this BaseIO default mode for processing.


getRootPath

public String getRootPath(int mode)
Returns the root path of this BaseIO if using specified mode. The root path is the root where all the resources will be taken from.

For example :
The root path = "c:\games\spaceinvader"
The resource name = "images\background.png"
The resource then will be taken from =
"c:\games\spaceinvader\images\background.png"


getModeString

public String getModeString(int mode)
Returns the official statement of specified IO mode, or [UNKNOWN-MODE] if the IO mode is undefined.

See Also:
getMode()

getMode

public int getMode()
Returns the default IO mode used for getting the resources.

See Also:
setMode(int), getModeString(int)

setMode

public void setMode(int i)
Sets the default IO mode used for getting the resources.

See Also:
getMode(), CLASS_URL, WORKING_DIRECTORY, CLASS_LOADER, SYSTEM_LOADER

getException

protected String getException(String path,
                              int mode,
                              String method)
Returns exception string used whenever resource can not be found.


setBase

public void setBase(Class base)
Sets the base class where the resources will be taken from.

See Also:
getBase()

getBase

public Class getBase()
Returns the base class where the resources will be taken from.

See Also:
setBase(Class)

getLoader

public ClassLoader getLoader()
Returns the class loader associated with this BaseIO.

See Also:
setBase(Class)

toString

public String toString()
Overrides:
toString in class Object

GTGE API

Copyright © 2003-2005 Golden T Studios. All rights reserved. Use is subject to license terms.
GoldenStudios.or.id