the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 65 lines 2.0 kB view raw
1#include "stdafx.h" 2#include "InputOutputStream.h" 3#include "NbtIo.h" 4 5CompoundTag *NbtIo::readCompressed(InputStream *in) 6{ 7 MemSect(26); 8 // 4J - this was using a try/finally block 9 DataInputStream dis = DataInputStream(in); // 4J - was new GZIPInputStream as well 10 CompoundTag *ret = NbtIo::read((DataInput *)&dis); 11 dis.close(); 12 MemSect(0); 13 return ret; 14} 15 16void NbtIo::writeCompressed(CompoundTag *tag, OutputStream *out) 17{ 18 // 4J - this was using a try/finally block 19 // 4J Stu - Buffer output in 1024 byte chunks so that we can allocate properly in the save file 20 BufferedOutputStream bos = BufferedOutputStream( out, 1024 ); 21 DataOutputStream dos = DataOutputStream(&bos); // 4J - was new GZIPOutputStream as well 22 NbtIo::write(tag, &dos); 23 dos.close(); 24} 25 26// Reads tags from a stream created from the input buffer. Doesn't free the data in the source buffer. 27CompoundTag *NbtIo::decompress(byteArray buffer) 28{ 29 ByteArrayInputStream bais = ByteArrayInputStream(buffer); 30 // 4J - this was using a try/finally block 31 DataInputStream in = DataInputStream(&bais); // 4J - was new GZIPInputStream as well 32 CompoundTag *ret = NbtIo::read((DataInput *)&in); 33 bais.reset(); // This stops the buffer referenced by the input stream from being freed when it goes out of context 34 in.close(); 35 return ret; 36} 37 38byteArray NbtIo::compress(CompoundTag *tag) 39{ 40 // 4J - this was using a try/finally block 41 ByteArrayOutputStream baos = ByteArrayOutputStream(); 42 DataOutputStream dos = DataOutputStream(&baos); // 4J - was new GZIPOutputStream as well 43 NbtIo::write(tag, &dos); 44 45 byteArray ret(baos.buf.length); 46 System::arraycopy(baos.buf,0,&ret,0,baos.buf.length); 47 dos.close(); 48 return ret; 49} 50 51CompoundTag *NbtIo::read(DataInput *dis) 52{ 53 Tag *tag = Tag::readNamedTag(dis); 54 55 if( tag->getId() == Tag::TAG_Compound ) return (CompoundTag *)tag; 56 57 if(tag!=NULL) delete tag; 58 // Root tag must be a named compound tag 59 return NULL; 60} 61 62void NbtIo::write(CompoundTag *tag, DataOutput *dos) 63{ 64 Tag::writeNamedTag(tag, dos); 65}