author | Johnson Ma <johnson.ma@nokia.com> |
Tue, 30 Mar 2010 14:39:29 +0800 | |
changeset 1 | 96906a986c3b |
permissions | -rw-r--r-- |
1
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
1 |
/* |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
2 |
* Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
3 |
* All rights reserved. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
5 |
* under the terms of "Eclipse Public License v1.0" |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
8 |
* |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
9 |
* Initial Contributors: |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
10 |
* Nokia Corporation - initial contribution. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
11 |
* |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
12 |
* Contributors: |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
13 |
* |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
14 |
* Description: Helper class to create, send and receive HTI messages. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
15 |
* |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
16 |
*/ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
17 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
18 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
19 |
package com.nokia.hti.common; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
20 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
21 |
import java.io.File; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
22 |
import java.io.FileInputStream; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
23 |
import java.io.FileOutputStream; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
24 |
import java.io.IOException; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
25 |
import java.io.InputStream; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
26 |
import java.io.OutputStream; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
27 |
import java.util.Arrays; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
28 |
import java.util.logging.Level; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
29 |
import java.util.logging.Logger; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
30 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
31 |
/** |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
32 |
* Helper class to create, send and receive HTI messages. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
33 |
* |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
34 |
*/ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
35 |
public class HtiHelper |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
36 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
37 |
//============================================================================== |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
38 |
//Public constants |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
39 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
40 |
/** |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
41 |
* Validates that the given service uid is among the existing UID's. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
42 |
* |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
43 |
* @param serviceUid The UID to be validated. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
44 |
* @return true if given service UID is valid, otherwise false. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
45 |
*/ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
46 |
public static boolean validateServiceUid( int serviceUid ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
47 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
48 |
return serviceUid == HtiConstants.SERVICE_UID_APP || |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
49 |
serviceUid == HtiConstants.SERVICE_UID_ECHO || |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
50 |
serviceUid == HtiConstants.SERVICE_UID_FTP || |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
51 |
serviceUid == HtiConstants.SERVICE_UID_HTI || |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
52 |
serviceUid == HtiConstants.SERVICE_UID_KEYEVENT || |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
53 |
serviceUid == HtiConstants.SERVICE_UID_SCREEN || |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
54 |
serviceUid == HtiConstants.SERVICE_UID_STIF || |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
55 |
serviceUid == HtiConstants.SERVICE_UID_SYSINFO || |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
56 |
serviceUid == HtiConstants.SERVICE_UID_AUDIO || |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
57 |
serviceUid == HtiConstants.SERVICE_UID_PIM || |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
58 |
serviceUid == HtiConstants.SERVICE_UID_MESSAGES ; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
59 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
60 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
61 |
/** |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
62 |
* Creates a HTI message from given service UID and input file containing |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
63 |
* the message body. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
64 |
* |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
65 |
* @param serviceUid The UID of the destination service. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
66 |
* @param inputFile The file containing the message body. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
67 |
* @return The created HTI message as a byte array. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
68 |
* @throws Exception if error occurs in file handling. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
69 |
*/ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
70 |
public static byte[] createHtiMessage( int serviceUid, File inputFile ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
71 |
throws Exception |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
72 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
73 |
byte[] message = new byte[14 + (int)inputFile.length()]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
74 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
75 |
Arrays.fill( message, (byte)0 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
76 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
77 |
// add service UID, 4 bytes |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
78 |
CommonMethods.intToLittleEndianBytes( serviceUid, message, 0, 4 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
79 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
80 |
// add body size, 4 bytes |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
81 |
int bodySize = (int)inputFile.length(); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
82 |
CommonMethods.intToLittleEndianBytes( bodySize, message, 4, 4 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
83 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
84 |
// hti message version |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
85 |
message[8] = (byte)1; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
86 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
87 |
// hti message priority |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
88 |
message[9] = serviceUid == HtiConstants.SERVICE_UID_FTP ? (byte) 2 : (byte) 0; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
89 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
90 |
// leave flags and ext size to zero |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
91 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
92 |
// add the crc |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
93 |
int crc = CommonMethods.CRC16CCITT( message, 12 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
94 |
CommonMethods.intToLittleEndianBytes( crc, message, 12, 2 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
95 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
96 |
// read message body from file |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
97 |
FileInputStream fis = new FileInputStream( inputFile ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
98 |
byte[] buf = new byte[1024]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
99 |
int readBytes; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
100 |
int offset = 14; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
101 |
while( ( readBytes = fis.read( buf ) ) != -1 ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
102 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
103 |
System.arraycopy( buf, 0, message, offset, readBytes ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
104 |
offset += readBytes; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
105 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
106 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
107 |
return message; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
108 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
109 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
110 |
/** |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
111 |
* Wrapper to the private helper method. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
112 |
* Creates a HTI message from given service UID, command and parameters. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
113 |
* Sets HTI message priority to the default value (=0). |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
114 |
* |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
115 |
* @param serviceUid The UID of the destination service. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
116 |
* @param command The command for the destination service. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
117 |
* @param params Optional parameters for the command. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
118 |
* @return The created HTI message as a byte array. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
119 |
*/ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
120 |
public static byte[] createHtiMessage( int serviceUid, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
121 |
int command, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
122 |
byte[] params ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
123 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
124 |
return createHtiMessage( serviceUid, command, params, 0, true ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
125 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
126 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
127 |
/** |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
128 |
* Wrapper to the private helper method. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
129 |
* Creates a HTI message from given service UID and parameters, with no |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
130 |
* command specified for the destination service. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
131 |
* Sets HTI message priority to the default value (=0). |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
132 |
* This method can be used in testing the ECHO service and error situations |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
133 |
* when the command is missing. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
134 |
* |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
135 |
* @param serviceUid The UID of the destination service. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
136 |
* @param params Optional parameters for the command. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
137 |
* @return The created HTI message as a byte array. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
138 |
*/ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
139 |
public static byte[] createHtiMessage( int serviceUid, byte[] params ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
140 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
141 |
return createHtiMessage( serviceUid, -1, params, 0, false ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
142 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
143 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
144 |
/** |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
145 |
* Wrapper to the private helper method. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
146 |
* Creates a command message for the FTP service with given command and |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
147 |
* parameters. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
148 |
* Sets HTI message priority to the FTP command priority (=2). |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
149 |
* |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
150 |
* @param command The command for the FTP service. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
151 |
* @param params The parameters for the command. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
152 |
* @return The created HTI message as a byte array. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
153 |
*/ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
154 |
public static byte[] createFTPCommandMessage( int command, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
155 |
byte[] params ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
156 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
157 |
return createHtiMessage( HtiConstants.SERVICE_UID_FTP, command, params, 2, true ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
158 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
159 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
160 |
/** |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
161 |
* Wrapper to the private helper method. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
162 |
* Creates a command message for the FTP service with given parameters and |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
163 |
* with no command specified. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
164 |
* Sets HTI message priority to the FTP command priority (=2). |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
165 |
* This method can be used in testing the error situations when the command |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
166 |
* is missing. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
167 |
* |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
168 |
* @param params The parameters for the command. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
169 |
* @return The created HTI message as a byte array. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
170 |
*/ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
171 |
public static byte[] createFTPCommandMessage( byte[] params ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
172 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
173 |
return createHtiMessage( HtiConstants.SERVICE_UID_FTP, -1, params, 2, false ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
174 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
175 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
176 |
/** |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
177 |
* Writes the HTI message to the given output stream. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
178 |
* |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
179 |
* @param message HTI message as a byte array. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
180 |
* @param out Output stream to which the HTI message is written. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
181 |
* @throws IOException if I/O error occurs when writing to the stream. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
182 |
*/ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
183 |
public static void sendHtiMessage( byte[] message, OutputStream out ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
184 |
throws IOException |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
185 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
186 |
out.write( message ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
187 |
out.flush(); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
188 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
189 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
190 |
/** |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
191 |
* Encapsulates the content of the given file to the HTI messages and sends |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
192 |
* them to the given output stream. Used with FTP STOR command. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
193 |
* |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
194 |
* @param file The file which is sent. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
195 |
* @param out Output stream to which the HTI messages are written. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
196 |
* @throws Exception if an error occurs when reading the file or |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
197 |
* writing to the stream. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
198 |
*/ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
199 |
public static void sendFileToFtpService( File file, OutputStream out ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
200 |
throws Exception |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
201 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
202 |
if( file.length() == 0 ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
203 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
204 |
sendEmptyFileToFtpService( out ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
205 |
return; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
206 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
207 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
208 |
final int BODY_MAX_SIZE = 10*1024 - 14; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
209 |
//final int BODY_MAX_SIZE = 2*1024 - 14; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
210 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
211 |
byte[] headerBytes = new byte[14]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
212 |
long fileRemaining = file.length(); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
213 |
FileInputStream fis = new FileInputStream( file ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
214 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
215 |
logger.info( "File size: " + fileRemaining ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
216 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
217 |
while( fileRemaining > 0 ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
218 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
219 |
Arrays.fill( headerBytes, (byte)0 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
220 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
221 |
// add ftp service uid to header |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
222 |
CommonMethods.intToLittleEndianBytes( HtiConstants.SERVICE_UID_FTP, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
223 |
headerBytes, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
224 |
0, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
225 |
4); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
226 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
227 |
int bodySize = fileRemaining <= BODY_MAX_SIZE |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
228 |
? (int)fileRemaining |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
229 |
: BODY_MAX_SIZE; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
230 |
fileRemaining -= bodySize; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
231 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
232 |
logger.info( "Body size: " + bodySize ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
233 |
logger.info( "File remaining: " + fileRemaining ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
234 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
235 |
CommonMethods.intToLittleEndianBytes( bodySize, headerBytes, 4, 4 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
236 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
237 |
// hti message version |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
238 |
headerBytes[8] = (byte)1; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
239 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
240 |
// add the crc |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
241 |
int crc = CommonMethods.CRC16CCITT( headerBytes, 12 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
242 |
CommonMethods.intToLittleEndianBytes( crc, headerBytes, 12, 2 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
243 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
244 |
// send header to the output stream |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
245 |
out.write( headerBytes ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
246 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
247 |
// read message body from file, and send it to the output stream |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
248 |
byte[] buf = new byte[BODY_MAX_SIZE]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
249 |
int readBytes; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
250 |
int sentBytes = 0; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
251 |
do |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
252 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
253 |
readBytes = fis.read( buf ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
254 |
out.write( buf, 0, readBytes ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
255 |
sentBytes += readBytes; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
256 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
257 |
} while( sentBytes < bodySize ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
258 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
259 |
out.flush(); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
260 |
// Thread.sleep( 1000 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
261 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
262 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
263 |
out.flush(); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
264 |
fis.close(); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
265 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
266 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
267 |
/** |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
268 |
* Encapsulates the content of the given byte array to the HTI messages |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
269 |
* and sends them to the given output stream. Used with FTP STOR command. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
270 |
* |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
271 |
* @param data The byte array containing data which is sent. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
272 |
* @param out Output stream to which the HTI messages are written. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
273 |
* @throws Exception if an error occurs when reading the file or |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
274 |
* writing to the stream. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
275 |
*/ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
276 |
public static void sendByteArrayToFtpService( byte[] data, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
277 |
OutputStream out ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
278 |
throws Exception |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
279 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
280 |
final int BODY_MAX_SIZE = 10*1024 - 14; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
281 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
282 |
byte[] headerBytes = new byte[14]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
283 |
int dataRemaining = data.length; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
284 |
int offset = 0; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
285 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
286 |
logger.info( "Data length: " + dataRemaining ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
287 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
288 |
while( dataRemaining > 0 ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
289 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
290 |
Arrays.fill( headerBytes, (byte)0 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
291 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
292 |
// add ftp service uid to header |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
293 |
CommonMethods.intToLittleEndianBytes( HtiConstants.SERVICE_UID_FTP, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
294 |
headerBytes, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
295 |
0, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
296 |
4); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
297 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
298 |
int bodySize = dataRemaining <= BODY_MAX_SIZE |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
299 |
? (int)dataRemaining |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
300 |
: BODY_MAX_SIZE; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
301 |
dataRemaining -= bodySize; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
302 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
303 |
logger.info( "Body size: " + bodySize ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
304 |
logger.info( "Data remaining: " + dataRemaining ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
305 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
306 |
CommonMethods.intToLittleEndianBytes( bodySize, headerBytes, 4, 4 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
307 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
308 |
// hti message version |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
309 |
headerBytes[8] = (byte)1; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
310 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
311 |
// add the crc |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
312 |
int crc = CommonMethods.CRC16CCITT( headerBytes, 12 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
313 |
CommonMethods.intToLittleEndianBytes( crc, headerBytes, 12, 2 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
314 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
315 |
// send header to the output stream |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
316 |
out.write( headerBytes ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
317 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
318 |
// get message body from data array, and send it to the |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
319 |
// output stream |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
320 |
byte[] buf = new byte[BODY_MAX_SIZE]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
321 |
System.arraycopy( data, offset, buf, 0, bodySize ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
322 |
out.write( buf, 0, bodySize ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
323 |
out.flush(); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
324 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
325 |
dataRemaining -= bodySize; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
326 |
offset += bodySize; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
327 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
328 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
329 |
out.flush(); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
330 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
331 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
332 |
/** |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
333 |
* Sends an empty FTP data message. Used with FTP STOR command when |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
334 |
* uploading zero sized files. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
335 |
* |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
336 |
* @param out Output stream to which the HTI messages are written. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
337 |
* @throws Exception if an error occurs when reading the file or |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
338 |
* writing to the stream. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
339 |
*/ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
340 |
public static void sendEmptyFileToFtpService( OutputStream out ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
341 |
throws Exception |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
342 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
343 |
// create a FTP data message, which contains no data (only HTI header) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
344 |
byte[] headerBytes = new byte[14]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
345 |
Arrays.fill( headerBytes, (byte)0 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
346 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
347 |
// add ftp service uid to header |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
348 |
CommonMethods.intToLittleEndianBytes( HtiConstants.SERVICE_UID_FTP, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
349 |
headerBytes, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
350 |
0, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
351 |
4); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
352 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
353 |
// bytes defining the message body size are left to zero |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
354 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
355 |
// hti message version |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
356 |
headerBytes[8] = (byte)1; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
357 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
358 |
// hti message priority is left to zero |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
359 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
360 |
// flags and ext size are left to zero |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
361 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
362 |
// add the crc |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
363 |
int crc = CommonMethods.CRC16CCITT( headerBytes, 12 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
364 |
CommonMethods.intToLittleEndianBytes( crc, headerBytes, 12, 2 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
365 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
366 |
// send header to the output stream |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
367 |
out.write( headerBytes ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
368 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
369 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
370 |
/** |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
371 |
* Reads file content encapsulated in HTI messages from an input stream |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
372 |
* and writes the data to the file with given file name. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
373 |
* Used with FTP RETR command. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
374 |
* |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
375 |
* @param filename Local file name to which the received data is |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
376 |
* written. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
377 |
* @param fileSize The size of the file received. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
378 |
* @param in Input stream from which the HTI messages are read. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
379 |
* @throws Exception if an error occurs when reading from stream or |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
380 |
* writing the file. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
381 |
*/ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
382 |
public static void receiveFileFromFtpService( String filename, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
383 |
long fileSize, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
384 |
InputStream in ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
385 |
throws Exception |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
386 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
387 |
byte[] header = new byte[14]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
388 |
long readBytes = 0; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
389 |
FileOutputStream fos = new FileOutputStream( filename ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
390 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
391 |
// For zero sized file we will get one empty data message |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
392 |
// so must always read at least one message. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
393 |
do |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
394 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
395 |
//read the header |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
396 |
int readHeader = 0; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
397 |
do |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
398 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
399 |
readHeader += in.read( header, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
400 |
readHeader, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
401 |
header.length - readHeader ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
402 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
403 |
while( readHeader < header.length ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
404 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
405 |
// first check the crc |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
406 |
if ( CommonMethods.CRC16CCITT( header, 12 ) != |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
407 |
CommonMethods.littleEndianBytesToInt( header, 12, 2 ) ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
408 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
409 |
logger.info( CommonMethods.formatByteArray( "Invalid header", |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
410 |
header, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
411 |
0, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
412 |
header.length ) ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
413 |
logger.info( "Header as string: " + |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
414 |
CommonMethods.extractString( header, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
415 |
0, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
416 |
header.length ) ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
417 |
throw new HtiException( "Invalid header. CRC's do not match." ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
418 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
419 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
420 |
// read the extension, if there is any |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
421 |
int extSize = header[11]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
422 |
byte[] extension = new byte[extSize]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
423 |
if( extSize > 0 ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
424 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
425 |
int readExt = 0; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
426 |
do |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
427 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
428 |
readExt += in.read( extension, readExt, extSize - readExt ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
429 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
430 |
while( readExt < extSize ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
431 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
432 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
433 |
// get the body size from the header |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
434 |
int bodySize = CommonMethods.littleEndianBytesToInt( header, 4, 4 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
435 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
436 |
// read the body |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
437 |
byte[] buf = new byte[1024]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
438 |
int received = 0; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
439 |
int readBodyBytes; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
440 |
int maxBytesToRead; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
441 |
do |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
442 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
443 |
// make sure not to read beyond the current HTI message |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
444 |
maxBytesToRead = bodySize - received < buf.length |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
445 |
? bodySize - received |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
446 |
: buf.length; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
447 |
readBodyBytes = in.read( buf, 0, maxBytesToRead ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
448 |
received += readBodyBytes; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
449 |
fos.write( buf, 0, readBodyBytes ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
450 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
451 |
while( received < bodySize ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
452 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
453 |
readBytes += received; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
454 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
455 |
logger.info( "Read HTI message, body size: " + bodySize ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
456 |
logger.info( "Total bytes read: " + readBytes ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
457 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
458 |
fos.flush(); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
459 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
460 |
while( readBytes < fileSize ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
461 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
462 |
fos.close(); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
463 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
464 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
465 |
/** |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
466 |
* Reads file content encapsulated in HTI messages from an input stream |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
467 |
* and returns the file content as byte array. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
468 |
* |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
469 |
* @param fileSize The size of the file received. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
470 |
* @param in Input stream from which the HTI messages are read. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
471 |
* @throws Exception if an error occurs when reading from stream or |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
472 |
* writing the file. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
473 |
*/ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
474 |
public static byte[] receiveFileFromFtpServiceAsByteArray( long fileSize, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
475 |
InputStream in ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
476 |
throws Exception |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
477 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
478 |
byte[] result = new byte[(int)fileSize]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
479 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
480 |
byte[] header = new byte[14]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
481 |
long readBytes = 0; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
482 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
483 |
// For zero sized file we will get one empty data message |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
484 |
// so must always read at least one message. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
485 |
do |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
486 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
487 |
//read the header |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
488 |
int readHeader = 0; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
489 |
do |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
490 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
491 |
readHeader += in.read( header, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
492 |
readHeader, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
493 |
header.length - readHeader ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
494 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
495 |
while( readHeader < header.length ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
496 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
497 |
// first check the crc |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
498 |
if ( CommonMethods.CRC16CCITT( header, 12 ) != |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
499 |
CommonMethods.littleEndianBytesToInt( header, 12, 2 ) ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
500 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
501 |
logger.info( CommonMethods.formatByteArray( "Invalid header", |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
502 |
header, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
503 |
0, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
504 |
header.length ) ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
505 |
logger.info( "Header as string: " + |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
506 |
CommonMethods.extractString( header, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
507 |
0, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
508 |
header.length ) ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
509 |
throw new HtiException( "Invalid header. CRC's do not match." ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
510 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
511 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
512 |
// read the extension, if there is any |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
513 |
int extSize = header[11]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
514 |
byte[] extension = new byte[extSize]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
515 |
if( extSize > 0 ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
516 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
517 |
int readExt = 0; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
518 |
do |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
519 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
520 |
readExt += in.read( extension, readExt, extSize - readExt ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
521 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
522 |
while( readExt < extSize ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
523 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
524 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
525 |
// get the body size from the header |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
526 |
int bodySize = CommonMethods.littleEndianBytesToInt( header, 4, 4 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
527 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
528 |
// read the body |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
529 |
byte[] buf = new byte[1024]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
530 |
int received = 0; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
531 |
int readBodyBytes; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
532 |
int maxBytesToRead; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
533 |
do |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
534 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
535 |
// make sure not to read beyond the current HTI message |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
536 |
maxBytesToRead = bodySize - received < buf.length |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
537 |
? bodySize - received |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
538 |
: buf.length; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
539 |
readBodyBytes = in.read( buf, 0, maxBytesToRead ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
540 |
System.arraycopy( buf, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
541 |
0, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
542 |
result, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
543 |
(int)readBytes + received, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
544 |
readBodyBytes ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
545 |
received += readBodyBytes; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
546 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
547 |
while( received < bodySize ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
548 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
549 |
readBytes += received; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
550 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
551 |
while( readBytes < fileSize ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
552 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
553 |
return result; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
554 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
555 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
556 |
/** |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
557 |
* Reads a HTI message from an input stream and returns the message body |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
558 |
* as a byte array. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
559 |
* |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
560 |
* @param in Input stream from which the HTI message is read. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
561 |
* @return The body of the HTI message that was read. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
562 |
* @throws IOException if there is an error reading from the stream. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
563 |
* @throws HtiException if the HTI message header is not valid. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
564 |
*/ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
565 |
public static byte[] receiveResponse( InputStream in ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
566 |
throws IOException, HtiException |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
567 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
568 |
byte[] header = new byte[14]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
569 |
int readBytes = 0; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
570 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
571 |
//read the header |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
572 |
do |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
573 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
574 |
readBytes += in.read( header, readBytes, header.length-readBytes ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
575 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
576 |
while( readBytes < header.length ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
577 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
578 |
logger.fine( CommonMethods.formatByteArray( "Received message header", |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
579 |
header, 0, header.length ) ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
580 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
581 |
// first check the crc |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
582 |
if ( CommonMethods.CRC16CCITT( header, 12 ) != |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
583 |
CommonMethods.littleEndianBytesToInt( header, 12, 2 ) ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
584 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
585 |
throw new HtiException( "Invalid header. CRC's do not match." ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
586 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
587 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
588 |
// read the extension, if there is any |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
589 |
int extSize = header[11]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
590 |
byte[] extension = new byte[extSize]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
591 |
if( extSize > 0 ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
592 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
593 |
int readExt = 0; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
594 |
do |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
595 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
596 |
readExt += in.read( extension, readExt, extSize - readExt ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
597 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
598 |
while( readExt < extSize ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
599 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
600 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
601 |
// get the body size from the header |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
602 |
int bodySize = CommonMethods.littleEndianBytesToInt( header, 4, 4 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
603 |
logger.fine( "Body size: " + bodySize ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
604 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
605 |
// read the body |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
606 |
byte[] body = new byte[bodySize]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
607 |
readBytes = 0; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
608 |
do |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
609 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
610 |
readBytes += in.read( body, readBytes, bodySize - readBytes ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
611 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
612 |
while( readBytes < bodySize ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
613 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
614 |
logger.fine( CommonMethods.formatByteArray( "Received message body", |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
615 |
body, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
616 |
0, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
617 |
body.length ) ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
618 |
return body; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
619 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
620 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
621 |
/** |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
622 |
* Reads a HTI message from an input stream and writes the message body |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
623 |
* to the given file. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
624 |
* |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
625 |
* @param in Input stream from which the HTI message is read. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
626 |
* @param outputFile File to which the message body is written. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
627 |
* @throws IOException if I/O error occurs. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
628 |
* @throws HtiException if the HTI message header is not valid. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
629 |
*/ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
630 |
public static void receiveResponse( InputStream in, File outputFile ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
631 |
throws IOException, HtiException |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
632 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
633 |
byte[] header = new byte[14]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
634 |
int readBytes = 0; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
635 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
636 |
//read the header |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
637 |
do |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
638 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
639 |
readBytes += in.read( header, readBytes, header.length-readBytes ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
640 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
641 |
while( readBytes < header.length ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
642 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
643 |
// check the crc |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
644 |
if ( CommonMethods.CRC16CCITT( header, 12 ) != |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
645 |
CommonMethods.littleEndianBytesToInt( header, 12, 2 ) ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
646 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
647 |
throw new HtiException( "Invalid header. CRC's do not match." ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
648 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
649 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
650 |
// read the extension, if there is any |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
651 |
int extSize = header[11]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
652 |
byte[] extension = new byte[extSize]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
653 |
if( extSize > 0 ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
654 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
655 |
int readExt = 0; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
656 |
do |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
657 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
658 |
readExt += in.read( extension, readExt, extSize - readExt ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
659 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
660 |
while( readExt < extSize ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
661 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
662 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
663 |
// get the body size from the header |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
664 |
int bodySize = CommonMethods.littleEndianBytesToInt( header, 4, 4 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
665 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
666 |
// read the body |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
667 |
byte[] body = new byte[bodySize]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
668 |
readBytes = 0; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
669 |
do |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
670 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
671 |
readBytes += in.read( body, readBytes, bodySize - readBytes ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
672 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
673 |
while( readBytes < bodySize ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
674 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
675 |
// write the message body to the output file |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
676 |
FileOutputStream fos = new FileOutputStream( outputFile ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
677 |
fos.write( body ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
678 |
fos.flush(); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
679 |
fos.close(); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
680 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
681 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
682 |
/** |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
683 |
* Sends a press key command to the HTI's key event service with given |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
684 |
* key code and verifies the OK response. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
685 |
* |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
686 |
* @param out Output stream to which the HTI message is written |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
687 |
* @param in Input strem from which the response is read |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
688 |
* @param keyCode The key code for the key to be pressed |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
689 |
* @throws IOException if writing to or reading from stream fails |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
690 |
* @throws HtiException if no OK reply is received |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
691 |
*/ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
692 |
public static void pressKey( OutputStream out, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
693 |
InputStream in, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
694 |
int keyCode ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
695 |
throws IOException, HtiException |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
696 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
697 |
byte[] keyBytes = new byte[2]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
698 |
CommonMethods.intToLittleEndianBytes( keyCode, keyBytes, 0, 2 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
699 |
byte[] msg = |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
700 |
HtiHelper.createHtiMessage( HtiConstants.SERVICE_UID_KEYEVENT, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
701 |
HtiConstants.CMD_KEYEVENT_PRESSKEY, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
702 |
keyBytes ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
703 |
HtiHelper.sendHtiMessage( msg, out ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
704 |
byte[] response = HtiHelper.receiveResponse( in ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
705 |
if( (byte)HtiConstants.CMD_KEYEVENT_OK != response[0] ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
706 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
707 |
throw new HtiException( "Pressing key failed with key code: " + |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
708 |
keyCode ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
709 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
710 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
711 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
712 |
/** |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
713 |
* Formats an HTI error response to a human readable form |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
714 |
* |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
715 |
* @param response The response bytes received from HTI |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
716 |
* @return HTI error code, service error code, plugin UID |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
717 |
* and error description. Empty string if data is not HTI error msg. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
718 |
* @throws HtiException if no OK reply is received |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
719 |
*/ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
720 |
public static String formatHtiErrorMsg( byte[] response ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
721 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
722 |
if ( response.length < 10 ) return ""; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
723 |
if ( response[0] != (byte) 0xFF ) return ""; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
724 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
725 |
StringBuffer sb = new StringBuffer(); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
726 |
sb.append( "HtiError = " ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
727 |
if ( response[1] == HtiConstants.ERROR_HTI_MSG_TOO_BIG ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
728 |
sb.append( "MessageTooBig" ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
729 |
else if ( response[1] == HtiConstants.ERROR_HTI_OUT_OF_MEMORY ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
730 |
sb.append( "OutOfMemory" ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
731 |
else if ( response[1] == HtiConstants.ERROR_HTI_SERVICE_NOT_FOUND ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
732 |
sb.append( "ServiceNotFound" ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
733 |
else if ( response[1] == HtiConstants.ERROR_HTI_SERVICE_ERROR ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
734 |
sb.append( "ServiceError" ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
735 |
else if ( response[1] == HtiConstants.ERROR_HTI_NOT_AUTHORIZED ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
736 |
sb.append( "NotAuthorized" ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
737 |
else if ( response[1] == HtiConstants.ERROR_HTI_FAILED_UNWRAP ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
738 |
sb.append( "FailedUnwrap" ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
739 |
else |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
740 |
sb.append( "Unknown" ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
741 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
742 |
sb.append( "\nServiceErrorCode = " ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
743 |
sb.append( CommonMethods.littleEndianBytesToInt( response, 2, 4 ) ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
744 |
sb.append( "\nPluginUID = " ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
745 |
sb.append( CommonMethods.littleEndianBytesToInt(response, 6, 4 ) ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
746 |
sb.append( "\nDescription = " ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
747 |
if ( response.length > 10 ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
748 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
749 |
sb.append( new String ( response ).substring( 10 ) ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
750 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
751 |
return sb.toString(); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
752 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
753 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
754 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
755 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
756 |
//============================================================================== |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
757 |
//Protected methods |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
758 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
759 |
//============================================================================== |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
760 |
//Private methods |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
761 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
762 |
/** |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
763 |
* Creates a HTI message from given destination service UID, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
764 |
* command, parameters and priority. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
765 |
* |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
766 |
* @param serviceUid The UID of the destination service. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
767 |
* @param command The command for the destination service. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
768 |
* @param params Optional parameters for the command. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
769 |
* @param priority The priority in HTI message. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
770 |
* @param withCommand Flag indicating if the command is present or omited. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
771 |
* @return The created HTI message as a byte array. |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
772 |
*/ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
773 |
private static byte[] createHtiMessage( int serviceUid, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
774 |
int command, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
775 |
byte[] params, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
776 |
int priority, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
777 |
boolean withCommand ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
778 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
779 |
// first construct the message header |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
780 |
byte[] headerBytes = new byte[14]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
781 |
Arrays.fill( headerBytes, (byte)0 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
782 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
783 |
// add service UID, 4 bytes |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
784 |
CommonMethods.intToLittleEndianBytes( serviceUid, headerBytes, 0, 4 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
785 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
786 |
// add body size, 4 bytes |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
787 |
int bodySize = withCommand ? 1 + params.length : params.length; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
788 |
CommonMethods.intToLittleEndianBytes( bodySize, headerBytes, 4, 4 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
789 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
790 |
// hti message version |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
791 |
headerBytes[8] = (byte)1; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
792 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
793 |
// hti message priority |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
794 |
headerBytes[9] = (byte)priority; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
795 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
796 |
// leave flags and ext size to zero |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
797 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
798 |
// add the crc |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
799 |
int crc = CommonMethods.CRC16CCITT( headerBytes, 12 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
800 |
CommonMethods.intToLittleEndianBytes( crc, headerBytes, 12, 2 ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
801 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
802 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
803 |
// next, construct the whole message, header + command + params |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
804 |
byte[] messageBytes = new byte[headerBytes.length + bodySize]; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
805 |
System.arraycopy( headerBytes, 0, messageBytes, 0, headerBytes.length ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
806 |
if( withCommand ) |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
807 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
808 |
messageBytes[headerBytes.length] = (byte)command; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
809 |
System.arraycopy( params, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
810 |
0, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
811 |
messageBytes, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
812 |
headerBytes.length + 1, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
813 |
params.length ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
814 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
815 |
else |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
816 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
817 |
System.arraycopy( params, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
818 |
0, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
819 |
messageBytes, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
820 |
headerBytes.length, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
821 |
params.length ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
822 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
823 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
824 |
logger.info( CommonMethods.formatByteArray( "Created message", |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
825 |
messageBytes, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
826 |
0, |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
827 |
messageBytes.length ) ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
828 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
829 |
return messageBytes; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
830 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
831 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
832 |
//============================================================================== |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
833 |
//Protected attributes |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
834 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
835 |
//============================================================================== |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
836 |
//Private attributes |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
837 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
838 |
//============================================================================== |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
839 |
//Static initialization block |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
840 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
841 |
public static Logger logger; |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
842 |
static |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
843 |
{ |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
844 |
logger = CommonMethods.getSimpleLogger( HtiHelper.class.getName(), |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
845 |
Level.SEVERE ); |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
846 |
} |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
847 |
|
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
848 |
//============================================================================== |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
849 |
//Inner classes |
96906a986c3b
contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff
changeset
|
850 |
} |