Package org.djutils.decoderdumper
Class Dumper<T>
java.lang.Object
org.djutils.decoderdumper.Dumper<T>
- Type Parameters:
T
- Type of dumper
- Direct Known Subclasses:
Base64Dumper
,HexDumper
Common code for all (decoder-) Dumpers.
Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUTILS License.
- Author:
- Alexander Verbraeck, Peter Knoppers
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddDecoder
(int index, Decoder decoder) Add a Decoder at a specified index.void
addDecoder
(Decoder decoder) Add a Decoder at the end of the current list of decoders.boolean
append
(byte theByte) Append one byte to this dump.append
(byte[] bytes) Append an array of bytes.append
(byte[] bytes, int start, int len) Append a slice of an array of bytes.append
(InputStream inputStream) Consume an entire input stream and append what it produces to this Dumpmer.boolean
flush()
Force the currently assembled output to be written (write partial result if the output line currently being assembled is not full).int
Return the maximum width of an output line.setOutputStream
(OutputStream newOutputStream) Set or replace the active output stream.setSuppressMultipleIdenticalLines
(boolean newState) Set the output compression mode.toString()
-
Constructor Details
-
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 Details
-
setOutputStream
Set or replace the active output stream. (The default output stream isSystem.out
.)- Parameters:
newOutputStream
- OutputStream; the new output stream- Returns:
- Dumper<T>; this Dumper object (for method chaining)
-
setSuppressMultipleIdenticalLines
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
Add a Decoder at the end of the current list of decoders.- Parameters:
decoder
- Decoder; the decoder to add or insert
-
addDecoder
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
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
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
Append a slice of an array of bytes.- Parameters:
bytes
- byte[]; byte array from which to take the bytes to appendstart
- int; index of first byte inbytes
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
Consume an entire input stream and append what it produces to this Dumpmer. The input stream is not closed by thisappend
method. This method does not return until theinputStream
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 theinputStream
throws that exception, or when an output stream has been set and that throws an IOException
-
flush
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
-
toString
-