1 22 package org.jboss.test.invokers.ejb; 23 24 import java.io.*; 25 import java.net.*; 26 27 class CompressionInputStream extends FilterInputStream 28 implements CompressionConstants 29 { 30 33 public CompressionInputStream(InputStream in) { 34 super(in); 35 } 36 37 41 int buf[] = new int[5]; 42 43 46 int bufPos = 5; 47 48 51 52 public int read() throws IOException { 53 try { 54 int code; 55 56 do { 59 code = readCode(); 60 } while (code == NOP); 61 62 if (code >= BASE) { 63 return codeTable.charAt(code - BASE); 66 } else if (code == RAW) { 67 int high = readCode(); 70 int low = readCode(); 71 return (high << 4) | low; 72 } else 73 throw new IOException("unknown compression code: " + code); 74 } catch (EOFException e) { 75 return -1; 77 } 78 } 79 80 84 public int read(byte b[], int off, int len) throws IOException { 85 86 if (len <= 0) { 87 return 0; 88 } 89 90 int c = read(); 91 if (c == -1) { 92 return -1; 93 } 94 b[off] = (byte)c; 95 96 int i = 1; 97 try { 100 for (; (i < len) && (in.available() > 0); i++) { 101 c = read(); 102 if (c == -1) { 103 break; 104 } 105 if (b != null) { 106 b[off + i] = (byte)c; 107 } 108 } 109 } catch (IOException ee) { 110 } 111 return i; 112 } 113 114 119 private int readCode() throws IOException { 120 if (bufPos == 5) { 123 int b1 = in.read(); 124 int b2 = in.read(); 125 int b3 = in.read(); 126 int b4 = in.read(); 127 128 if ((b1 | b2 | b3 | b4) < 0) { 131 throw new EOFException(); 132 } 133 int pack = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4; 136 buf[0] = (pack >>> 24) & 0x3F; 137 buf[1] = (pack >>> 18) & 0x3F; 138 buf[2] = (pack >>> 12) & 0x3F; 139 buf[3] = (pack >>> 6) & 0x3F; 140 buf[4] = (pack >>> 0) & 0x3F; 141 bufPos = 0; 142 } 143 return buf[bufPos++]; 144 } 145 } 146 | Popular Tags |