1 22 23 package org.jboss.test.invokers.ejb; 24 25 import java.io.*; 26 27 class CompressionOutputStream extends FilterOutputStream 28 implements CompressionConstants 29 { 30 31 34 public CompressionOutputStream(OutputStream out) { 35 super(out); 36 } 37 38 42 int buf[] = new int[5]; 43 44 47 int bufPos = 0; 48 49 50 53 public void write(int b) throws IOException { 54 b &= 0xFF; 56 57 int pos = codeTable.indexOf((char)b); 59 60 if (pos != -1){ 61 68 writeCode(BASE + pos); 69 } else { 70 writeCode(RAW); 73 74 writeCode(b >> 4); 76 77 writeCode(b & 0xF); 80 } 81 } 82 83 86 public void write(byte b[], int off, int len) throws IOException { 87 93 for (int i = 0; i < len; i++) 94 write(b[off + i]); 95 } 96 97 98 101 public void flush() throws IOException { 102 while (bufPos > 0) 103 writeCode(NOP); 104 } 105 106 111 private void writeCode(int c) throws IOException { 112 buf[bufPos++] = c; 113 if (bufPos == 5) { int pack = (buf[0] << 24) | (buf[1] << 18) | (buf[2] << 12) | 115 (buf[3] << 6) | buf[4]; 116 out.write((pack >>> 24) & 0xFF); 117 out.write((pack >>> 16) & 0xFF); 118 out.write((pack >>> 8) & 0xFF); 119 out.write((pack >>> 0) & 0xFF); 120 bufPos = 0; 121 } 122 } 123 } 124 | Popular Tags |