package org.djutils.serialization.util; import java.io.ByteArrayOutputStream; import java.io.IOException; import org.djutils.decoderdumper.Dumper; import org.djutils.decoderdumper.FixedString; import org.djutils.decoderdumper.HexAddressDecoder; import org.djutils.decoderdumper.HexDecoder; import org.djutils.serialization.EndianUtil; import org.djutils.serialization.SerialDataDecoder; /** * Dumper for serialized data. *
* Copyright (c) 2019-2021 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See DJUTILS License.
*
* version Jun 27, 2019
* @author Alexander Verbraeck
* @author Peter Knoppers
*/
public class SerialDataDumper extends Dumperbytes
*/
public static String serialDataDumper(final EndianUtil endianUtil, final int addressOffset, final byte[] bytes)
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try
{
new SerialDataDumper(endianUtil, addressOffset).setOutputStream(baos).append(bytes).flush();
}
catch (IOException exception)
{
// Cannot happen because ByteOutputStream.write(byte[]) cannot fail
}
return baos.toString();
}
/**
* Create a SerialDataDumper object with addressOffset 0; use it to dump an array of bytes and return the dump as a String.
* @param endianUtil EndianUtil; used to decode multi-byte values
* @param bytes byte[]; the bytes to hex-dump
* @return String; the hexadecimal and character dump of the bytes
*/
public static String serialDataDumper(final EndianUtil endianUtil, final byte[] bytes)
{
return serialDataDumper(endianUtil, 0, bytes);
}
/** {@inheritDoc} */
@Override
public String toString()
{
return "SerialDataDumper [super=" + super.toString() + "]";
}
}