Search in sources :

Example 1 with CopierObjectInputStream

use of mage.util.CopierObjectInputStream in project mage by magefree.

the class GameReplay method loadGame.

private Game loadGame(UUID gameId) {
    InputStream file = null;
    InputStream buffer = null;
    InputStream gzip = null;
    ObjectInput input = null;
    try {
        file = new FileInputStream("saved/" + gameId.toString() + ".game");
        buffer = new BufferedInputStream(file);
        gzip = new GZIPInputStream(buffer);
        input = new CopierObjectInputStream(Main.classLoader, gzip);
        Game loadGame = (Game) input.readObject();
        GameStates states = (GameStates) input.readObject();
        loadGame.loadGameStates(states);
        return loadGame;
    } catch (ClassNotFoundException ex) {
        logger.fatal("Cannot load game. Class not found.", ex);
    } catch (IOException ex) {
        logger.fatal("Cannot load game:" + gameId, ex);
    } finally {
        StreamUtils.closeQuietly(file);
        StreamUtils.closeQuietly(buffer);
        StreamUtils.closeQuietly(input);
        StreamUtils.closeQuietly(gzip);
    }
    return null;
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) GameStates(mage.game.GameStates) Game(mage.game.Game) BufferedInputStream(java.io.BufferedInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) CopierObjectInputStream(mage.util.CopierObjectInputStream) InputStream(java.io.InputStream) ObjectInput(java.io.ObjectInput) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) CopierObjectInputStream(mage.util.CopierObjectInputStream)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ObjectInput (java.io.ObjectInput)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 Game (mage.game.Game)1 GameStates (mage.game.GameStates)1 CopierObjectInputStream (mage.util.CopierObjectInputStream)1