edu.rit.util
Class HexPrintStream

java.lang.Object
  extended by edu.rit.util.HexPrintStream

public class HexPrintStream
extends Object

Class HexPrintStream provides an object that does everything a PrintStream does, and that can print integer values and byte arrays in hexadecimal. The hex print stream prints into some underlying print stream.

Two predefined hex print streams are provided. HexPrintStream.out prints into System.out. HexPrintStream.err prints into System.err.


Field Summary
static HexPrintStream err
          A hex print stream that prints into System.err.
static HexPrintStream out
          A hex print stream that prints into System.out.
 
Constructor Summary
HexPrintStream(PrintStream ps)
          Construct a new hex print stream that will print into the given underlying print stream.
 
Method Summary
 void close()
          Close this hex print stream.
 void flush()
          Flush this hex print stream.
 PrintStream getPrintStream()
          Returns this hex print stream's underlying print stream.
 void print(boolean b)
          Print a boolean value to this hex print stream.
 void print(char c)
          Print a character to this hex print stream.
 void print(char[] s)
          Print an array of characters to this hex print stream.
 void print(double d)
          Print a double-precision floating-point value to this hex print stream.
 void print(float f)
          Print a single-precision floating-point value to this hex print stream.
 void print(int i)
          Print an integer value to this hex print stream.
 void print(long l)
          Print a long integer value to this hex print stream.
 void print(Object obj)
          Print an object to this hex print stream.
 void print(String s)
          Print a string to this hex print stream.
 void printhex(byte b)
          Print a byte value in hexadecimal to this hex print stream.
 void printhex(byte[] buf)
          Print a byte array in hexadecimal to this hex print stream.
 void printhex(byte[] buf, int off, int len)
          Print a portion of a byte array in hexadecimal to this hex print stream.
 void printhex(char c)
          Print a character value in hexadecimal to this hex print stream.
 void printhex(int i)
          Print an integer value in hexadecimal to this hex print stream.
 void printhex(long l)
          Print a long integer value in hexadecimal to this hex print stream.
 void println()
          Print a line separator to this hex print stream.
 void println(boolean b)
          Print a boolean value plus a line separator to this hex print stream.
 void println(char c)
          Print a character plus a line separator to this hex print stream.
 void println(char[] s)
          Print an array of characters plus a line separator to this hex print stream.
 void println(double d)
          Print a double-precision floating-point value plus a line separator to this hex print stream.
 void println(float f)
          Print a single-precision floating-point value plus a line separator to this hex print stream.
 void println(int i)
          Print an integer value plus a line separator to this hex print stream.
 void println(long l)
          Print a long integer value plus a line separator to this hex print stream.
 void println(Object obj)
          Print an object plus a line separator to this hex print stream.
 void println(String s)
          Print a string plus a line separator to this hex print stream.
 void printlnhex(byte b)
          Print a byte value in hexadecimal plus a line separator to this hex print stream.
 void printlnhex(byte[] buf, int n)
          Print a byte array in hexadecimal with line separators to this hex print stream.
 void printlnhex(byte[] buf, int off, int len, int n)
          Print a portion of a byte array in hexadecimal with line separators to this hex print stream.
 void printlnhex(char c)
          Print a character value in hexadecimal plus a line separator to this hex print stream.
 void printlnhex(int i)
          Print an integer value in hexadecimal plus a line separator to this hex print stream.
 void printlnhex(long l)
          Print a long integer value in hexadecimal plus a line separator to this hex print stream.
 void printStackTrace(Throwable exc)
          Print the given exception's stack trace to this hex print stream.
 void write(byte[] buf)
          Write the given byte array to this hex print stream.
 void write(byte[] buf, int off, int len)
          Write a portion of the given byte array to this hex print stream.
 void write(int b)
          Write the given byte to this hex print stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

public static final HexPrintStream out
A hex print stream that prints into System.out.


err

public static final HexPrintStream err
A hex print stream that prints into System.err.

Constructor Detail

HexPrintStream

public HexPrintStream(PrintStream ps)
Construct a new hex print stream that will print into the given underlying print stream.

Parameters:
ps - Underlying print stream.
Throws:
NullPointerException - (unchecked exception) Thrown if ps is null.
Method Detail

getPrintStream

public PrintStream getPrintStream()
Returns this hex print stream's underlying print stream.


flush

public void flush()
Flush this hex print stream. The underlying print stream is flushed.


close

public void close()
Close this hex print stream. The underlying print stream is closed.


write

public void write(int b)
Write the given byte to this hex print stream.

Parameters:
b - Byte.

write

public void write(byte[] buf)
Write the given byte array to this hex print stream.

Parameters:
buf - Byte array.
Throws:
NullPointerException - (unchecked exception) Thrown if buf is null.

write

public void write(byte[] buf,
                  int off,
                  int len)
Write a portion of the given byte array to this hex print stream.

Parameters:
buf - Byte array.
off - Index of first byte to write.
len - Number of bytes to write.
Throws:
NullPointerException - (unchecked exception) Thrown if buf is null.
IndexOutOfBoundsException - (unchecked exception) Thrown if off < 0, len < 0, or off+len > buf.length.

print

public void print(boolean b)
Print a boolean value to this hex print stream.

Parameters:
b - Boolean value.

print

public void print(char c)
Print a character to this hex print stream.

Parameters:
c - Character.

print

public void print(int i)
Print an integer value to this hex print stream.

Parameters:
i - Integer value.

print

