<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Just answer the F*#king question &#187; RIM / Blackberry</title>
	<atom:link href="http://www.jatfq.com/archives/category/usefull-stuff/java/rim-blackberry/feed" rel="self" type="application/rss+xml" />
	<link>http://www.jatfq.com</link>
	<description>Saving the world from dicks with forum logins ...</description>
	<pubDate>Mon, 03 Nov 2008 17:18:18 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>Converting a Midlet to a COD file for OTA installation</title>
		<link>http://www.jatfq.com/archives/20</link>
		<comments>http://www.jatfq.com/archives/20#comments</comments>
		<pubDate>Thu, 14 Feb 2008 15:01:19 +0000</pubDate>
		<dc:creator>Sime</dc:creator>
		
		<category><![CDATA[RIM / Blackberry]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.jatfq.com/archives/20</guid>
		<description><![CDATA[God, RIM sucks. Thought I&#8217;d mention that. I hate Blackberries with passion. Really.
Now, if you are converting a Midlet to a COD file, you will need to use the infamous rapc tool provided with the RIM JDE ( in the bin directory if you are looking for it ) . Now, along with issues with [...]]]></description>
			<content:encoded><![CDATA[<p>God, RIM sucks. Thought I&#8217;d mention that. I hate Blackberries with passion. Really.</p>
<p>Now, if you are converting a Midlet to a COD file, you will need to use the infamous rapc tool provided with the RIM JDE ( in the bin directory if you are looking for it ) . Now, along with issues with multiple versions, bugs and what have you, one big pain is if you want the RIM version of the JAD file created for OTA installation, rapc doesn&#8217;t give you all the parameters if you use the -midlet paramater. If you DON&#8217;T use it, you get a nice JAD but the COD will not work.</p>
<p>So, to get around this, I created a small app to extract the RIM specfic information from the COD file generated by rapc.</p>
<p>Generated the COD using</p>
<p><code>rapc import="%jde%\lib\net_rim_api.jar" codename=%jar% -midlet jad=%jar%.jad %jar%.jar </code></p>
<p>where %jde% is your JDE path, %jar% is the name of your module.</p>
<p><a href='http://www.jatfq.com/wp-content/uploads/2008/02/cod2jad.jar' title='Extract JAD information from a COD file'>Extract JAD information from a COD file</a></p>
<p>To run:</p>
<p><code>java -jar cod2jad.jar {cod file} {module name}</code></p>
<p>This will dump the extra information to stdout, so you can just append it to your JAD file with >>, ie</p>
<p><code>java -jar cod2jad.jar path.cod myapp >> path.jad</code></p>
<p>Remember, once you have done this, open the COD file in winzip ( or whatever ) and extract the seperate elements to your webserver. Once note, if you COD is only made of one module, this will probably fail ( sorry ).</p>
<p>Oh, and if you are using Netbeans components, and/or getting verification errors, try turning down your obfusication level in your project - rapc hates the splash screen and wait screen when obfusicated for some reason.  The other option is to try including the net_rim_api.jar in your project ( but don&#8217;t include in the package ).</p>
<p>And even nicer of me, here is the source code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
</pre></td><td class="code"><pre class="java"><span style="color: #000000; font-weight: bold;">package</span> com.<span style="color: #006600;">magnetmobile</span>.<span style="color: #006600;">tools</span>.<span style="color: #006600;">rim</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 *
 * @author Sime when drunk ... yay drunk code
 */</span>
<span style="color: #a1a100;">import java.io.*;</span>
<span style="color: #a1a100;">import java.util.*;</span>
<span style="color: #a1a100;">import java.util.jar.*;</span>
<span style="color: #a1a100;">import java.io.UnsupportedEncodingException;</span>
<span style="color: #a1a100;">import java.security.MessageDigest;</span>
<span style="color: #a1a100;">import java.security.NoSuchAlgorithmException;</span>
<span style="color: #a1a100;">import java.util.logging.Level;</span>
<span style="color: #a1a100;">import java.util.logging.Logger;</span>
<span style="color: #a1a100;">import java.util.zip.ZipEntry;</span>
<span style="color: #a1a100;">import java.util.zip.ZipInputStream;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Cod2Jad <span style="color: #66cc66;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #993333;">void</span> main<span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">String</span> args<span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #aaaadd; font-weight: bold;">NoSuchAlgorithmException</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
        <span style="color: #aaaadd; font-weight: bold;">FileInputStream</span> fis = <span style="color: #000000; font-weight: bold;">null</span>;
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #993333;">int</span> count = <span style="color: #cc66cc;">0</span>;
            <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>args.<span style="color: #006600;">length</span> != <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                <span style="color: #aaaadd; font-weight: bold;">System</span>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;usage: {path to COD} {Module name}&quot;</span><span style="color: #66cc66;">&#41;</span>;
                <span style="color: #aaaadd; font-weight: bold;">System</span>.<span style="color: #006600;">exit</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span>
            <span style="color: #aaaadd; font-weight: bold;">Hashtable</span> htSizes = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #aaaadd; font-weight: bold;">Hashtable</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #aaaadd; font-weight: bold;">Hashtable</span> htJarContents = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #aaaadd; font-weight: bold;">Hashtable</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            fis = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #aaaadd; font-weight: bold;">FileInputStream</span><span style="color: #66cc66;">&#40;</span>args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
&nbsp;
            <span style="color: #aaaadd; font-weight: bold;">BufferedInputStream</span> bis = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #aaaadd; font-weight: bold;">BufferedInputStream</span><span style="color: #66cc66;">&#40;</span>fis<span style="color: #66cc66;">&#41;</span>;
            <span style="color: #aaaadd; font-weight: bold;">ZipInputStream</span> zis = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #aaaadd; font-weight: bold;">ZipInputStream</span><span style="color: #66cc66;">&#40;</span>bis<span style="color: #66cc66;">&#41;</span>;
            <span style="color: #aaaadd; font-weight: bold;">ZipEntry</span> ze = <span style="color: #000000; font-weight: bold;">null</span>;
            <span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>ze = zis.<span style="color: #006600;">getNextEntry</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> != <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>ze.<span style="color: #006600;">isDirectory</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                    <span style="color: #000000; font-weight: bold;">continue</span>;
                <span style="color: #66cc66;">&#125;</span>
&nbsp;
                <span style="color: #993333;">int</span> size = <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span><span style="color: #66cc66;">&#41;</span> ze.<span style="color: #006600;">getSize</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
                <span style="color: #808080; font-style: italic;">// -1 means unknown size.</span>
                <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>size == <span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                    size = <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">Integer</span><span style="color: #66cc66;">&#41;</span> htSizes.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span>ze.<span style="color: #006600;">getName</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">intValue</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
                <span style="color: #66cc66;">&#125;</span>
                <span style="color: #993333;">byte</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> b = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #993333;">byte</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span><span style="color: #66cc66;">&#41;</span> size<span style="color: #66cc66;">&#93;</span>;
                <span style="color: #993333;">int</span> rb = <span style="color: #cc66cc;">0</span>;
                <span style="color: #993333;">int</span> chunk = <span style="color: #cc66cc;">0</span>;
                <span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span><span style="color: #66cc66;">&#41;</span> size - rb<span style="color: #66cc66;">&#41;</span> &gt; <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                    chunk = zis.<span style="color: #006600;">read</span><span style="color: #66cc66;">&#40;</span>b, rb, <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span><span style="color: #66cc66;">&#41;</span> size - rb<span style="color: #66cc66;">&#41;</span>;
                    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>chunk == <span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                        <span style="color: #000000; font-weight: bold;">break</span>;
                    <span style="color: #66cc66;">&#125;</span>
                    rb += chunk;
                <span style="color: #66cc66;">&#125;</span>
                htJarContents.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span>ze.<span style="color: #006600;">getName</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, b<span style="color: #66cc66;">&#41;</span>;
                process<span style="color: #66cc66;">&#40;</span>ze, count, b<span style="color: #66cc66;">&#41;</span>;
                count++;
            <span style="color: #66cc66;">&#125;</span>
&nbsp;
            <span style="color: #aaaadd; font-weight: bold;">System</span>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;RIM-COD-Module-Name:&quot;</span> + args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #aaaadd; font-weight: bold;">System</span>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;RIM-COD-Module-Dependencies: net_rim_cldc&quot;</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #aaaadd; font-weight: bold;">System</span>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;RIM-COD-Creation-Time: 1202924527&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
            zis.<span style="color: #006600;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            bis.<span style="color: #006600;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            fis.<span style="color: #006600;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">IOException</span> ex<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #aaaadd; font-weight: bold;">System</span>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Could not access file &quot;</span>+args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #aaaadd; font-weight: bold;">System</span>.<span style="color: #006600;">exit</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">finally</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #66cc66;">&#123;</span>
                fis.<span style="color: #006600;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">IOException</span> ex<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                Logger.<span style="color: #006600;">getLogger</span><span style="color: #66cc66;">&#40;</span>Cod2Jad.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006600;">getName</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">log</span><span style="color: #66cc66;">&#40;</span>Level.<span style="color: #006600;">SEVERE</span>, <span style="color: #000000; font-weight: bold;">null</span>, ex<span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span>
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #993333;">void</span> process<span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">Object</span> obj, <span style="color: #993333;">int</span> count,<span style="color: #993333;">byte</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> data<span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #aaaadd; font-weight: bold;">NoSuchAlgorithmException</span>,
<span style="color: #aaaadd; font-weight: bold;">UnsupportedEncodingException</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #aaaadd; font-weight: bold;">ZipEntry</span> entry = <span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">ZipEntry</span><span style="color: #66cc66;">&#41;</span> obj;
        <span style="color: #aaaadd; font-weight: bold;">String</span> name = entry.<span style="color: #006600;">getName</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #993333;">long</span> size = entry.<span style="color: #006600;">getSize</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #993333;">long</span> compressedSize = entry.<span style="color: #006600;">getCompressedSize</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
        <span style="color: #aaaadd; font-weight: bold;">String</span> output = <span style="color: #ff0000;">&quot;RIM-COD-URL&quot;</span> + <span style="color: #66cc66;">&#40;</span>count &gt; <span style="color: #cc66cc;">0</span> ? <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;-&quot;</span> + count<span style="color: #66cc66;">&#41;</span> : <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">&quot;: &quot;</span> + name;
        <span style="color: #aaaadd; font-weight: bold;">System</span>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span>output<span style="color: #66cc66;">&#41;</span>;
&nbsp;
        output = <span style="color: #ff0000;">&quot;RIM-COD-Size&quot;</span> + <span style="color: #66cc66;">&#40;</span>count &gt; <span style="color: #cc66cc;">0</span> ? <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;-&quot;</span> + count<span style="color: #66cc66;">&#41;</span> : <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">&quot;: &quot;</span> + compressedSize;
        <span style="color: #aaaadd; font-weight: bold;">System</span>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span>output<span style="color: #66cc66;">&#41;</span>;
&nbsp;
        output = <span style="color: #ff0000;">&quot;RIM-COD-SHA1&quot;</span> + <span style="color: #66cc66;">&#40;</span>count &gt; <span style="color: #cc66cc;">0</span> ? <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;-&quot;</span> + count<span style="color: #66cc66;">&#41;</span> : <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">&quot;: &quot;</span>;
        output +=  SHA1<span style="color: #66cc66;">&#40;</span>data, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #aaaadd; font-weight: bold;">System</span>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span>output<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #aaaadd; font-weight: bold;">String</span> convertToHex<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">byte</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> data, <span style="color: #993333;">boolean</span> spaced<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #aaaadd; font-weight: bold;">StringBuffer</span> buf = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #aaaadd; font-weight: bold;">StringBuffer</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> i = <span style="color: #cc66cc;">0</span>; i &lt;
                data.<span style="color: #006600;">length</span>; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #993333;">int</span> halfbyte = <span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span> &gt;&gt;&gt; <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span> &amp; 0x0F;
            <span style="color: #993333;">int</span> two_halfs = <span style="color: #cc66cc;">0</span>;
            <span style="color: #b1b100;">do</span> <span style="color: #66cc66;">&#123;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span> &lt;= halfbyte<span style="color: #66cc66;">&#41;</span> &amp;&amp; <span style="color: #66cc66;">&#40;</span>halfbyte &lt;= <span style="color: #cc66cc;">9</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                    buf.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333;">char</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'0'</span> + halfbyte<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
                <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
                    buf.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333;">char</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'a'</span> + <span style="color: #66cc66;">&#40;</span>halfbyte - <span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
                <span style="color: #66cc66;">&#125;</span>
&nbsp;
                halfbyte = data<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span> &amp; 0x0F;
            <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span>two_halfs++ &lt; <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>spaced<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                buf.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">' '</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span>
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">return</span> buf.<span style="color: #006600;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #aaaadd; font-weight: bold;">String</span> SHA1<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">byte</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> data, <span style="color: #993333;">boolean</span> spaced<span style="color: #66cc66;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #aaaadd; font-weight: bold;">NoSuchAlgorithmException</span>, <span style="color: #aaaadd; font-weight: bold;">UnsupportedEncodingException</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #aaaadd; font-weight: bold;">MessageDigest</span> md;
        md =
                <span style="color: #aaaadd; font-weight: bold;">MessageDigest</span>.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;SHA-1&quot;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #993333;">byte</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> sha1hash = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #993333;">byte</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">40</span><span style="color: #66cc66;">&#93;</span>;
        md.<span style="color: #006600;">update</span><span style="color: #66cc66;">&#40;</span>data, <span style="color: #cc66cc;">0</span>, data.<span style="color: #006600;">length</span><span style="color: #66cc66;">&#41;</span>;
        sha1hash =
                md.<span style="color: #006600;">digest</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #000000; font-weight: bold;">return</span> convertToHex<span style="color: #66cc66;">&#40;</span>sha1hash, spaced<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>


<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F20&amp;title=Converting+a+Midlet+to+a+COD+file+for+OTA+installation" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F20&amp;title=Converting+a+Midlet+to+a+COD+file+for+OTA+installation" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F20&amp;title=Converting+a+Midlet+to+a+COD+file+for+OTA+installation" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F20&amp;title=Converting+a+Midlet+to+a+COD+file+for+OTA+installation" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F20&amp;title=Converting+a+Midlet+to+a+COD+file+for+OTA+installation', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://del.icio.us/favicon.ico" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F20" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F20&amp;title=Converting+a+Midlet+to+a+COD+file+for+OTA+installation" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F20&amp;title=Converting+a+Midlet+to+a+COD+file+for+OTA+installation" title="Stumble it!"><img src="/icon_stumbleupon.gif" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.jatfq.com/archives/20/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
