From d1a515f8781d36f7b8f23c644e3cf5e553dbfba0 Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Tue, 18 Oct 2011 21:15:16 +0000 Subject: [PATCH] - use GZIP in SaveGame git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8452 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../src/tools/jme3tools/savegame/SaveGame.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/engine/src/tools/jme3tools/savegame/SaveGame.java b/engine/src/tools/jme3tools/savegame/SaveGame.java index 189934606..5f3477f51 100644 --- a/engine/src/tools/jme3tools/savegame/SaveGame.java +++ b/engine/src/tools/jme3tools/savegame/SaveGame.java @@ -11,12 +11,12 @@ import com.jme3.export.binary.BinaryImporter; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +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 java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; import sun.misc.UUDecoder; import sun.misc.UUEncoder; @@ -36,12 +36,9 @@ 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 { - zos.putNextEntry(new ZipEntry(dataName)); + GZIPOutputStream zos = new GZIPOutputStream(out); ex.save(data, zos); - zos.closeEntry(); zos.close(); } catch (IOException ex1) { Logger.getLogger(SaveGame.class.getName()).log(Level.SEVERE, "Error saving data: {0}", ex1); @@ -49,6 +46,7 @@ public class SaveGame { } UUEncoder enc = new UUEncoder(); String dataString = enc.encodeBuffer(out.toByteArray()); + System.out.println(dataString); if (dataString.length() > Preferences.MAX_VALUE_LENGTH) { throw new IllegalStateException("SaveGame dataset too large"); } @@ -75,12 +73,11 @@ public class SaveGame { public static Savable loadGame(String gamePath, String dataName, AssetManager manager) { Preferences prefs = Preferences.userRoot().node(gamePath); String data = prefs.get(dataName, ""); - ZipInputStream is = null; + InputStream is = null; Savable sav = null; UUDecoder dec = new UUDecoder(); try { - is = new ZipInputStream(new ByteArrayInputStream(dec.decodeBuffer(data))); - is.getNextEntry(); + is = new GZIPInputStream(new ByteArrayInputStream(dec.decodeBuffer(data))); BinaryImporter imp = BinaryImporter.getInstance(); if (manager != null) { imp.setAssetManager(manager);