|
@@ -11,12 +11,12 @@ import com.jme3.export.binary.BinaryImporter;
|
|
|
import java.io.ByteArrayInputStream;
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
|
+import java.io.InputStream;
|
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Level;
|
|
|
import java.util.logging.Logger;
|
|
import java.util.logging.Logger;
|
|
|
import java.util.prefs.Preferences;
|
|
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.UUDecoder;
|
|
|
import sun.misc.UUEncoder;
|
|
import sun.misc.UUEncoder;
|
|
|
|
|
|
|
@@ -36,12 +36,9 @@ public class SaveGame {
|
|
|
Preferences prefs = Preferences.userRoot().node(gamePath);
|
|
Preferences prefs = Preferences.userRoot().node(gamePath);
|
|
|
BinaryExporter ex = BinaryExporter.getInstance();
|
|
BinaryExporter ex = BinaryExporter.getInstance();
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
- ZipOutputStream zos = new ZipOutputStream(out);
|
|
|
|
|
- zos.setLevel(9);
|
|
|
|
|
try {
|
|
try {
|
|
|
- zos.putNextEntry(new ZipEntry(dataName));
|
|
|
|
|
|
|
+ GZIPOutputStream zos = new GZIPOutputStream(out);
|
|
|
ex.save(data, zos);
|
|
ex.save(data, zos);
|
|
|
- zos.closeEntry();
|
|
|
|
|
zos.close();
|
|
zos.close();
|
|
|
} catch (IOException ex1) {
|
|
} catch (IOException ex1) {
|
|
|
Logger.getLogger(SaveGame.class.getName()).log(Level.SEVERE, "Error saving data: {0}", 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();
|
|
UUEncoder enc = new UUEncoder();
|
|
|
String dataString = enc.encodeBuffer(out.toByteArray());
|
|
String dataString = enc.encodeBuffer(out.toByteArray());
|
|
|
|
|
+ System.out.println(dataString);
|
|
|
if (dataString.length() > Preferences.MAX_VALUE_LENGTH) {
|
|
if (dataString.length() > Preferences.MAX_VALUE_LENGTH) {
|
|
|
throw new IllegalStateException("SaveGame dataset too large");
|
|
throw new IllegalStateException("SaveGame dataset too large");
|
|
|
}
|
|
}
|
|
@@ -75,12 +73,11 @@ public class SaveGame {
|
|
|
public static Savable loadGame(String gamePath, String dataName, AssetManager manager) {
|
|
public static Savable loadGame(String gamePath, String dataName, AssetManager manager) {
|
|
|
Preferences prefs = Preferences.userRoot().node(gamePath);
|
|
Preferences prefs = Preferences.userRoot().node(gamePath);
|
|
|
String data = prefs.get(dataName, "");
|
|
String data = prefs.get(dataName, "");
|
|
|
- ZipInputStream is = null;
|
|
|
|
|
|
|
+ InputStream is = null;
|
|
|
Savable sav = null;
|
|
Savable sav = null;
|
|
|
UUDecoder dec = new UUDecoder();
|
|
UUDecoder dec = new UUDecoder();
|
|
|
try {
|
|
try {
|
|
|
- is = new ZipInputStream(new ByteArrayInputStream(dec.decodeBuffer(data)));
|
|
|
|
|
- is.getNextEntry();
|
|
|
|
|
|
|
+ is = new GZIPInputStream(new ByteArrayInputStream(dec.decodeBuffer(data)));
|
|
|
BinaryImporter imp = BinaryImporter.getInstance();
|
|
BinaryImporter imp = BinaryImporter.getInstance();
|
|
|
if (manager != null) {
|
|
if (manager != null) {
|
|
|
imp.setAssetManager(manager);
|
|
imp.setAssetManager(manager);
|