From: fred-boy Date: Tue, 24 Apr 2018 17:45:25 +0000 (+0700) Subject: Save with BufferedOutputStream X-Git-Tag: alpha0.3~5 X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=08def9aa287e5309c12c6a4110f6b8486afd3a6c;p=cavedroid.git Save with BufferedOutputStream --- diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java b/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java index fccc7bc..1bf6684 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java @@ -3,8 +3,9 @@ package ru.deadsoftware.cavecraft.game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; import ru.deadsoftware.cavecraft.CaveGame; -import ru.deadsoftware.cavecraft.Items; +import java.io.BufferedOutputStream; +import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.nio.ByteBuffer; @@ -16,39 +17,42 @@ public class GameSaver { private static int[][] fMap, bMap; private static int readIndex; - private static int bytesInt(byte[] bytes) { + private static int bytesToInt(byte[] bytes) { ByteBuffer wrapped = ByteBuffer.wrap(bytes); int res = wrapped.getInt(readIndex); readIndex+=4; return res; } - private static void writeInt(FileHandle file, int i, boolean append) { - byte[] bytes = ByteBuffer.allocate(4).putInt(i).array(); - file.writeBytes(bytes, append); + private static byte[] intToBytes(int i) { + return ByteBuffer.allocate(4).putInt(i).array(); } - private static void saveMap(FileHandle file, int[][] map) { + private static void saveMap(FileHandle file, int[][] map) throws IOException{ int rl,bl; int width = map.length; int height = map[0].length; - writeInt(file, VERSION, false); - writeInt(file, width, true); - writeInt(file, height, true); + BufferedOutputStream out = new BufferedOutputStream(file.write(false)); + out.write(intToBytes(VERSION)); + out.write(intToBytes(width)); + out.write(intToBytes(height)); for (int y=0; y