From 9850440a6566d77a8e2bade69f2b63398571107c Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Tue, 18 Oct 2011 20:31:36 +0000 Subject: [PATCH] - use ZIP in SaveGame git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8446 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../src/tools/jme3tools/savegame/SaveGame.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/engine/src/tools/jme3tools/savegame/SaveGame.java b/engine/src/tools/jme3tools/savegame/SaveGame.java index 5a1656123..cec255d96 100644 --- a/engine/src/tools/jme3tools/savegame/SaveGame.java +++ b/engine/src/tools/jme3tools/savegame/SaveGame.java @@ -15,6 +15,9 @@ import java.io.InputStream; import java.util.logging.Level; import java.util.logging.Logger; import java.util.prefs.Preferences; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import java.util.zip.ZipOutputStream; import sun.misc.UUDecoder; import sun.misc.UUEncoder; @@ -34,14 +37,20 @@ public class SaveGame { Preferences prefs = Preferences.userRoot().node(gamePath); BinaryExporter ex = BinaryExporter.getInstance(); ByteArrayOutputStream out = new ByteArrayOutputStream(); + ZipOutputStream zos = new ZipOutputStream(out); + zos.setLevel(9); try { - ex.save(data, out); + zos.putNextEntry(new ZipEntry(dataName)); + ex.save(data, zos); + zos.closeEntry(); + zos.close(); } catch (IOException ex1) { Logger.getLogger(SaveGame.class.getName()).log(Level.SEVERE, "Error saving data: {0}", ex1); ex1.printStackTrace(); } UUEncoder enc = new UUEncoder(); String dataString = enc.encodeBuffer(out.toByteArray()); + System.out.println(out); if (dataString.length() > Preferences.MAX_VALUE_LENGTH) { throw new IllegalStateException("SaveGame dataset too large"); } @@ -68,11 +77,12 @@ public class SaveGame { public static Savable loadGame(String gamePath, String dataName, AssetManager manager) { Preferences prefs = Preferences.userRoot().node(gamePath); String data = prefs.get(dataName, ""); - InputStream is = null; + ZipInputStream is = null; Savable sav = null; UUDecoder dec = new UUDecoder(); try { - is = new ByteArrayInputStream(dec.decodeBuffer(data)); + is = new ZipInputStream(new ByteArrayInputStream(dec.decodeBuffer(data))); + is.getNextEntry(); BinaryImporter imp = BinaryImporter.getInstance(); if (manager != null) { imp.setAssetManager(manager);