1 7 8 package com.sun.corba.se.impl.orbutil; 9 10 import java.io.StringWriter ; 11 import java.io.OutputStream ; 12 import java.io.IOException ; 13 14 21 public class HexOutputStream extends OutputStream 22 { 23 static private final char hex[] = { 24 '0', '1', '2', '3', '4', '5', '6', '7', 25 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' 26 }; 27 28 private StringWriter writer; 29 30 34 public 35 HexOutputStream(StringWriter w) { 36 writer = w; 37 } 38 39 40 46 public synchronized void write(int b) throws IOException { 47 writer.write(hex[((b >> 4) & 0xF)]); 48 writer.write(hex[((b >> 0) & 0xF)]); 49 } 50 51 public synchronized void write(byte[] b) throws IOException { 52 write(b, 0, b.length); 53 } 54 55 public synchronized void write(byte[] b, int off, int len) 56 throws IOException 57 { 58 for(int i=0; i < len; i++) { 59 write(b[off + i]); 60 } 61 } 62 } 63 64 | Popular Tags |