📄 clipevent.java
字号:
package com.jzl.sirius.at.event;
import java.nio.ByteBuffer;
import com.jzl.sirius.at.ATConstants;
import com.jzl.sirius.at.util.StringMatch;
public class CLIPEvent extends MutiableEvent {
private StringMatch startMatch = new StringMatch(ATConstants.CRLF + "+CLIP:");
private StringMatch endMatch = new StringMatch(ATConstants.CRLF);
private boolean eventStarted = false;
private StringBuffer sb = new StringBuffer();
private String number;
private int type;
public void reset() {
super.reset();
eventStarted = false;
number = "";
type = -1;
sb = new StringBuffer();
}
public boolean match(char ch) {
eventStarted = startMatch.match(ch);
return eventStarted;
}
private void decodeResponse() {
int index = sb.indexOf(ATConstants.CRLF);
if (index == -1)
return;
try {
String str = sb.substring(0, index).trim();
index = str.indexOf(',');
if (index == -1) {
return;
}
number = str.substring(1, index - 1).trim();
type = Integer.parseInt(str.substring(index + 1).trim());
}
catch(Exception ex) {
}
}
public boolean readResponse(ByteBuffer buffer) {
while(buffer.hasRemaining()){
char ch = (char)buffer.get();
if (eventStarted) {
sb.append(ch);
if (endMatch.match(ch)) {
// 事件结束,进行结果解析
decodeResponse();
finish();
return true;
}
}
else
match(ch);
}
return false;
}
public String getNumber() {
return number;
}
public int getType() {
return type;
}
public Object clone() throws CloneNotSupportedException {
CLIPEvent obj = (CLIPEvent)super.clone();
obj.sb.append(sb);
obj.eventStarted = eventStarted;
obj.number = number;
obj.type = type;
return obj;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -