task.java

来自「利用Java Socket写的一段通讯协议」· Java 代码 · 共 71 行

JAVA
71
字号
package com.ict.netcom2.task;

import java.io.*;

public class Task implements Serializable {
	
	private int taskId;
	private long delay;
	private boolean isRoutine;
	private TaskParam param;

	private int taskType;
	private byte[] taskCode;
	private String oid;	

	public Task (int taskId, long delay, boolean isRoutine,
			TaskParam param) {
		this.taskId = taskId;
		this.delay = delay;
		this.isRoutine = isRoutine;
		this.param = param;
	}
	
	/**
	 * 
	 *	Must be called after {@link #taskType} initialized
	 */
	void encode() {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);
        byte[] paramCode = param.getParamCode();
        try {
            dos.writeInt(taskId);
            dos.writeInt((int)delay);
            dos.writeBoolean(isRoutine);
            dos.writeByte(taskType);
            dos.writeInt(paramCode.length);
            dos.write(paramCode);
            dos.close();
            baos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        taskCode = baos.toByteArray();
	}
	
	public byte[] getTaskCode() {
		return taskCode;
	}
	
	public String getOid() {
		return oid;
	}
	
	public int getId() {
		return taskId;
	}
	
	public int getType() {
		return taskType;
	}
	
	void setType(int type) {
		taskType = type;
	}
	
	void setOid(String oid) {
		this.oid = oid;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?