On Tue, 9 Mar 2021 21:37:16 GMT, Roger Riggs <rriggs@openjdk.org> wrote:
ObjectStreamPrinter is a Formatter plugin to the test library HexPrinter.
A binary stream of serialized java objects is converted into a textual form by parsing the header, typecodes, and interpreting the stream contents. The formatter can be used standalone or with the HexPrinter to align the formatted stream with the corresponding hexadecimal bytes.
StreamDump is a test utility to pass the contents of a file to the HexPrinter utility. The format of the file is guessed from the encoding and initial bytes. ASN.1 and serialized object streams are supported.
The idea is to provide a fairly literal interpretation of the stream contents with annotations to make it easy to read and understand the nesting, object handle assignments, internal references, class descriptors, and block data usage. A Hashmap with three key/value pairs is formatted: Map<String, String> map = new HashMap<>(); map.put("1", "One"); map.put("2", "Two"); map.put("2.2", "Two"); 0000: ac ed 00 05 // ObjectStream Version: 5 0004: 73 72 00 11 6a 61 76 61 2e 75 74 69 // READ CLASSDESC #0 java.util.HashMap 0010: 6c 2e 48 61 73 68 4d 61 70 // 0019: 05 07 da c1 c3 16 60 // svid: 362498820763181265L 0020: d1 // 0021: 03 // flags: WRITE_OBJECT, SERIALIZABLE 0022: 00 02 // 2 field(s) { 0024: 46 00 0a 6c 6f 61 64 46 61 63 74 6f // F loadFactor float; 0030: 72 // 0031: 49 00 09 74 68 72 65 73 68 6f 6c 64 // I threshold int; 003d: 78 // } ENDBLOCK; 003e: 70 // Super: NULL; 003f: // OBJ #1 java.util.HashMap 003f: 3f // loadFactor:0.75 0040: 40 00 00 // 0043: 00 00 00 0c // threshold:12 0047: // CustomData: 0047: 77 08 00 00 00 10 00 00 00 // BLOCKDATA 8[ ........]; 0050: 03 // 0051: 74 00 01 31 // STRING #2 "1" 0055: 74 00 03 4f 6e 65 // STRING #3 "One" 005b: 74 00 01 32 // STRING #4 "2" 005f: 74 // STRING #5 "Two" 0060: 00 03 54 77 6f // 0065: 74 00 03 32 2e 32 // STRING #6 "2.2" 006b: 71 00 7e 00 05 // REF #5 Two 0070: 78 // ENDBLOCK; The tests include a number of other examples. ------------- PR: https://git.openjdk.java.net/jdk/pull/2900