the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at master 87 lines 2.6 kB view raw
1#include "stdafx.h" 2 3#include "BufferedOutputStream.h" 4 5//Creates a new buffered output stream to write data to the specified underlying output stream with the specified buffer size. 6//Parameters: 7//out - the underlying output stream. 8//size - the buffer size. 9BufferedOutputStream::BufferedOutputStream(OutputStream *out, int size) 10{ 11 stream = out; 12 buf = byteArray( size ); 13 count = 0; 14} 15 16BufferedOutputStream::~BufferedOutputStream() 17{ 18 delete buf.data; 19} 20 21//Flushes this buffered output stream. This forces any buffered output bytes to be written out to the underlying output stream. 22void BufferedOutputStream::flush() 23{ 24 stream->write( buf, 0, count ); 25 26 count = 0; 27} 28 29//Closes this output stream and releases any system resources associated with the stream. 30//The close method of FilterOutputStream calls its flush method, and then calls the close method of its underlying output stream. 31void BufferedOutputStream::close() 32{ 33 flush(); 34 stream->close(); 35} 36 37//Writes len bytes from the specified byte array starting at offset off to this buffered output stream. 38//Ordinarily this method stores bytes from the given array into this stream's buffer, flushing the buffer to the 39//underlying output stream as needed. If the requested length is at least as large as this stream's buffer, however, 40//then this method will flush the buffer and write the bytes directly to the underlying output stream. 41//Thus redundant BufferedOutputStreams will not copy data unnecessarily. 42// 43//Overrides: 44//write in class FilterOutputStream 45//Parameters: 46//b - the data. 47//off - the start offset in the data. 48//len - the number of bytes to write. 49void BufferedOutputStream::write(byteArray b, unsigned int offset, unsigned int length) 50{ 51 // Over the length of what we can store in our buffer - just flush the buffer and output directly 52 if( length >= buf.length ) 53 { 54 flush(); 55 stream->write(b, offset, length); 56 } 57 else 58 { 59 for(unsigned int i = 0; i < length; i++ ) 60 { 61 write( b[offset+i] ); 62 } 63 } 64} 65 66//Writes b.length bytes to this output stream. 67//The write method of FilterOutputStream calls its write method of three arguments with the arguments b, 0, and b.length. 68// 69//Note that this method does not call the one-argument write method of its underlying stream with the single argument b. 70void BufferedOutputStream::write(byteArray b) 71{ 72 write( b, 0, b.length ); 73} 74 75//Writes the specified byte to this buffered output stream. 76//Overrides: 77//write in class FilterOutputStream 78//Parameters: 79//b - the byte to be written. 80void BufferedOutputStream::write(unsigned int b) 81{ 82 buf[count++] = (byte) b; 83 if( count == buf.length ) 84 { 85 flush(); 86 } 87}