2013年5月10日 星期五
Pure Java java.util.zip Implementation
在J2ME的世界裡,沒有java.util.zip的lib可以用(弔詭的是明明porting也需要jar decoder,還是要包一個zip lib),對於J2ME的開發環境,Jar size動不動就限制2M或4M(此時覺得nokia的偉大,隨便都16M),遊戲圖片想要多一點、華麗一點就可以宣告死刑,當然有很多種方式可以達成目的,例如:降低圖片解析度、減少code size(這有點...)、全部resource用OTA下載、有些programmer就會利用zip的方式減少Jar Size,就最後一個方案是最不傷遊戲畫面及遊戲邏輯的解決方案,該死的是J2ME沒有這個玩意!
不過日本的J2ME(DoJa)有com.nttdocomo.util.JarInflater取代之,所以才發想此專案 - Jazzlib2me
https://github.com/bearprada/jazzlib2me
主要還是改自jazzlib這個J2SE的solution,歡迎大家享用(不過話說寫J2ME App的Programmer應該不多了:( )
2013年1月18日 星期五
JInjector - Code coverage tool for J2ME
Overview
- related application
EMMA
Cobertura for J2me - advantage
presentation slice
Concept
- injector
- make html report
Step-by-Step
1. checkout the code(include jinjector_tool and jinjector_mobile)
- svn checkout http://jinjector.googlecode.com/svn/trunk/ jinjector-read-only
- jinjector_tool : you can build jinjector by yourself
- jinjector_mobile : run the example
2. get the related lib from web by script
./adddextrapackagesandifiles.sh (copy from jinjector_mobile/)
| requirement tool on lib/
google-collect-snapshot-20090211.zip
junit3.8.1.zip easymock2.4.zip easymockclassextension2.4.zip clib-2.2.jar |
3. modify the build.xml
build-yourprojectname.xml -> build.xml:
- <property name="WTK" value ="c:\wtk2.6" /> -> change the value into your WTK folder
- <property name="emulator.device" value="DefaultColorPhone" /> -> you can change device by setting this value
jinjector.yourprojectname.properties:
- jars: c:/wtk2.6/lib/cldcapi10.jar... -> your_WTK_folder/lib/cldcapi10.jar...
4. put your source and test case
jinjector_mobile\src : your source
jinjector_mobile\tests_to_inject : your test case
jinjector_mobile\tests_to_inject : your test case
also you can change the value of srcdir:
<target name="injectiontests" depends="unittests" description="Compiles the tests to inject"><javac srcdir="${basedir}/tests_to_inject" .........<target name="compile" depends="debug_ant, extract" description="Compiles the source"><javac srcdir="${basedir}/src" ... |
5. build test case with jinjector
ant build
- it can auto run the emulator from WTK
figure. auto run the emulator from WTK
figure. end of test and output the log of coverage
hint: the log will put in here in experiential
| lcov file place on Windows 7
direction: {UserDir}/j2mewtk/{WTK_Version}/appdb/{Device_Name}/filesystem/root1/{Log_Name}
example: C:/Users/prada.hsiung/j2mewtk/2.5.2/appdb/DefaultColorPhone/filesystem/root1/qq.lcov |
| lcov file place on Ubuntu 10
direction: ~/j2mewtk/{WTK_Version}/appdb/{Device_Name}/filesystem/roo
example: /home/prada/j2mewtk/2.5.2/appdb/DefaultColorPhone/filesystem/root1/qq.lcov |
6. generate report html
- copy the lcov file into the "/src" where is your source folder
- generating the report html by genhtml command
- genhtml qq.lcov*
- open the index.html in the same folderfigure. the main page show the percentage of code coverage for each class
figure. under light the code by different color. orange=coverage, red=not coverage yet in the test case
Reference
2013年1月17日 星期四
Study network transmission format
Introduction
POST
it's a simple solution for transmission data to server, and server can capture the value by pair-element(like php, $_POST['company'])
- Example from J2ME
try {
HttpConnection c = (HttpConnection)Connector.open(URL);
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("Content-Type","application/x-www-form-urlencoded");//MUST
String msg = "uuid=444566&imei=9ddd999&jblend_license=2223";
byte[] data = msg.getBytes();
for(int x=0;x<data.length;x++)
System.out.print(data[x]+",");
c.setRequestProperty("Content-length",""+msg.getBytes().length);//MUST
OutputStream os = c.openOutputStream();
os.write(data);
os.flush();
int rc = c.getResponseCode();
System.out.println(""+rc);
} catch (IOException e) {
System.out.println("IOException:"+e.getMessage());
}
XML (eXtensible Markup Language)
XML design for describing data.
it's Rich Documents : easy to describe the complex structure
it's Metadata
it's Configuration Files : using to set software parameter
- Example
<?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
- who use XML
ANT, Android's layout ... etc
JSON(JavaScript Object Notation)
it's a light-weight language for exchange data. the JavaScript can easy read it by eval(). but it's not only for JavaScript
- Example
{"2": {"nick_name": "kan", "full_name": "Kan Kan"}, "4": {"nick_name": "mitsuhiko", ...}, ...}
- who use JSON
plurk, facebook, twitter
YAML(YAML Ain't Markup Language)
- Example
Name: Gary
Profile:
Birth: 1975-04-43
Addr:
- City: Taipei
Road: Chung-Shoang
Number: 20
Flood: 3
- City: TaoYuan
Road: LongChung
Number: 10
Flood: 2
Blood Type: A
Score: 0.98
- Who use YAML
Google app engine(configure file)
Suggestion Architecture
Server -> Client : JSON or XML
Client -> Server : POST
For example, the PLURK API for search function:
/API/PlurkSearch/search
- Returns the latest 20 plurks on a search term.
- Required parameters:
- api_key: Your Plurk API key.
- query: The query after Plurks.
- Optional parameters:
- offset: A plurk_id of the oldest Plurk in the last search result.
- Successful return:
A JSON list of plurks that the user have permissions to see:
[{"id": 3, "content": "Test", "qualifier_translated": "says", "qualifier": "says", ...}, ...]
Result
table. the result of comparing each format
POST
XML
JSON
YAML
readability
low
high
median
high
performance
high
low
median
median-high
security
low
high
median
median
security : parser for checking well-form
Conclusion
the purpose of stage activation get report on server(grails)
it's not complication structure(tree or nest)
it's not need to high readability
it's not need to easy to integrate each platform(like different web-platform, mobile...)
it's only good at security
Introduction
POST
it's a simple solution for transmission data to server, and server can capture the value by pair-element(like php, $_POST['company'])
- Example from J2ME
try{HttpConnection c = (HttpConnection)Connector.open(URL);c.setRequestMethod(HttpConnection.POST);c.setRequestProperty("Content-Type","application/x-www-form-urlencoded");//MUSTString msg ="uuid=444566&imei=9ddd999&jblend_license=2223";byte[] data = msg.getBytes();for(intx=0;x<data.length;x++)System.out.print(data[x]+",");c.setRequestProperty("Content-length",""+msg.getBytes().length);//MUSTOutputStream os = c.openOutputStream();os.write(data);os.flush();intrc = c.getResponseCode();System.out.println(""+rc);}catch(IOException e) {System.out.println("IOException:"+e.getMessage());}
XML (eXtensible Markup Language)
XML design for describing data.
it's Rich Documents : easy to describe the complex structure
it's Metadata
it's Configuration Files : using to set software parameter
it's Rich Documents : easy to describe the complex structure
it's Metadata
it's Configuration Files : using to set software parameter
- Example
<?xml version="1.0"?><note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget methisweekend!</body></note>
- who use XML
ANT, Android's layout ... etc
JSON(JavaScript Object Notation)
it's a light-weight language for exchange data. the JavaScript can easy read it by eval(). but it's not only for JavaScript
- Example
{"2": {"nick_name": "kan", "full_name": "Kan Kan"}, "4": {"nick_name": "mitsuhiko", ...}, ...} |
- who use JSON
plurk, facebook, twitter
YAML(YAML Ain't Markup Language)
- Example
Name: GaryProfile:Birth:1975-04-43Addr:- City: TaipeiRoad: Chung-ShoangNumber:20Flood:3- City: TaoYuanRoad: LongChungNumber:10Flood:2Blood Type: AScore:0.98
- Who use YAML
Google app engine(configure file)
Suggestion Architecture
Server -> Client : JSON or XML
Client -> Server : POST
Client -> Server : POST
For example, the PLURK API for search function:
/API/PlurkSearch/search
- Returns the latest 20 plurks on a search term.
- Required parameters:
- api_key: Your Plurk API key.
- query: The query after Plurks.
- Optional parameters:
- offset: A plurk_id of the oldest Plurk in the last search result.
- Successful return:
A JSON list of plurks that the user have permissions to see:[{"id":3,"content":"Test","qualifier_translated":"says","qualifier":"says", ...}, ...]
Result
table. the result of comparing each format
POST
|
XML
|
JSON
|
YAML
| |
|---|---|---|---|---|
readability
|
low
|
high
|
median
|
high
|
performance
|
high
|
low
|
median
|
median-high
|
security
|
low
|
high
|
median
|
median
|
security : parser for checking well-form
Conclusion
the purpose of stage activation get report on server(grails)
it's not complication structure(tree or nest)
it's not need to high readability
it's not need to easy to integrate each platform(like different web-platform, mobile...)
it's only good at security
it's not complication structure(tree or nest)
it's not need to high readability
it's not need to easy to integrate each platform(like different web-platform, mobile...)
it's only good at security
訂閱:
文章 (Atom)