1 51 package org.apache.fop.render.ps; 52 53 import java.io.OutputStream ; 54 import java.io.FilterOutputStream ; 55 import java.io.IOException ; 56 57 63 public class ASCIIHexOutputStream extends FilterOutputStream { 64 65 private static final int EOL = 0x0A; private static final int EOD = 0x3E; private static final int ZERO = 0x30; private static final int NINE = 0x39; private static final int A = 0x41; private static final int ADIFF = A - NINE -1; 71 72 private int posinline = 0; 73 74 75 public ASCIIHexOutputStream(OutputStream out) { 76 super(out); 77 } 78 79 80 public void write(int b) throws IOException { 81 b &= 0xFF; 82 83 int digit1 = ((b & 0xF0) >> 4) + ZERO; 84 if (digit1 > NINE) digit1 += ADIFF; 85 out.write(digit1); 86 87 int digit2 = (b & 0x0F) + ZERO; 88 if (digit2 > NINE) digit2 += ADIFF; 89 out.write(digit2); 90 91 posinline++; 92 checkLineWrap(); 93 } 94 95 96 private void checkLineWrap() throws IOException { 97 if (posinline >= 40) { 99 out.write(EOL); 100 posinline = 0; 101 } 102 } 103 104 105 public void finalizeStream() throws IOException { 106 checkLineWrap(); 107 super.write(EOD); 109 110 flush(); 111 if (out instanceof Finalizable) { 112 ((Finalizable)out).finalizeStream(); 113 } 114 } 115 116 117 public void close() throws IOException { 118 finalizeStream(); 119 super.close(); 120 } 121 122 123 } 124 125 126 | Popular Tags |