Package com.maverick.multiplex

Source Code of com.maverick.multiplex.Request

package com.maverick.multiplex;

import java.io.IOException;
import java.math.BigInteger;
import java.util.Date;

import com.maverick.util.ByteArrayWriter;

public class Request {
    byte[] requestData;
    String requestName;

    public Request(String requestName) {
        this(requestName, (byte[]) null);
    }

    public Request(String requestName, byte[] requestData) {
        this.requestName = requestName;
        this.requestData = requestData;
    }

    public Request(String requestName, Object[] values) throws IOException {
        this.requestName = requestName;
        ByteArrayWriter writer = new ByteArrayWriter();
        for (int index = 0; index < values.length; index++) {
            Object value = values[index];
            if (value instanceof BigInteger) {
                writer.writeBigInteger((BigInteger) value);
            } else if (value instanceof Integer) {
                writer.writeInt(((Integer) value).intValue());
            } else if (value instanceof Long) {
                writer.writeUINT64(((Long) value).longValue());
            } else if (value instanceof Short) {
                writer.writeShort(((Short) value).shortValue());
            } else if (value instanceof Boolean) {
                writer.writeBoolean(((Boolean) value).booleanValue());
            } else if (value instanceof Date) {
                writer.writeUINT64(((Date) value).getTime());
            } else {
                writer.writeString(value.toString());
            }
        }
        requestData = writer.toByteArray();
    }

    public String getRequestName() {
        return requestName;
    }

    public byte[] getRequestData() {
        return requestData;
    }

    public void setRequestData(byte[] requestData) {
        this.requestData = requestData;
    }
}
TOP

Related Classes of com.maverick.multiplex.Request

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.