File: WbxmlRoundtrip.java

package info (click to toggle)
kxml2 2.3.0%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,192 kB
  • sloc: java: 5,607; xml: 104; makefile: 6
file content (64 lines) | stat: -rw-r--r-- 1,580 bytes parent folder | download | duplicates (4)
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
import java.io.*;

import org.kxml2.io.*;
import org.kxml2.wap.*;
import org.xmlpull.v1.*;

/*
 * Created on 25.09.2003
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */

/**
 * @author haustein
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class WbxmlRoundtrip {

	public static void main(String[] argv) throws Exception {
		
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		
		XmlPullParser xp = new KXmlParser();
		xp.setInput(new FileInputStream(argv[0]), null);
		XmlSerializer xs = new WbxmlSerializer();
		xs.setOutput(bos, null); 
		
		new Roundtrip(xp, xs).roundTrip();
		
		byte[] wbxml = bos.toByteArray();
		
		System.out.println("********* WBXML size: "+wbxml.length+" ***********");	
		
		for(int i = 0; i < wbxml.length; i += 16){
			for (int j = i; j < Math.min(i + 16, wbxml.length); j ++) {
				int b = ((int) wbxml[j]) & 0x0ff;
				System.out.print(Integer.toHexString(b / 16));
				System.out.print(Integer.toHexString(b % 16));
				System.out.print(' ');
			}
			
			for (int j = i; j < Math.min(i + 16, wbxml.length); j ++) {
				int b = wbxml[j];
				System.out.print(b >= 32 && b <= 127  ? (char) b : '?');
			}
			
			System.out.println();
		}
		
		ByteArrayInputStream bis = new ByteArrayInputStream(wbxml);
		
		xp = new WbxmlParser();
		xp.setInput(bis, null);
		
		xs = new KXmlSerializer();
		xs.setOutput(System.out, null);
		
		new Roundtrip(xp, xs).roundTrip();
	}

}