1 package org.djutils.serialization.util;
2
3 import java.io.ByteArrayOutputStream;
4 import java.io.IOException;
5
6 import org.djutils.decoderdumper.Dumper;
7 import org.djutils.decoderdumper.FixedString;
8 import org.djutils.decoderdumper.HexAddressDecoder;
9 import org.djutils.decoderdumper.HexDecoder;
10 import org.djutils.serialization.EndianUtil;
11 import org.djutils.serialization.SerialDataDecoder;
12
13
14
15
16
17
18
19
20
21
22
23 public class SerialDataDumper extends Dumper<SerialDataDumper>
24 {
25
26
27
28
29
30 public SerialDataDumper(final EndianUtil endianUtil, final int addressOffset)
31 {
32 super(addressOffset);
33 addDecoder(new HexAddressDecoder(16));
34 addDecoder(new FixedString(": "));
35 addDecoder(new HexDecoder(16, 8));
36 addDecoder(new FixedString(" "));
37 addDecoder(new SerialDataDecoder(endianUtil));
38 addDecoder(new FixedString("\n"));
39 }
40
41
42
43
44
45 public SerialDataDumper(final EndianUtil endianUtil)
46 {
47 this(endianUtil, 0);
48 }
49
50
51
52
53
54
55
56
57 public static String serialDataDumper(final EndianUtil endianUtil, final int addressOffset, final byte[] bytes)
58 {
59 ByteArrayOutputStream baos = new ByteArrayOutputStream();
60 try
61 {
62 new SerialDataDumper(endianUtil, addressOffset).setOutputStream(baos).append(bytes).flush();
63 }
64 catch (IOException exception)
65 {
66
67 }
68 return baos.toString();
69 }
70
71
72
73
74
75
76
77 public static String serialDataDumper(final EndianUtil endianUtil, final byte[] bytes)
78 {
79 return serialDataDumper(endianUtil, 0, bytes);
80 }
81
82 @Override
83 public String toString()
84 {
85 return "SerialDataDumper [super=" + super.toString() + "]";
86 }
87
88 }