1 package org.djutils.decoderdumper;
2
3 import java.io.IOException;
4
5 /**
6 * Decoder that returns a time stamp in milliseconds that applies to the time of dump of the first byte on the output line.
7 * <p>
8 * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
9 * BSD-style license. See <a href="https://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
10 * <p>
11 * @version $Revision$, $LastChangedDate$, by $Author$, initial version Jan 3, 2019 <br>
12 * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
13 * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
14 * @author <a href="https://www.transport.citg.tudelft.nl">Wouter Schakel</a>
15 */
16 public class TimeStamper implements Decoder
17 {
18 /** Result of next call to getResult. */
19 private String result = "";
20
21 /** {@inheritDoc} */
22 @Override
23 public String getResult()
24 {
25 String retVal = this.result;
26 this.result = "";
27 return retVal;
28 }
29
30 /** {@inheritDoc} */
31 @Override
32 public int getMaximumWidth()
33 {
34 return 14;
35 }
36
37 /** {@inheritDoc} */
38 @Override
39 public boolean append(int address, byte theByte) throws IOException
40 {
41 if (this.result.length() == 0)
42 {
43 long now = System.currentTimeMillis();
44 this.result = String.format("%10d.%03d ", now / 1000, now % 1000);
45 }
46 return false;
47 }
48
49 /** {@inheritDoc} */
50 @Override
51 public boolean ignoreForIdenticalOutputCheck()
52 {
53 return false;
54 }
55
56 /** {@inheritDoc} */
57 @Override
58 public String toString()
59 {
60 return "TimeStamper [result=" + this.result + "]";
61 }
62
63 }