| 73 | } |
| 74 | |
| 75 | public void readHeader() throws IOException { |
| 76 | |
| 77 | byte[] empty = "".getBytes(); |
| 78 | inflater.setOutput(empty, 0, 0); |
| 79 | inflater.setInput(empty, 0, 0, false); |
| 80 | |
| 81 | byte[] b = new byte[10]; |
| 82 | |
| 83 | int n = fill(b); |
| 84 | if(n!=10){ |
| 85 | if(n>0){ |
| 86 | inflater.setInput(b, 0, n, false); |
| 87 | //inflater.next_in_index = n; |
| 88 | inflater.next_in_index = 0; |
| 89 | inflater.avail_in = n; |
| 90 | } |
| 91 | throw new IOException("no input"); |
| 92 | } |
| 93 | |
| 94 | inflater.setInput(b, 0, n, false); |
| 95 | |
| 96 | byte[] b1 = new byte[1]; |
| 97 | do{ |
| 98 | if(inflater.avail_in<=0){ |
| 99 | int i = in.read(b1); |
| 100 | if(i<=0) |
| 101 | throw new IOException("no input"); |
| 102 | inflater.setInput(b1, 0, 1, true); |
| 103 | } |
| 104 | |
| 105 | int err = inflater.inflate(JZlib.Z_NO_FLUSH); |
| 106 | |
| 107 | if(err!=0/*Z_OK*/){ |
| 108 | int len = 2048-inflater.next_in.length; |
| 109 | if(len>0){ |
| 110 | byte[] tmp = new byte[len]; |
| 111 | n = fill(tmp); |
| 112 | if(n>0){ |
| 113 | inflater.avail_in += inflater.next_in_index; |
| 114 | inflater.next_in_index = 0; |
| 115 | inflater.setInput(tmp, 0, n, true); |
| 116 | } |
| 117 | } |
| 118 | //inflater.next_in_index = inflater.next_in.length; |
| 119 | inflater.avail_in += inflater.next_in_index; |
| 120 | inflater.next_in_index = 0; |
| 121 | throw new IOException(inflater.msg); |
| 122 | } |
| 123 | } |
| 124 | while(inflater.istate.inParsingHeader()); |
| 125 | } |
| 126 | |
| 127 | private int fill(byte[] buf) { |
| 128 | int len = buf.length; |