APIdia Launch Partner
Top Description Fields Constructors Methods
sun.security.util

public Class HexDumpEncoder

extends Object
Class Inheritance
Imports
java.io.ByteArrayInputStream, .ByteArrayOutputStream, .InputStream, .PrintStream, .OutputStream, .IOException, java.nio.ByteBuffer

This class encodes a buffer into the classic: "Hexadecimal Dump" format of the past. It is useful for analyzing the contents of binary buffers. The format produced is as follows:
xxxx: 00 11 22 33 44 55 66 77   88 99 aa bb cc dd ee ff ................
Where xxxx is the offset into the buffer in 16 byte chunks, followed by ascii coded hexadecimal bytes followed by the ASCII representation of the bytes or '.' if they are not valid bytes.
Author
Chuck McManis

Field Summary

Modifier and TypeField and Description
private int
private int
protected PrintStream
pStream

Stream that understands "printing"

private final byte[]
private int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected int
protected int
public void
encode(InputStream inStream, OutputStream outStream)

Encode bytes from the input stream, and write them as text characters to the output stream.

public String
encode(byte[] aBuffer)

A 'streamless' version of encode that simply takes a buffer of bytes and returns a string containing the encoded buffer.

public String
encode(ByteBuffer aBuffer)

A 'streamless' version of encode that simply takes a ByteBuffer and returns a string containing the encoded buffer.

protected void
encodeAtom(OutputStream o, byte[] buf, int off, int len)

public void
encodeBuffer(InputStream inStream, OutputStream outStream)

Encode bytes from the input stream, and write them as text characters to the output stream.

public void
encodeBuffer(byte[] aBuffer, OutputStream aStream)

Encode the buffer in aBuffer and write the encoded result to the OutputStream aStream.

public String
encodeBuffer(byte[] aBuffer)

A 'streamless' version of encode that simply takes a buffer of bytes and returns a string containing the encoded buffer.

public void
encodeBuffer(ByteBuffer aBuffer, OutputStream aStream)

Encode the aBuffer ByteBuffer and write the encoded result to the OutputStream aStream.

protected void
protected void
protected void
private byte[]
getBytes(ByteBuffer bb)

Return a byte array from the remaining bytes in this ByteBuffer.

pack-priv static void
hexDigit(PrintStream p, byte x)

protected int
readFully(InputStream in, byte[] buffer)

This method works around the bizarre semantics of BufferedInputStream's read method.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentByteback to summary
private int currentByte
offsetback to summary
private int offset
pStreamback to summary
protected PrintStream pStream

Stream that understands "printing"

thisLineback to summary
private final byte[] thisLine
thisLineLengthback to summary
private int thisLineLength

Constructor Detail

HexDumpEncoderback to summary
public HexDumpEncoder()

Method Detail

bytesPerAtomback to summary
protected int bytesPerAtom()
bytesPerLineback to summary
protected int bytesPerLine()
encodeback to summary
public void encode(InputStream inStream, OutputStream outStream) throws IOException

Encode bytes from the input stream, and write them as text characters to the output stream. This method will run until it exhausts the input stream, but does not print the line suffix for a final line that is shorter than bytesPerLine().

encodeback to summary
public String encode(byte[] aBuffer)

A 'streamless' version of encode that simply takes a buffer of bytes and returns a string containing the encoded buffer.

encodeback to summary
public String encode(ByteBuffer aBuffer)

A 'streamless' version of encode that simply takes a ByteBuffer and returns a string containing the encoded buffer.

The ByteBuffer's position will be advanced to ByteBuffer's limit.

encodeAtomback to summary
protected void encodeAtom(OutputStream o, byte[] buf, int off, int len) throws IOException
encodeBufferback to summary
public void encodeBuffer(InputStream inStream, OutputStream outStream) throws IOException

Encode bytes from the input stream, and write them as text characters to the output stream. This method will run until it exhausts the input stream. It differs from encode in that it will add the line at the end of a final line that is shorter than bytesPerLine().

encodeBufferback to summary
public void encodeBuffer(byte[] aBuffer, OutputStream aStream) throws IOException

Encode the buffer in aBuffer and write the encoded result to the OutputStream aStream.

encodeBufferback to summary
public String encodeBuffer(byte[] aBuffer)

A 'streamless' version of encode that simply takes a buffer of bytes and returns a string containing the encoded buffer.

Returned string is encoded with the ISO-8859-1, also known as ISO-LATIN-1.

encodeBufferback to summary
public void encodeBuffer(ByteBuffer aBuffer, OutputStream aStream) throws IOException

Encode the aBuffer ByteBuffer and write the encoded result to the OutputStream aStream.

The ByteBuffer's position will be advanced to ByteBuffer's limit.

encodeBufferPrefixback to summary
protected void encodeBufferPrefix(OutputStream o) throws IOException
encodeLinePrefixback to summary
protected void encodeLinePrefix(OutputStream o, int len)
encodeLineSuffixback to summary
protected void encodeLineSuffix(OutputStream o) throws IOException
getBytesback to summary
private byte[] getBytes(ByteBuffer bb)

Return a byte array from the remaining bytes in this ByteBuffer.

The ByteBuffer's position will be advanced to ByteBuffer's limit.

To avoid an extra copy, the implementation will attempt to return the byte array backing the ByteBuffer. If this is not possible, a new byte array will be created.

hexDigitback to summary
pack-priv static void hexDigit(PrintStream p, byte x)
readFullyback to summary
protected int readFully(InputStream in, byte[] buffer) throws IOException

This method works around the bizarre semantics of BufferedInputStream's read method.