    001    package net.minecraft.network.rcon;
    002
    003    public class RConUtils
    004    {
    005        /** Translation array of decimal to hex digits */
    006        public static char[] hexDigits = new char[] {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
    007
    008        /**
    009         * Read a null-terminated string from the given byte array
    010         */
    011        public static String getBytesAsString(byte[] par0ArrayOfByte, int par1, int par2)
    012        {
    013            int var3 = par2 - 1;
    014            int var4;
    015
    016            for (var4 = par1 > var3 ? var3 : par1; 0 != par0ArrayOfByte[var4] && var4 < var3; ++var4)
    017            {
    018                ;
    019            }
    020
    021            return new String(par0ArrayOfByte, par1, var4 - par1);
    022        }
    023
    024        /**
    025         * Read 4 bytes from the
    026         */
    027        public static int getRemainingBytesAsLEInt(byte[] par0ArrayOfByte, int par1)
    028        {
    029            return getBytesAsLEInt(par0ArrayOfByte, par1, par0ArrayOfByte.length);
    030        }
    031
    032        /**
    033         * Read 4 bytes from the given array in little-endian format and return them as an int
    034         */
    035        public static int getBytesAsLEInt(byte[] par0ArrayOfByte, int par1, int par2)
    036        {
    037            return 0 > par2 - par1 - 4 ? 0 : par0ArrayOfByte[par1 + 3] << 24 | (par0ArrayOfByte[par1 + 2] & 255) << 16 | (par0ArrayOfByte[par1 + 1] & 255) << 8 | par0ArrayOfByte[par1] & 255;
    038        }
    039
    040        /**
    041         * Read 4 bytes from the given array in big-endian format and return them as an int
    042         */
    043        public static int getBytesAsBEint(byte[] par0ArrayOfByte, int par1, int par2)
    044        {
    045            return 0 > par2 - par1 - 4 ? 0 : par0ArrayOfByte[par1] << 24 | (par0ArrayOfByte[par1 + 1] & 255) << 16 | (par0ArrayOfByte[par1 + 2] & 255) << 8 | par0ArrayOfByte[par1 + 3] & 255;
    046        }
    047
    048        /**
    049         * Returns a String representation of the byte in hexadecimal format
    050         */
    051        public static String getByteAsHexString(byte par0)
    052        {
    053            return "" + hexDigits[(par0 & 240) >>> 4] + hexDigits[par0 & 15];
    054        }
    055    }