public void print(long l)
Print a long integer value to this hex print stream.

Parameters:
l - Long integer value.

print

public void print(float f)
Print a single-precision floating-point value to this hex print stream.

Parameters:
f - Single-precision floating-point value.

print

public void print(double d)
Print a double-precision floating-point value to this hex print stream.

Parameters:
d - Double-precision floating-point value.

print

public void print(char[] s)
Print an array of characters to this hex print stream.

Parameters:
s - Array of characters.

print

public void print(String s)
Print a string to this hex print stream.

Parameters:
s - String.

print

public void print(Object obj)
Print an object to this hex print stream.

Parameters:
obj - Object.

println

public void println()
Print a line separator to this hex print stream.


println

public void println(boolean b)
Print a boolean value plus a line separator to this hex print stream.

Parameters:
b - Boolean value.

println

public void println(char c)
Print a character plus a line separator to this hex print stream.

Parameters:
c - Character.

println

public void println(int i)
Print an integer value plus a line separator to this hex print stream.

Parameters:
i - Integer value.

println

public void println(long l)
Print a long integer value plus a line separator to this hex print stream.

Parameters:
l - Long integer value.

println

public void println(float f)
Print a single-precision floating-point value plus a line separator to this hex print stream.

Parameters:
f - Single-precision floating-point value.

println

public void println(double d)
Print a double-precision floating-point value plus a line separator to this hex print stream.

Parameters:
d - Double-precision floating-point value.

println

public void println(char[] s)
Print an array of characters plus a line separator to this hex print stream.

Parameters:
s - Array of characters.

println

public void println(String s)
Print a string plus a line separator to this hex print stream.

Parameters:
s - String.

println

public void println(Object obj)
Print an object plus a line separator to this hex print stream.

Parameters:
obj - Object.

printhex

public void printhex(byte b)
Print a byte value in hexadecimal to this hex print stream. Two hexadecimal digits are printed.

Parameters:
b - Byte value.

printhex

public void printhex(char c)
Print a character value in hexadecimal to this hex print stream. Four hexadecimal digits are printed.

Parameters:
c - Character value.

printhex

public void printhex(int i)
Print an integer value in hexadecimal to this hex print stream. Eight hexadecimal digits are printed.

Parameters:
i - Integer value.

printhex

public void printhex(long l)
Print a long integer value in hexadecimal to this hex print stream. Sixteen hexadecimal digits are printed.

Parameters:
l - Long integer value.

printhex

public void printhex(byte[] buf)
Print a byte array in hexadecimal to this hex print stream. Two hexadecimal digits are printed for each byte, with a space between each byte and the next.

Parameters:
buf - Byte array.
Throws:
NullPointerException - (unchecked exception) Thrown if buf is null.

printhex

public void printhex(byte[] buf,
                     int off,
                     int len)
Print a portion of a byte array in hexadecimal to this hex print stream. Two hexadecimal digits are printed for each byte, with a space between each byte and the next.

Parameters:
buf - Byte array.
off - Index of first byte to write.
len - Number of bytes to write.
Throws:
NullPointerException - (unchecked exception) Thrown if buf is null.
IndexOutOfBoundsException - (unchecked exception) Thrown if off < 0, len < 0, or off+len > buf.length.

printlnhex

public void printlnhex(byte b)
Print a byte value in hexadecimal plus a line separator to this hex print stream. Two hexadecimal digits are printed.

Parameters:
b - Byte value.

printlnhex

public void printlnhex(char c)
Print a character value in hexadecimal plus a line separator to this hex print stream. Four hexadecimal digits are printed.

Parameters:
c - Character value.

printlnhex

public void printlnhex(int i)
Print an integer value in hexadecimal plus a line separator to this hex print stream. Eight hexadecimal digits are printed.

Parameters:
i - Integer value.

printlnhex

public void printlnhex(long l)
Print a long integer value in hexadecimal plus a line separator to this hex print stream. Sixteen hexadecimal digits are printed.

Parameters:
l - Long integer value.

printlnhex

public void printlnhex(byte[] buf,
                       int n)
Print a byte array in hexadecimal with line separators to this hex print stream. Two hexadecimal digits are printed for each byte, with a space between each byte and the next. A line separator is printed before the first byte, after every n-th byte, and after the last byte.

Parameters:
buf - Byte array.
n - Number of bytes per line.
Throws:
NullPointerException - (unchecked exception) Thrown if buf is null.
IllegalArgumentException - (unchecked exception) Thrown if n < 1.

printlnhex

public void printlnhex(byte[] buf,
                       int off,
                       int len,
                       int n)
Print a portion of a byte array in hexadecimal with line separators to this hex print stream. Two hexadecimal digits are printed for each byte, with a space between each byte and the next. A line separator is printed before the first byte, after every n-th byte, and after the last byte.

Parameters:
buf - Byte array.
off - Index of first byte to write.
len - Number of bytes to write.
n - Number of bytes per line.
Throws:
NullPointerException - (unchecked exception) Thrown if buf is null.
IndexOutOfBoundsException - (unchecked exception) Thrown if off < 0, len < 0, or off+len > buf.length.
IllegalArgumentException - (unchecked exception) Thrown if n < 1.

printStackTrace

public void printStackTrace(Throwable exc)
Print the given exception's stack trace to this hex print stream.

Parameters:
exc - Exception.


Copyright © 2001-2006 by Alan Kaminsky. All rights reserved. Send comments to ark­@­cs.rit.edu.