001    package net.minecraft.network.rcon;
002    
003    import java.io.ByteArrayOutputStream;
004    import java.io.DataOutputStream;
005    import java.io.IOException;
006    
007    public class RConOutputStream
008    {
009        /** Output stream */
010        private ByteArrayOutputStream byteArrayOutput;
011    
012        /** ByteArrayOutputStream wrapper */
013        private DataOutputStream output;
014    
015        public RConOutputStream(int par1)
016        {
017            this.byteArrayOutput = new ByteArrayOutputStream(par1);
018            this.output = new DataOutputStream(this.byteArrayOutput);
019        }
020    
021        /**
022         * Writes the given byte array to the output stream
023         */
024        public void writeByteArray(byte[] par1ArrayOfByte) throws IOException
025        {
026            this.output.write(par1ArrayOfByte, 0, par1ArrayOfByte.length);
027        }
028    
029        /**
030         * Writes the given String to the output stream
031         */
032        public void writeString(String par1Str) throws IOException
033        {
034            this.output.writeBytes(par1Str);
035            this.output.write(0);
036        }
037    
038        /**
039         * Writes the given int to the output stream
040         */
041        public void writeInt(int par1) throws IOException
042        {
043            this.output.write(par1);
044        }
045    
046        /**
047         * Writes the given short to the output stream
048         */
049        public void writeShort(short par1) throws IOException
050        {
051            this.output.writeShort(Short.reverseBytes(par1));
052        }
053    
054        /**
055         * Returns the contents of the output stream as a byte array
056         */
057        public byte[] toByteArray()
058        {
059            return this.byteArrayOutput.toByteArray();
060        }
061    
062        /**
063         * Resets the byte array output.
064         */
065        public void reset()
066        {
067            this.byteArrayOutput.reset();
068        }
069    }