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