Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static byte[] WriteShort(int in)
- /* */ {
- /* 7 */ byte[] bytes = new byte[2];
- /* 8 */ bytes[0] = (byte)(in >>> 8 & 0xFF);
- /* 9 */ bytes[1] = (byte)(in >>> 0 & 0xFF);
- /* 10 */ return bytes;
- /* */ }
- /* */
- /* */ public static byte[] WriteInt(int in) {
- /* 14 */ byte[] bytes = new byte[4];
- /* 15 */ bytes[0] = (byte)(in >>> 24 & 0xFF);
- /* 16 */ bytes[1] = (byte)(in >>> 16 & 0xFF);
- /* 17 */ bytes[2] = (byte)(in >>> 8 & 0xFF);
- /* 18 */ bytes[3] = (byte)(in >>> 0 & 0xFF);
- /* 19 */ return bytes;
- /* */ }
- /* */
- /* */ public static byte[] ChompBytes(byte[] bzBytes, int Offset, int numBytes)
- /* */ {
- /* 24 */ int End = Offset + numBytes;
- /* 25 */ if (End > bzBytes.length) {
- /* 26 */ End = bzBytes.length;
- /* */ }
- /* 28 */ if (numBytes > bzBytes.length)
- /* 29 */ numBytes = bzBytes.length;
- /* 30 */ if (numBytes < 0) {
- /* 31 */ numBytes = 0;
- /* */ }
- /* 33 */ byte[] bzChunk = new byte[numBytes];
- /* 34 */ for (int x = 0; x < numBytes; x++)
- /* */ {
- /* 36 */ bzChunk[x] = bzBytes[(Offset++)];
- /* */ }
- /* */
- /* 39 */ return bzChunk;
- /* */ }
- public static Byte[] EncodeInt16(int x)
- {
- return EncodeInt16((short)x);
- }
- public static Byte[] EncodeInt16(short x)
- {
- return new Byte[]{ (byte)(x >>> 8), (byte)x };
- }
- public static Byte[] EncodeInt32(int x)
- {
- return new Byte[]{ (byte)(x >>> 24), (byte)(x >>> 16), (byte)(x >>> 8), (byte)x };
- }
- public static Byte[] EncodeString(String x)
- {
- Byte[] Output = new Byte[x.length() + 2];
- int k = 0;
- Byte[] EncodeInt16 = EncodeInt16(x.length());
- Output[k++] = EncodeInt16[0];
- Output[k++] = EncodeInt16[1];
- for(byte c : x.getBytes())
- {
- Output[k++] = c;
- }
- return Output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement