📄 jremclientprotocol.java
字号:
/* * JRemCntl - Copyright (C) 2007 Filippo Di Vattimo <fildiv@gmail.com> * See COPYING */package fildiv.jremcntl.client.core;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import fildiv.jremcntl.common.core.Config;import fildiv.jremcntl.common.core.Context;import fildiv.jremcntl.common.core.JRemCommandData;import fildiv.jremcntl.common.core.JRemConfigData;import fildiv.jremcntl.common.core.JRemContextData;import fildiv.jremcntl.common.core.Logger;import fildiv.jremcntl.common.proto.ByteReader;import fildiv.jremcntl.common.proto.ByteWriter;import fildiv.jremcntl.common.proto.JRemAbstractProtocol;import fildiv.jremcntl.common.proto.JRemDataTransferException;import fildiv.jremcntl.common.proto.JRemProtocolMessagesType;public class JRemClientProtocol extends JRemAbstractProtocol { private Logger log; public JRemClientProtocol(InputStream in, OutputStream out, Logger log) { super(in, out); this.log = log; } public void sendCommandID(int cmdID) throws JRemDataTransferException { ByteWriter bw = new ByteWriter(); createMessage(bw, LENGHT_INT, JRemProtocolMessagesType.MSG_TYPE_SEND_COMMAND_ID); bw.addInt(cmdID); sendMessage(bw.getBytes()); } public Config retrieveConfig() throws JRemDataTransferException { Config conf = null; try { ByteReader br = readPacket(true); int command = br.getInt(); if (command != JRemProtocolMessagesType.MSG_TYPE_SEND_CONFIG) throw new JRemDataTransferException( "Invalid command, expected MSG_TYPE_SEND_CONFIG"); String name = br.getString(); conf = new JRemConfigData(name, null); int contextCount = br.getInt(); for (int index = 0; index < contextCount; ++index) { int id = br.getInt(); String desc = br.getString(); short defView = br.getShort(); Context context = new JRemContextData( (JRemConfigData) conf, id, desc, defView, null); conf.appendContext(context); receiveContext(br, context); } } catch(IOException e) { throw new JRemDataTransferException(e); } return conf; } public ServerResponse retrieveServerResponse() throws IOException { ByteReader br = readPacket(false); if (br == null) return null; return new ServerResponse(br); } /* * Implementation */ protected void receiveContext(ByteReader br, Context context) { int commandCount = br.getInt(); for (int index = 0; index < commandCount; ++index) { receiveCommand(br, context); } } protected void receiveCommand(ByteReader br, Context context) { int id = br.getInt(); String desc = br.getString(); String key = br.getString(); String question = br.getString(); JRemCommandData command = new JRemCommandData( (JRemContextData) context, id, desc, null, key, question); context.appendCommand(command); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -