📄 otaconfigparsertest.java
字号:
private void testParseMessageBriefcaseSection() throws Exception {
boolean result = true;
String msg = "testParseMessageBriefcaseSection - Error parsing: \n";
if(!message.getRemoteUri(message.BRIEFCASE).equals(REMOTEBRIEFCASEURI)){
result = false;
msg += ("REMOTEBRIEFCASEURI, found: " + message.getRemoteUri(message.BRIEFCASE)
+ " instead of: " + REMOTEBRIEFCASEURI);
}
try{
assertTrue(msg, result);
}
catch (AssertionFailedException asex){
}
}
/**
* Message builder: builds a message in byte[] format and shows its Hex Form
* Useful to create URL for incoming SMS
* @param msg is the message to be built
*/
private void initParserTest() throws Exception {
msg = buildMessage();
//Build complete message
message = ocmp.parseMessage(msg);
//Print out a string useful for URL creation
//String out = bytesToHex(msg, '%');
//Log.debug(out);
}
/**
* Build a complete message
* @return byte[] message representation
*/
private byte[] buildMessage() throws IOException {
ByteArrayOutputStream msgByteArray = new ByteArrayOutputStream();
DataOutputStream msgData = new DataOutputStream(msgByteArray);
// write message header %01%06%03%1F%01%B6
msgData.write(0x01);
msgData.write(0x06);
msgData.write(0x03);
msgData.write(0x1F);
msgData.write(0x01);
msgData.write(0xB6);
// write message body
msgData.write(buildSyncMLSection());
msgData.write(buildMailSection());
msgData.write(buildContactSection());
msgData.write(buildCalendarSection());
msgData.write(buildTaskSection());
msgData.write(buildNoteSection());
msgData.write(buildBriefcaseSection());
return msgByteArray.toByteArray();
}
/**
* Build SyncML Message Section
* @return byte[] Section representation
*/
private byte[] buildSyncMLSection() throws IOException {
ByteArrayOutputStream msgByteArray = new ByteArrayOutputStream();
DataOutputStream msgData = new DataOutputStream(msgByteArray);
//Section Type
msgData.writeByte(message.SYNCML);
//First Field length
msgData.writeByte(URL.getBytes().length);
//First Field Value
msgData.write(URL.getBytes());
//Second Field length
msgData.writeByte(USER.getBytes().length);
//Second Field Value
msgData.write(USER.getBytes());
//Third Field legth
msgData.writeByte(PASSWORD.getBytes().length);
//Third Field Value
msgData.write(PASSWORD.getBytes());
return msgByteArray.toByteArray();
}
/**
* Build Mail Message Section
* @return byte[] Section representation
*/
private byte[] buildMailSection() throws IOException {
ByteArrayOutputStream msgByteArray = new ByteArrayOutputStream();
DataOutputStream msgData = new DataOutputStream(msgByteArray);
//Section Type
msgData.writeByte(message.MAIL);
//First Field length
msgData.writeByte(REMOTEMAILURI.getBytes().length);
//First Field Value
msgData.write(REMOTEMAILURI.getBytes());
//Second Field length
msgData.writeByte(VISIBLENAME.getBytes().length);
//Second Field Value
msgData.write(VISIBLENAME.getBytes());
//Third Field length
msgData.writeByte(MAILADDRESS.getBytes().length);
//Third Field Value
msgData.write(MAILADDRESS.getBytes());
return msgByteArray.toByteArray();
}
/**
* Build Contact Message Section
* @return byte[] Section representation
*/
private byte[] buildContactSection() throws IOException {
ByteArrayOutputStream msgByteArray = new ByteArrayOutputStream();
DataOutputStream msgData = new DataOutputStream(msgByteArray);
//Section Type
msgData.writeByte(message.CONTACT);
//First Field length
msgData.writeByte(REMOTECONTACTURI.getBytes().length);
//First Field Value
msgData.write(REMOTECONTACTURI.getBytes());
//Second Field length
msgData.writeByte(FORMAT.getBytes().length);
//Second Field Value
msgData.write(FORMAT.getBytes());
return msgByteArray.toByteArray();
}
/**
* Build Calendar Message Section
* @return byte[] Section representation
*/
private byte[] buildCalendarSection() throws IOException {
ByteArrayOutputStream msgByteArray = new ByteArrayOutputStream();
DataOutputStream msgData = new DataOutputStream(msgByteArray);
//Section Type
msgData.writeByte(message.CALENDAR);
//First Field length
msgData.writeByte(REMOTECALENDARURI.getBytes().length);
//First Field Value
msgData.write(REMOTECALENDARURI.getBytes());
//Second Field length
msgData.writeByte(FORMAT.getBytes().length);
//Second Field Value
msgData.write(FORMAT.getBytes());
return msgByteArray.toByteArray();
}
/**
* Build Task Message Section
* @return byte[] Section representation
*/
private byte[] buildTaskSection() throws IOException {
ByteArrayOutputStream msgByteArray = new ByteArrayOutputStream();
DataOutputStream msgData = new DataOutputStream(msgByteArray);
//Section Type
msgData.writeByte(message.TASK);
//First Field length
msgData.writeByte(REMOTETASKURI.getBytes().length);
//First Field Value
msgData.write(REMOTETASKURI.getBytes());
//Second Field length
msgData.writeByte(FORMAT.getBytes().length);
//Second Field Value
msgData.write(FORMAT.getBytes());
return msgByteArray.toByteArray();
}
/**
* Build Note Message Section
* @return byte[] Section representation
*/
private byte[] buildNoteSection() throws IOException {
ByteArrayOutputStream msgByteArray = new ByteArrayOutputStream();
DataOutputStream msgData = new DataOutputStream(msgByteArray);
//Section Type
msgData.writeByte(message.NOTE);
//First Field length
msgData.writeByte(REMOTENOTEURI.getBytes().length);
//First Field Value
msgData.write(REMOTENOTEURI.getBytes());
//OPEN POINT: LocalURI is unuseful for eMail Client Configuration
//Second Field length
//msgData.writeByte(LOCALURI.getBytes().length);
//Second Field Value
//msgData.write(LOCALURI.getBytes());
return msgByteArray.toByteArray();
}
/**
* Build Briefcase Message Section
* @return byte[] Section representation
*/
private byte[] buildBriefcaseSection() throws IOException {
ByteArrayOutputStream msgByteArray = new ByteArrayOutputStream();
DataOutputStream msgData = new DataOutputStream(msgByteArray);
//Section Type
msgData.writeByte(message.BRIEFCASE);
//First Field length
msgData.writeByte(REMOTEBRIEFCASEURI.getBytes().length);
//First Field Value
msgData.write(REMOTEBRIEFCASEURI.getBytes());
//OPEN POINT: LocalURI is unuseful for eMail Client Configuration
//Second Field length
//msgData.writeByte(LOCALURI.getBytes().length);
//Second Field Value
//msgData.write(LOCALURI.getBytes());
return msgByteArray.toByteArray();
}
/**
* Useful method to translate translate a byte array in HEX form
* @param byte to be translate
* @param delimitator is the output string separator to be used
* @return String byte translated
*/
private static String bytesToHex(byte [] b, char delimitator) {
StringBuffer buf = new StringBuffer("");
for (int i=0; i< b.length;i++) {
if (i != 0) {
if (delimitator != 0) {
buf.append(delimitator);
}
}
buf.append(byteToHex(b[i]));
}
return buf.toString();
}
/**
* Translate byte in HEX form
* @param byte to be translate
* @return String byte translated
*/
private static String byteToHex(byte b) {
// Returns hex String representation of byte b
char hexDigit[] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
char[] array = { hexDigit[(b >> 4) & 0x0f], hexDigit[b & 0x0f] };
return new String(array);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -