the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 80 lines 2.4 kB view raw
1#include "stdafx.h" 2 3#include "ByteArrayOutputStream.h" 4 5// Creates a new byte array output stream. The buffer capacity is initially 32 bytes, though its size increases if necessary. 6ByteArrayOutputStream::ByteArrayOutputStream() 7{ 8 count = 0; 9 buf = byteArray( 32 ); 10} 11 12//Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes. 13//Parameters: 14//size - the initial size. 15ByteArrayOutputStream::ByteArrayOutputStream(unsigned int size) 16{ 17 count = 0; 18 buf = byteArray( size ); 19} 20 21ByteArrayOutputStream::~ByteArrayOutputStream() 22{ 23 if (buf.data != NULL) 24 delete[] buf.data; 25} 26 27//Writes the specified byte to this byte array output stream. 28//Parameters: 29//b - the byte to be written. 30void ByteArrayOutputStream::write(unsigned int b) 31{ 32 // If we will fill the buffer we need to make it bigger 33 if( count + 1 >= buf.length ) 34 buf.resize( buf.length * 2 ); 35 36 buf[count] = (byte) b; 37 count++; 38} 39 40// Writes b.length bytes from the specified byte array to this output stream. 41//The general contract for write(b) is that it should have exactly the same effect as the call write(b, 0, b.length). 42void ByteArrayOutputStream::write(byteArray b) 43{ 44 write(b, 0, b.length); 45} 46 47//Writes len bytes from the specified byte array starting at offset off to this byte array output stream. 48//Parameters: 49//b - the data. 50//off - the start offset in the data. 51//len - the number of bytes to write. 52void ByteArrayOutputStream::write(byteArray b, unsigned int offset, unsigned int length) 53{ 54 assert( b.length >= offset + length ); 55 56 // If we will fill the buffer we need to make it bigger 57 if( count + length >= buf.length ) 58 buf.resize( max( count + length + 1, buf.length * 2 ) ); 59 60 XMemCpy( &buf[count], &b[offset], length ); 61 //std::copy( b->data+offset, b->data+offset+length, buf->data + count ); // Or this instead? 62 63 count += length; 64} 65 66//Closing a ByteArrayOutputStream has no effect. 67//The methods in this class can be called after the stream has been closed without generating an IOException. 68void ByteArrayOutputStream::close() 69{ 70} 71 72//Creates a newly allocated byte array. Its size is the current size of this output stream and the valid contents of the buffer have been copied into it. 73//Returns: 74//the current contents of this output stream, as a byte array. 75byteArray ByteArrayOutputStream::toByteArray() 76{ 77 byteArray out(count); 78 memcpy(out.data,buf.data,count); 79 return out; 80}