Abstracted code that parses XML configuration definitions into Java
objects which are then serialized for rapid loading and simple utilization by the client and server; created serialized config services for our character component constraints (what components are available at character creation time, etc.). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1101 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// $Id: CompiledConfig.java,v 1.1 2002/03/08 06:15:21 mdb Exp $
|
||||
|
||||
package com.threerings.yohoho.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Used to load and store compiled configuration data (generally XML files
|
||||
* that are parsed into Java object models and then serialized for rapid
|
||||
* and simple access on the client and server).
|
||||
*/
|
||||
public class CompiledConfig
|
||||
{
|
||||
/**
|
||||
* Unserializes a configuration object from the supplied input stream.
|
||||
*/
|
||||
public static Serializable loadConfig (InputStream source)
|
||||
throws IOException, ClassNotFoundException
|
||||
{
|
||||
ObjectInputStream oin = new ObjectInputStream(source);
|
||||
return (Serializable)oin.readObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the supplied configuration object to the specified file
|
||||
* path.
|
||||
*/
|
||||
public static void saveConfig (File target, Serializable config)
|
||||
throws IOException
|
||||
{
|
||||
FileOutputStream fout = new FileOutputStream(target);
|
||||
ObjectOutputStream oout = new ObjectOutputStream(fout);
|
||||
oout.writeObject(config);
|
||||
oout.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user