View Javadoc
1   package org.djutils.decoderdumper.demo;
2   
3   import java.io.IOException;
4   
5   import org.djutils.decoderdumper.HexDumper;
6   
7   /**
8    * Demonstration code.
9    * @author pknoppers
10   */
11  public final class DecoderDumperDemos
12  {
13      /**
14       * Do not instantiate.
15       */
16      private DecoderDumperDemos()
17      {
18          // Do not instantiate.
19      }
20  
21      /**
22       * Run the demonstation(s).
23       * @param args can be left blank
24       * @throws IOException on error
25       */
26      public static void main(final String[] args) throws IOException
27      {
28          byte[] bytes = new byte[] {10, 20, 0x04, (byte) 0xff, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm'};
29          System.out.println(HexDumper.hexDumper(bytes));
30  
31          System.out.println(HexDumper.hexDumper(123, bytes));
32  
33          HexDumper hexDumper = new HexDumper();
34          hexDumper.setOutputStream(System.err); // from now on, all output is sent to the error output
35          hexDumper.append(bytes); // will output the first complete line; buffer byte 17 as first byte of the next output line
36          System.err.println("before flush");
37          hexDumper.flush(); // force buffered output to printed
38          System.err.println("adding more data");
39          byte[] moreBytes = new byte[] {-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17};
40          hexDumper.append(moreBytes); // will output complete line with gap for previously output data and buffer two bytes
41          System.err.println("before 2nd flush");
42          hexDumper.flush(); // force the two buffered bytes to be output
43      }
44  
45  }