private static void testCompressor() { int[] size3D = { 3, 6, 6 }; // (z,y,x) IMazeGenerator mazeGenerator3d = new MyMaze3dGenerator(); Maze3d maze = (Maze3d)mazeGenerator3d.generate(size3D); maze.print(); Console.ReadKey(); byte[] decomp = maze.toByteArray(); for (int i = 0; i < decomp.Length; i++) { Console.Write(decomp[i] + " "); } ICompressor compressor = new MyMaze3DCompressor(); Console.WriteLine("\ncompression : "); byte[] comp = compressor.compress(decomp); for (int i = 0; i < comp.Length; i++) { Console.Write(comp[i] + " "); } decomp = compressor.decompress(comp); Console.WriteLine("\ndecompression : "); for (int i = 0; i < decomp.Length; i++) { Console.Write(decomp[i] + " "); } }
private static void testMeze3dGenerator(MyMaze3dGenerator mg) { ArrayList s = new ArrayList(); s.Add(20); s.Add(20); s.Add(4); Console.WriteLine(mg.MeasureAlgorithmTime(s)); AMaze maze = mg.generate(s); Position start = maze.getStartPosition(); start.print(); maze.getGoalPosition().print(); maze.Print(); byte[] dar = (maze as Maze3d).toByteArray(); Maze3d hara = new Maze3d(dar); ICompressor car = new MyMaze3DCompressor(); byte[] hara1 = car.compress(dar); byte[] hara2 = car.decompress(hara1); Maze3d hara3 = new Maze3d(hara2); hara3.Print(); /*using (FileStream fileOutStream = new FileStream("1.maze", FileMode.Create)) * { * using (Stream outStream = new MyCompressorStream(fileOutStream, 1)) * { * outStream.Write((maze as Maze3d).toByteArray(),0,1); * outStream.Flush(); * } * } * byte[] mazeBytes; * using (FileStream fileInStream = new FileStream("1.maze", FileMode.Open)) * { * using (Stream inStream = new MyCompressorStream(fileInStream,1)) * { * mazeBytes = new byte[(maze as Maze3d).toByteArray().Count()]; * input.read(b); * } * } * Maze3d loadedMaze = new Maze3d(mazeBytes); * System.out.println(loaded.equals(maze));*/ Console.ReadKey(); }
public void Save(string mazename, string path) { if (!(m_controller as MyController).mazes.ContainsKey(mazename)) { File.Create(path); byte[] comp = ((m_controller as MyController).mazes[mazename] as Maze3d).toByteArray(); MyMaze3DCompressor dcomp = new MyMaze3DCompressor(); byte[] tosave = dcomp.compress(comp); File.WriteAllBytes(path, tosave); } else { (m_controller as MyController).M_view.Output("maze name does not exists"); } return; }
/// <summary> /// compress Zip Maze /// </summary> private void compressZipMaze() { MyMaze3DCompressor compressor = new MyMaze3DCompressor(); ZipFile zipFile = new ZipFile("Mazes.zip"); foreach (Maze3d maze3d in m_DicOfMazes.Values) { byte[] compressedMaze = maze3d.toByteArray(); string nameToSave = m_DicOfMazes.FirstOrDefault(x => x.Value == maze3d).Key; writeDataToDisk(compressedMaze, nameToSave); } foreach (string maze3dName in m_DicOfMazes.Keys) { zipFile.AddFile(maze3dName); } zipFile.Save(); deleteAllFiles(); }
private static void TestCheck() { IMazeGenerator mg = new MyMaze3dGenerator(); Maze maze = mg.generate(8, 8, 5); MyMaze3DCompressor comp = new MyMaze3DCompressor(); byte[] byteArray = ((Maze3d)maze).toByteArray(); Console.WriteLine("Before"); for (int i = 0; i < byteArray.Length; i++) { Console.Write(byteArray[i]); } Console.WriteLine(); Console.WriteLine("After"); byte[] byteArrayAfter = comp.compress(byteArray); byte[] byteArrayAfterDec = comp.decompress(byteArrayAfter); for (int i = 0; i < byteArrayAfterDec.Length; i++) { Console.Write(byteArrayAfterDec[i]); } Console.WriteLine(); }