Class Dumper<T>

  • Type Parameters:
    T - Type of dumper
    Direct Known Subclasses:
    Base64Dumper, HexDumper

    public class Dumper<T>
    extends Object
    Common code for all (decoder-) Dumpers.

    Copyright (c) 2013-2021 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
    BSD-style license. See DJUTILS License.

    Version:
    $Revision$, $LastChangedDate$, by $Author$, initial version Jan 3, 2019
    Author:
    Alexander Verbraeck, Peter Knoppers
    • Constructor Detail

      • Dumper

        public Dumper​(int addressOffset)
        Construct a new Dumper.
        Parameters:
        addressOffset - int; address for the first byte that will be appended
      • Dumper

        public Dumper()
        Construct a new Dumper with addressOffset 0.
    • Method Detail

      • setOutputStream

        public Dumper<T> setOutputStream​(OutputStream newOutputStream)
        Set or replace the active output stream. (The default output stream is System.out.)
        Parameters:
        newOutputStream - OutputStream; the new output stream
        Returns:
        Dumper<T>; this Dumper object (for method chaining)
      • setSuppressMultipleIdenticalLines

        public Dumper<T> setSuppressMultipleIdenticalLines​(boolean newState)
        Set the output compression mode.
        Parameters:
        newState - boolean; if true; groups of three or more output lines with the significant content are compressed; if false; no output is suppressed
        Returns:
        Dumper<T>; this Dumper object (for method chaining)
      • addDecoder

        public void addDecoder​(Decoder decoder)
        Add a Decoder at the end of the current list of decoders.
        Parameters:
        decoder - Decoder; the decoder to add or insert
      • addDecoder

        public Dumper<T> addDecoder​(int index,
                                    Decoder decoder)
                             throws IndexOutOfBoundsException
        Add a Decoder at a specified index.
        Parameters:
        index - int; the position where the Decoder must be added (inserted)
        decoder - Decoder; the decoder to add or insert
        Returns:
        Dumper<T>; this Dumper object (for method chaining)
        Throws:
        IndexOutOfBoundsException - when the provided index is invalid
      • append

        public boolean append​(byte theByte)
                       throws IOException
        Append one byte to this dump.
        Parameters:
        theByte - byte; the byte to append
        Returns:
        boolean; true if output was generated; false if the byte was accumulated, but did not result in immediate output
        Throws:
        IOException - when output was generated and writing to the output stream generated an IOException
      • append

        public Dumper<T> append​(byte[] bytes)
                         throws IOException
        Append an array of bytes.
        Parameters:
        bytes - byte[]; the bytes to append
        Returns:
        Dumper<T>; this Dumper object (for method chaining)
        Throws:
        IOException - when an outputStream has been set and it throws an IOException
      • append

        public Dumper<T> append​(byte[] bytes,
                                int start,
                                int len)
                         throws IOException
        Append a slice of an array of bytes.
        Parameters:
        bytes - byte[]; byte array from which to take the bytes to append
        start - int; index of first byte in bytes to append (NB. using non-zero does not cause a jump in the address that is printed before the dumped bytes)
        len - int; number of bytes to append
        Returns:
        Dumper<T>; this Dumper object (for method chaining)
        Throws:
        IOException - when an outputStream has been set and it throws an IOException
      • append

        public Dumper<T> append​(InputStream inputStream)
                         throws IOException
        Consume an entire input stream and append what it produces to this Dumpmer. The input stream is not closed by this append method. This method does not return until the inputStream returns end of file, or throws an IOException (which is - actually - not a return to the caller, but a jump to the closest handler for that exception).
        Parameters:
        inputStream - InputStream; the input stream that is to be consumed
        Returns:
        Dumper<T>; this Dumper object (for method chaining)
        Throws:
        IOException - when the inputStream throws that exception, or when an output stream has been set and that throws an IOException
      • flush

        public boolean flush()
                      throws IOException
        Force the currently assembled output to be written (write partial result if the output line currently being assembled is not full).
        Returns:
        boolean; true if output was generated; false if no output was generated
        Throws:
        IOException - when output was generated and writing to the output stream generated an IOException
      • getMaximumWidth

        public int getMaximumWidth()
        Return the maximum width of an output line.
        Returns:
        int; the maximum width of an output line