Revize 0286c04b
Přidáno uživatelem Michal Horký před více než 4 roky(ů)
demo_mh/Deserializer/src/deserialize/ToJSON.java | ||
---|---|---|
4 | 4 |
import java.io.FileWriter; |
5 | 5 |
import java.io.IOException; |
6 | 6 |
import java.nio.ByteBuffer; |
7 |
import java.util.ArrayList; |
|
7 | 8 |
import java.util.HashMap; |
9 |
import java.util.List; |
|
10 |
import java.util.concurrent.atomic.AtomicInteger; |
|
8 | 11 |
|
9 | 12 |
import org.json.simple.JSONArray; |
10 | 13 |
import org.json.simple.JSONObject; |
... | ... | |
13 | 16 |
|
14 | 17 |
public class ToJSON extends Thread { |
15 | 18 |
|
16 |
private final static byte TC_CLASSDESC = 0x72; |
|
17 |
private final static byte TC_ENDBLOCKDATA = 0x78; |
|
18 |
private final static byte SC_SERIALIZABLE = 0x02; |
|
19 |
|
|
20 |
HashMap<Character, String> typeCodes; |
|
21 |
|
|
22 | 19 |
private byte buffer[]; |
23 | 20 |
|
24 | 21 |
public ToJSON(byte buffer[]) { |
25 | 22 |
this.buffer = buffer; |
26 |
|
|
27 |
typeCodes = new HashMap<Character, String>(); |
|
28 |
typeCodes.put('B', "byte"); |
|
29 |
typeCodes.put('C', "char"); |
|
30 |
typeCodes.put('D', "double"); |
|
31 |
typeCodes.put('F', "float"); |
|
32 |
typeCodes.put('I', "integer"); |
|
33 |
typeCodes.put('J', "long"); |
|
34 |
typeCodes.put('S', "short"); |
|
35 |
typeCodes.put('Z', "boolean"); |
|
36 |
// --- |
|
37 |
typeCodes.put('[', "array"); |
|
38 |
typeCodes.put('L', "object"); |
|
39 | 23 |
} |
40 | 24 |
|
41 | 25 |
@Override |
42 | 26 |
public void run() { |
43 | 27 |
super.run(); |
44 | 28 |
|
45 |
for (int i = 0; i < buffer.length; i++) { |
|
29 |
List<Byte> buffer = new ArrayList<Byte>(); |
|
30 |
for (int i = 0; i < this.buffer.length; i++) { |
|
31 |
buffer.add(this.buffer[i]); |
|
32 |
} |
|
33 |
|
|
34 |
Grammar g = new Grammar(buffer); |
|
35 |
g.start(); |
|
36 |
|
|
37 |
/*for (int i = 0; i < buffer.length; i++) { |
|
46 | 38 |
if (buffer[i] == TC_CLASSDESC) { |
47 | 39 |
// Class name |
48 | 40 |
int nameLength = Formatter.createInt(buffer[++i], buffer[++i]); |
... | ... | |
76 | 68 |
// TODO |
77 | 69 |
System.out.println(buffer[++i] == TC_ENDBLOCKDATA); |
78 | 70 |
} |
79 |
} |
|
71 |
}*/
|
|
80 | 72 |
} |
81 | 73 |
|
82 | 74 |
@SuppressWarnings("unchecked") |
Také k dispozici: Unified diff
#7767
Zjednodušení gramatiky, částečné zprovoznění s exportem do konzole.