1 30 31 package org.ofbiz.service.rmi.socket.zip; 32 33 import java.io.FilterOutputStream ; 34 import java.io.IOException ; 35 import java.io.OutputStream ; 36 37 public class CompressionOutputStream extends FilterOutputStream implements CompressionConstants { 38 39 42 public CompressionOutputStream(OutputStream out) { 43 super(out); 44 } 45 46 50 int buf[] = new int[5]; 51 52 55 int bufPos = 0; 56 57 58 61 public void write(int b) throws IOException { 62 b &= 0xFF; 64 65 int pos = codeTable.indexOf((char) b); 67 68 if (pos != -1) { 69 76 writeCode(BASE + pos); 77 } else { 78 writeCode(RAW); 81 82 writeCode(b >> 4); 84 85 writeCode(b & 0xF); 88 } 89 } 90 91 94 public void write(byte b[], int off, int len) throws IOException { 95 101 for (int i = 0; i < len; i++) 102 write(b[off + i]); 103 } 104 105 106 109 public void flush() throws IOException { 110 while (bufPos > 0) 111 writeCode(NOP); 112 } 113 114 119 private void writeCode(int c) throws IOException { 120 buf[bufPos++] = c; 121 if (bufPos == 5) { int pack = (buf[0] << 24) | (buf[1] << 18) | (buf[2] << 12) | 123 (buf[3] << 6) | buf[4]; 124 out.write((pack >>> 24) & 0xFF); 125 out.write((pack >>> 16) & 0xFF); 126 out.write((pack >>> 8) & 0xFF); 127 out.write((pack >>> 0) & 0xFF); 128 bufPos = 0; 129 } 130 } 131 } 132 | Popular Tags |