package TX_OtherClass;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import zip.d;

public class p {
    public static byte[] a_tobyte(RequestCommand arg7, long arg8) {
        byte[] v0 = null;
        byte[] v1 = ProtocolPackage.buildPostData(arg7);
        if(v1 != null) {
            int v2 = v1.length + 17;
            ByteBuffer v3 = ByteBuffer.allocate(v2);
            v3.put((byte) 38);
            v3.putInt(v2);
            v3.put((byte) 1);
            v3.position(v3.position() + 10);
            v3.put(v1);
            v3.put((byte) 40);
            v1 = v3.array();
            ByteArrayOutputStream v2_1 = new ByteArrayOutputStream(v1.length + 50);
            DataOutputStream v3_1 = new DataOutputStream(((OutputStream)v2_1));
            int v4 = 19;
            try {
                v3_1.writeByte(v4);
                v3_1.writeInt(0);
                v3_1.writeShort(1);
                v3_1.writeShort(65281);
                v3_1.writeShort(arg7.head.cmdId);
                v3_1.writeShort(0);
                v3_1.writeLong(arg8);
                v3_1.writeInt(531);
                v3_1.writeInt(o.f());
                v3_1.writeLong(0);
                p.a(((OutputStream)v3_1), arg7.head.guid, 32);
                v3_1.writeByte(o.g());
                v3_1.writeInt(o.h());
                p.a(((OutputStream)v3_1), null, 6);
                v3_1.writeByte(0);
                v3_1.writeShort(0);
                v3_1.writeShort(0);
                v3_1.writeInt(v1.length);
                v1 = d.a(v1);
                if(v1 == null) {
                    return v0;
                }

                v3_1.write(v1);
                v3_1.writeByte(3);
                v3_1.close();
                v1 = v2_1.toByteArray();
                ByteBuffer v2_2 = ByteBuffer.wrap(v1);
                v2_2.putInt(1, v1.length);
                v0 = v2_2.array();
            }
            catch(IOException v1_1) {
                v1_1.printStackTrace();
            }
        }

        return v0;
    }

    private static void a(OutputStream arg3, String arg4, int arg5) throws IOException {
        int v0;
        byte[] v2 = null;
        if(arg5 > 0) {
            if(arg4 != null) {
                try {
					v2 = arg4.getBytes("UTF-8");
				} catch (UnsupportedEncodingException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
                v0 = v2.length;
            }
            else {
                v2 = null;
                v0 = 0;
            }

            if(v0 >= arg5) {
                arg3.write(v2, 0, arg5);
                return;
            }

            if(v0 > 0) {
                arg3.write(v2, 0, v0);
            }

            while(v0 < arg5) {
                arg3.write(0);
                ++v0;
            }
        }
    }
}
