FileDocCategorySizeDatePackage
HexFilter.javaAPI DocExample1010Sat Feb 04 06:10:10 GMT 2006com.elharo.io

HexFilter

public class HexFilter extends DumpFilter

Fields Summary
private int
numRead
private int
breakAfter
private int
ratio
Constructors Summary
public HexFilter(InputStream in)

 // Number of bytes of output per byte of input.

     
    super(in);
  
Methods Summary
public intavailable()

    return (buf.length - index) + ratio * in.available();
  
protected voidfill()

  
    buf = new int[ratio];
    int datum = in.read();
    this.numRead++;    
    if (datum == -1) {
      // Let read() handle end of stream.
      throw new EOFException();
    }

    String hex = Integer.toHexString(datum);
    if (datum < 16) { // Add a leading zero.
      hex = '0" + hex;
    }
    
    for (int i = 0; i < hex.length(); i++) {
      buf[i] = hex.charAt(i);
    }
    if (numRead < breakAfter) {
      buf[buf.length - 1] = ' ";
    }
    else {
      buf[buf.length - 1] = '\n";
      numRead = 0;
    }