-
Notifications
You must be signed in to change notification settings - Fork 56
Java serialization
Sayapin Alexander edited this page Nov 10, 2016
·
9 revisions
- http://javapapers.com/core-java/java-serialization/
- https://docs.oracle.com/javase/8/docs/platform/serialization/spec/protocol.html
- https://habrahabr.ru/post/60317/
- http://www.javaworld.com/article/2072752/the-java-serialization-algorithm-revealed.html
package test.serialize;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.HashMap;
public class TestSerialize {
public static void main(String[] args) throws IOException, ClassNotFoundException {
ObjectOutputStream oos = new ObjectOutputStream(System.out);
HashMap<String, Long> values = new HashMap<String, Long>();
values.put("key1", 123L);
oos.writeObject("Hello");
oos.writeObject(values);
oos.writeLong(132L);
oos.writeUTF("Hello str");
oos.flush();
oos.close();
}
}
Пример запуска
$ java -cp build/classes/ test.serialize.TestSerialize | xxd
00000000: aced 0005 7400 0548 656c 6c6f 7372 0011 ....t..Hellosr..
00000010: 6a61 7661 2e75 7469 6c2e 4861 7368 4d61 java.util.HashMa
00000020: 7005 07da c1c3 1660 d103 0002 4600 0a6c p......`....F..l
00000030: 6f61 6446 6163 746f 7249 0009 7468 7265 oadFactorI..thre
00000040: 7368 6f6c 6478 703f 4000 0000 0000 0c77 [email protected]
00000050: 0800 0000 1000 0000 0174 0004 6b65 7931 .........t..key1
00000060: 7372 000e 6a61 7661 2e6c 616e 672e 4c6f sr..java.lang.Lo
00000070: 6e67 3b8b e490 cc8f 23df 0200 014a 0005 ng;.....#....J..
00000080: 7661 6c75 6578 7200 106a 6176 612e 6c61 valuexr..java.la
00000090: 6e67 2e4e 756d 6265 7286 ac95 1d0b 94e0 ng.Number.......
000000a0: 8b02 0000 7870 0000 0000 0000 007b 7877 ....xp.......{xw
000000b0: 1300 0000 0000 0000 8400 0948 656c 6c6f ...........Hello
000000c0: 2073 7472 str